mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-10 21:06:33 +00:00
fix: copy example with .pde
main sketch file
Closes arduino/arduino-ide#2377 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
parent
4217c0001d
commit
aa9b10d68e
@ -609,9 +609,13 @@ export class SketchesServiceImpl
|
|||||||
force: true,
|
force: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const sourceMainSketchFilePath = FileUri.fsPath(sketch.mainFileUri);
|
||||||
|
// Can copy sketch with pde main sketch file: https://github.com/arduino/arduino-ide/issues/2377
|
||||||
|
const ext = path.extname(sourceMainSketchFilePath);
|
||||||
|
|
||||||
// rename the main sketch file
|
// rename the main sketch file
|
||||||
await fs.rename(
|
await fs.rename(
|
||||||
join(temp, `${sourceFolderBasename}.ino`),
|
join(temp, `${sourceFolderBasename}${ext}`),
|
||||||
join(temp, `${destinationFolderBasename}.ino`)
|
join(temp, `${destinationFolderBasename}.ino`)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -3,18 +3,19 @@ import {
|
|||||||
DisposableCollection,
|
DisposableCollection,
|
||||||
} from '@theia/core/lib/common/disposable';
|
} from '@theia/core/lib/common/disposable';
|
||||||
import { isWindows } from '@theia/core/lib/common/os';
|
import { isWindows } from '@theia/core/lib/common/os';
|
||||||
|
import { URI } from '@theia/core/lib/common/uri';
|
||||||
import { FileUri } from '@theia/core/lib/node/file-uri';
|
import { FileUri } from '@theia/core/lib/node/file-uri';
|
||||||
import { Container } from '@theia/core/shared/inversify';
|
import { Container } from '@theia/core/shared/inversify';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { promises as fs } from 'node:fs';
|
|
||||||
import { basename, join } from 'node:path';
|
|
||||||
import { rejects } from 'node:assert/strict';
|
import { rejects } from 'node:assert/strict';
|
||||||
|
import { promises as fs } from 'node:fs';
|
||||||
|
import path, { basename, join } from 'node:path';
|
||||||
import { sync as rimrafSync } from 'rimraf';
|
import { sync as rimrafSync } from 'rimraf';
|
||||||
import temp from 'temp';
|
import temp from 'temp';
|
||||||
import { Sketch, SketchesError, SketchesService } from '../../common/protocol';
|
import { Sketch, SketchesError, SketchesService } from '../../common/protocol';
|
||||||
import {
|
import {
|
||||||
isAccessibleSketchPath,
|
|
||||||
SketchesServiceImpl,
|
SketchesServiceImpl,
|
||||||
|
isAccessibleSketchPath,
|
||||||
} from '../../node/sketches-service-impl';
|
} from '../../node/sketches-service-impl';
|
||||||
import { ErrnoException } from '../../node/utils/errors';
|
import { ErrnoException } from '../../node/utils/errors';
|
||||||
import { createBaseContainer, startDaemon } from './node-test-bindings';
|
import { createBaseContainer, startDaemon } from './node-test-bindings';
|
||||||
@ -332,6 +333,37 @@ describe('sketches-service-impl', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should copy sketch if the main sketch file has pde extension (#2377)', async () => {
|
||||||
|
const sketchesService =
|
||||||
|
container.get<SketchesServiceImpl>(SketchesService);
|
||||||
|
let sketch = await sketchesService.createNewSketch();
|
||||||
|
toDispose.push(disposeSketch(sketch));
|
||||||
|
expect(sketch.mainFileUri.endsWith('.ino')).to.be.true;
|
||||||
|
|
||||||
|
// Create a sketch and rename the main sketch file to .pde
|
||||||
|
const mainSketchFilePathIno = FileUri.fsPath(new URI(sketch.mainFileUri));
|
||||||
|
const sketchFolderPath = path.dirname(mainSketchFilePathIno);
|
||||||
|
const mainSketchFilePathPde = path.join(
|
||||||
|
sketchFolderPath,
|
||||||
|
`${basename(sketchFolderPath)}.pde`
|
||||||
|
);
|
||||||
|
await fs.rename(mainSketchFilePathIno, mainSketchFilePathPde);
|
||||||
|
|
||||||
|
sketch = await sketchesService.loadSketch(sketch.uri);
|
||||||
|
expect(sketch.mainFileUri.endsWith('.pde')).to.be.true;
|
||||||
|
|
||||||
|
const tempDirPath = await sketchesService['createTempFolder']();
|
||||||
|
const destinationPath = join(tempDirPath, 'GH-2377');
|
||||||
|
const destinationUri = FileUri.create(destinationPath).toString();
|
||||||
|
|
||||||
|
await sketchesService.copy(sketch, {
|
||||||
|
destinationUri,
|
||||||
|
});
|
||||||
|
|
||||||
|
const copiedSketch = await sketchesService.loadSketch(destinationUri);
|
||||||
|
expect(copiedSketch.mainFileUri.endsWith('.ino')).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
it('should copy sketch inside the sketch folder', async () => {
|
it('should copy sketch inside the sketch folder', async () => {
|
||||||
const sketchesService =
|
const sketchesService =
|
||||||
container.get<SketchesServiceImpl>(SketchesService);
|
container.get<SketchesServiceImpl>(SketchesService);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user