Skip to content

Commit d28398e

Browse files
committed
Added a modifiable default sketch for new project
1 parent bc264d1 commit d28398e

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

arduino-ide-extension/src/node/sketches-service-impl.ts

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -447,18 +447,10 @@ export class SketchesServiceImpl
447447
const sketchDir = path.join(parentPath, sketchName);
448448
const sketchFile = path.join(sketchDir, `${sketchName}.ino`);
449449
await fs.mkdir(sketchDir, { recursive: true });
450+
let defaultContent = await this.loadDefault();
450451
await fs.writeFile(
451452
sketchFile,
452-
`void setup() {
453-
// put your setup code here, to run once:
454-
455-
}
456-
457-
void loop() {
458-
// put your main code here, to run repeatedly:
459-
460-
}
461-
`,
453+
defaultContent,
462454
{ encoding: 'utf8' }
463455
);
464456
return this.loadSketch(FileUri.create(sketchDir).toString());
@@ -637,6 +629,40 @@ void loop() {
637629
return false;
638630
}
639631
}
632+
633+
// Returns the default.ino from the default folder
634+
private async loadDefault(): Promise<string> {
635+
const root = await this.root(await this.sketchbookUri());
636+
let result : string;
637+
result = `void setup() {
638+
// put your setup code here, to run once:
639+
640+
}
641+
642+
void loop() {
643+
// put your main code here, to run repeatedly:
644+
645+
}`;
646+
647+
let filename = `${root}/default/default.ino`;
648+
let exists = false;
649+
let raw = "";
650+
651+
try {
652+
raw = await fs.readFile(filename, {encoding: 'utf8', });
653+
exists = true;
654+
} catch {
655+
exists = false;
656+
}
657+
658+
if (exists) {
659+
result = raw;
660+
this.logger.info (`-- Default found at ${filename}`)
661+
} else {
662+
this.logger.info (`-- Default sketch not found at ${filename}`)
663+
}
664+
return result;
665+
}
640666
}
641667

642668
interface SketchWithDetails extends Sketch {

compile_output.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
yarn install v1.22.19
2+
[1/5] Validating package.json...
3+
[2/5] Resolving packages...
4+
success Already up-to-date.
5+
$ lerna run prepare && yarn download:plugins
6+
arduino-ide-extension: yarn run v1.22.19
7+
arduino-ide-extension: $ yarn download-cli && yarn download-fwuploader && yarn download-ls && yarn copy-i18n && yarn clean && yarn download-examples && yarn build && yarn test
8+
arduino-ide-extension: $ node ./scripts/download-cli.js
9+
arduino-ide-extension: Building CLI from https://github.com/arduino/arduino-cli.git. Commitish: c8ff042
10+
arduino-ide-extension: >>> Cloning CLI source to C:\Users\nicol\AppData\Local\Temp\d-2022913-10576-1gzrhxh.8o37...
11+
arduino-ide-extension: <<< Cloned CLI repo.
12+
arduino-ide-extension: >>> Checking out c8ff042...
13+
arduino-ide-extension: <<< Checked out c8ff042.
14+
arduino-ide-extension: >>> Building the CLI...
15+
arduino-ide-extension: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
16+
arduino-ide-extension: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
17+
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

0 commit comments

Comments
 (0)