create-mikrojs 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +33 -0
- package/bin/create-mikrojs.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +106 -0
- package/dist/index.js.map +1 -0
- package/dist/inspect.d.ts +2 -0
- package/dist/inspect.d.ts.map +1 -0
- package/dist/inspect.js +56 -0
- package/dist/inspect.js.map +1 -0
- package/dist/logo.d.ts +2 -0
- package/dist/logo.d.ts.map +1 -0
- package/dist/logo.js +26 -0
- package/dist/logo.js.map +1 -0
- package/dist/pkg-manager.d.ts +5 -0
- package/dist/pkg-manager.d.ts.map +1 -0
- package/dist/pkg-manager.js +15 -0
- package/dist/pkg-manager.js.map +1 -0
- package/dist/scaffold.d.ts +22 -0
- package/dist/scaffold.d.ts.map +1 -0
- package/dist/scaffold.js +133 -0
- package/dist/scaffold.js.map +1 -0
- package/dist/scaffold.test.d.ts +2 -0
- package/dist/scaffold.test.d.ts.map +1 -0
- package/dist/scaffold.test.js +105 -0
- package/dist/scaffold.test.js.map +1 -0
- package/dist/templates/_common/dependencies.d.ts +7 -0
- package/dist/templates/_common/dependencies.d.ts.map +1 -0
- package/dist/templates/_common/dependencies.js +7 -0
- package/dist/templates/_common/dependencies.js.map +1 -0
- package/dist/templates/_common/env-example.d.ts +2 -0
- package/dist/templates/_common/env-example.d.ts.map +1 -0
- package/dist/templates/_common/env-example.js +10 -0
- package/dist/templates/_common/env-example.js.map +1 -0
- package/dist/templates/_common/gitignore.d.ts +2 -0
- package/dist/templates/_common/gitignore.d.ts.map +1 -0
- package/dist/templates/_common/gitignore.js +8 -0
- package/dist/templates/_common/gitignore.js.map +1 -0
- package/dist/templates/_common/package-json.d.ts +22 -0
- package/dist/templates/_common/package-json.d.ts.map +1 -0
- package/dist/templates/_common/package-json.js +22 -0
- package/dist/templates/_common/package-json.js.map +1 -0
- package/dist/templates/_common/readme.d.ts +11 -0
- package/dist/templates/_common/readme.d.ts.map +1 -0
- package/dist/templates/_common/readme.js +45 -0
- package/dist/templates/_common/readme.js.map +1 -0
- package/dist/templates/_common/tsconfig.d.ts +3 -0
- package/dist/templates/_common/tsconfig.d.ts.map +1 -0
- package/dist/templates/_common/tsconfig.js +26 -0
- package/dist/templates/_common/tsconfig.js.map +1 -0
- package/package.json +56 -0
- package/src/templates/_common/dependencies.ts +9 -0
- package/src/templates/_common/env-example.ts +9 -0
- package/src/templates/_common/gitignore.ts +7 -0
- package/src/templates/_common/package-json.ts +35 -0
- package/src/templates/_common/readme.ts +64 -0
- package/src/templates/_common/tsconfig.ts +27 -0
- package/src/templates/blank/app/main.ts +3 -0
- package/src/templates/blinky/app/main.ts +18 -0
- package/src/templates/neopixel/app/color.ts +23 -0
- package/src/templates/neopixel/app/main.ts +24 -0
- package/src/templates/neopixel/app/patterns/breathe.ts +22 -0
- package/src/templates/neopixel/app/patterns/color-wipe.ts +35 -0
- package/src/templates/neopixel/app/patterns/comet.ts +29 -0
- package/src/templates/neopixel/app/patterns/rainbow.ts +24 -0
- package/src/templates/neopixel/app/patterns/sparkle.ts +25 -0
- package/src/templates/pwm-led/app/main.ts +21 -0
- package/src/templates/rtc-counter/app/main.ts +20 -0
- package/src/templates/sntp/app/main.ts +35 -0
- package/src/templates/sntp/env.d.ts +4 -0
- package/src/templates/wifi-access-point/app/main.ts +40 -0
- package/src/templates/wifi-fetch/app/main.ts +35 -0
- package/src/templates/wifi-fetch/env.d.ts +4 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../../../src/templates/_common/dependencies.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,OAAO,EAAE,QAAQ;CACoB,CAAA;AAEvC,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,UAAU,EAAE,aAAa;CACe,CAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const envExample = "# Copy this file to .env and add environment variables for your project.\n# .env, .env.development, .env.production, .env.test, and .env.simulator\n# are auto-loaded by `mikro` and pushed to the device on deploy.\n# Names must be 15 characters or fewer (NVS key limit).\n\n# WIFI_SSID=\n# WIFI_PASSPHRASE=\n";
|
|
2
|
+
//# sourceMappingURL=env-example.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-example.d.ts","sourceRoot":"","sources":["../../../src/templates/_common/env-example.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,wTAQtB,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const envExample = `\
|
|
2
|
+
# Copy this file to .env and add environment variables for your project.
|
|
3
|
+
# .env, .env.development, .env.production, .env.test, and .env.simulator
|
|
4
|
+
# are auto-loaded by \`mikro\` and pushed to the device on deploy.
|
|
5
|
+
# Names must be 15 characters or fewer (NVS key limit).
|
|
6
|
+
|
|
7
|
+
# WIFI_SSID=
|
|
8
|
+
# WIFI_PASSPHRASE=
|
|
9
|
+
`;
|
|
10
|
+
//# sourceMappingURL=env-example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-example.js","sourceRoot":"","sources":["../../../src/templates/_common/env-example.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG;;;;;;;;CAQzB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gitignore.d.ts","sourceRoot":"","sources":["../../../src/templates/_common/gitignore.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,wDAMrB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gitignore.js","sourceRoot":"","sources":["../../../src/templates/_common/gitignore.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG;;;;;;CAMxB,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PackageJson } from 'type-fest';
|
|
2
|
+
export declare function packageJson(name: string, { devDependencies, dependencies, typescript, }?: {
|
|
3
|
+
dependencies?: PackageJson['devDependencies'];
|
|
4
|
+
devDependencies?: PackageJson['dependencies'];
|
|
5
|
+
/** Include the tsc predeploy hook. */
|
|
6
|
+
typescript?: boolean;
|
|
7
|
+
}): {
|
|
8
|
+
mikrojs?: {
|
|
9
|
+
predeploy: string[];
|
|
10
|
+
} | undefined;
|
|
11
|
+
name: string;
|
|
12
|
+
version: string;
|
|
13
|
+
private: true;
|
|
14
|
+
type: "module";
|
|
15
|
+
main: string;
|
|
16
|
+
scripts: {
|
|
17
|
+
dev: string;
|
|
18
|
+
};
|
|
19
|
+
dependencies: {};
|
|
20
|
+
devDependencies: {};
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=package-json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-json.d.ts","sourceRoot":"","sources":["../../../src/templates/_common/package-json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,WAAW,CAAA;AAE1C,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,EACE,eAAe,EACf,YAAY,EACZ,UAAU,GACX,GAAE;IACD,YAAY,CAAC,EAAE,WAAW,CAAC,iBAAiB,CAAC,CAAA;IAC7C,eAAe,CAAC,EAAE,WAAW,CAAC,cAAc,CAAC,CAAA;IAC7C,sCAAsC;IACtC,UAAU,CAAC,EAAE,OAAO,CAAA;CAChB;;;;;;;;;;;;kBAW0B,EAAE;qBACI,EAAE;EASzC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function packageJson(name, { devDependencies, dependencies, typescript, } = {}) {
|
|
2
|
+
return {
|
|
3
|
+
name,
|
|
4
|
+
version: '0.0.0',
|
|
5
|
+
private: true,
|
|
6
|
+
type: 'module',
|
|
7
|
+
main: './app/main.ts',
|
|
8
|
+
scripts: {
|
|
9
|
+
dev: 'mikro dev',
|
|
10
|
+
},
|
|
11
|
+
dependencies: dependencies,
|
|
12
|
+
devDependencies: devDependencies,
|
|
13
|
+
...(typescript
|
|
14
|
+
? {
|
|
15
|
+
mikrojs: {
|
|
16
|
+
predeploy: ['tsc --noEmit --pretty'],
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
: {}),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=package-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-json.js","sourceRoot":"","sources":["../../../src/templates/_common/package-json.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,WAAW,CACzB,IAAY,EACZ,EACE,eAAe,EACf,YAAY,EACZ,UAAU,MAMR,EAAE;IAEN,OAAO;QACL,IAAI;QACJ,OAAO,EAAE,OAAO;QAChB,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,eAAe;QACrB,OAAO,EAAE;YACP,GAAG,EAAE,WAAW;SACjB;QACD,YAAY,EAAE,YAAkB;QAChC,eAAe,EAAE,eAAqB;QACtC,GAAG,CAAC,UAAU;YACZ,CAAC,CAAC;gBACE,OAAO,EAAE;oBACP,SAAS,EAAE,CAAC,uBAAuB,CAAC;iBACrC;aACF;YACH,CAAC,CAAC,EAAE,CAAC;KACc,CAAA;AACzB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PkgManager } from '../../pkg-manager.js';
|
|
2
|
+
export interface ReadmeOptions {
|
|
3
|
+
projectName: string;
|
|
4
|
+
description: string;
|
|
5
|
+
pm: PkgManager;
|
|
6
|
+
hardware?: string;
|
|
7
|
+
wiring?: string;
|
|
8
|
+
setup?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function readme(options: ReadmeOptions): string;
|
|
11
|
+
//# sourceMappingURL=readme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readme.d.ts","sourceRoot":"","sources":["../../../src/templates/_common/readme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAA;AAOpD,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,EAAE,EAAE,UAAU,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,wBAAgB,MAAM,CAAC,OAAO,EAAE,aAAa,UA+C5C"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
function mikro(pm, cmd) {
|
|
2
|
+
if (pm === 'npm')
|
|
3
|
+
return `npx mikro ${cmd}`;
|
|
4
|
+
return `pnpm mikro ${cmd}`;
|
|
5
|
+
}
|
|
6
|
+
export function readme(options) {
|
|
7
|
+
const { projectName, description, pm, hardware, wiring, setup } = options;
|
|
8
|
+
const sections = [];
|
|
9
|
+
sections.push(`# ${projectName}\n\n${description}`);
|
|
10
|
+
if (hardware) {
|
|
11
|
+
sections.push(`## Hardware\n\n${hardware}`);
|
|
12
|
+
}
|
|
13
|
+
if (wiring) {
|
|
14
|
+
sections.push(`## Wiring\n\n${wiring}`);
|
|
15
|
+
}
|
|
16
|
+
if (setup) {
|
|
17
|
+
sections.push(`## Setup\n\n${setup}`);
|
|
18
|
+
}
|
|
19
|
+
sections.push(`## Getting started
|
|
20
|
+
|
|
21
|
+
Install dependencies:
|
|
22
|
+
|
|
23
|
+
\`\`\`sh
|
|
24
|
+
${pm} install
|
|
25
|
+
\`\`\`
|
|
26
|
+
|
|
27
|
+
Flash firmware and start developing:
|
|
28
|
+
|
|
29
|
+
\`\`\`sh
|
|
30
|
+
${mikro(pm, 'dev')}
|
|
31
|
+
\`\`\``);
|
|
32
|
+
sections.push(`## Commands
|
|
33
|
+
|
|
34
|
+
- \`${mikro(pm, 'dev')}\` — develop on connected device
|
|
35
|
+
- \`${mikro(pm, 'deploy')}\` — build and deploy to device
|
|
36
|
+
- \`${mikro(pm, 'console')}\` — open REPL on device
|
|
37
|
+
- \`${mikro(pm, 'env set KEY value')}\` — set environment variable on device`);
|
|
38
|
+
sections.push(`## Learn more
|
|
39
|
+
|
|
40
|
+
- [Mikro.js documentation](https://mikrojs.dev)
|
|
41
|
+
- [API reference](https://mikrojs.dev/api/)
|
|
42
|
+
- [Examples](https://mikrojs.dev/examples/)`);
|
|
43
|
+
return sections.join('\n\n') + '\n';
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=readme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readme.js","sourceRoot":"","sources":["../../../src/templates/_common/readme.ts"],"names":[],"mappings":"AAEA,SAAS,KAAK,CAAC,EAAc,EAAE,GAAW;IACxC,IAAI,EAAE,KAAK,KAAK;QAAE,OAAO,aAAa,GAAG,EAAE,CAAA;IAC3C,OAAO,cAAc,GAAG,EAAE,CAAA;AAC5B,CAAC;AAWD,MAAM,UAAU,MAAM,CAAC,OAAsB;IAC3C,MAAM,EAAC,WAAW,EAAE,WAAW,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAC,GAAG,OAAO,CAAA;IAEvE,MAAM,QAAQ,GAAa,EAAE,CAAA;IAE7B,QAAQ,CAAC,IAAI,CAAC,KAAK,WAAW,OAAO,WAAW,EAAE,CAAC,CAAA;IAEnD,IAAI,QAAQ,EAAE,CAAC;QACb,QAAQ,CAAC,IAAI,CAAC,kBAAkB,QAAQ,EAAE,CAAC,CAAA;IAC7C,CAAC;IAED,IAAI,MAAM,EAAE,CAAC;QACX,QAAQ,CAAC,IAAI,CAAC,gBAAgB,MAAM,EAAE,CAAC,CAAA;IACzC,CAAC;IAED,IAAI,KAAK,EAAE,CAAC;QACV,QAAQ,CAAC,IAAI,CAAC,eAAe,KAAK,EAAE,CAAC,CAAA;IACvC,CAAC;IAED,QAAQ,CAAC,IAAI,CAAC;;;;;EAKd,EAAE;;;;;;EAMF,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC;OACX,CAAC,CAAA;IAEN,QAAQ,CAAC,IAAI,CAAC;;MAEV,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC;MAChB,KAAK,CAAC,EAAE,EAAE,QAAQ,CAAC;MACnB,KAAK,CAAC,EAAE,EAAE,SAAS,CAAC;MACpB,KAAK,CAAC,EAAE,EAAE,mBAAmB,CAAC,yCAAyC,CAAC,CAAA;IAE5E,QAAQ,CAAC,IAAI,CAAC;;;;4CAI4B,CAAC,CAAA;IAE3C,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAA;AACrC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tsconfig.d.ts","sourceRoot":"","sources":["../../../src/templates/_common/tsconfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,WAAW,CAAA;AAE3C,eAAO,MAAM,QAAQ,EAAE,YAwBtB,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const tsconfig = {
|
|
2
|
+
include: ['app/**/*'],
|
|
3
|
+
compilerOptions: {
|
|
4
|
+
module: 'nodenext',
|
|
5
|
+
target: 'es2024',
|
|
6
|
+
lib: ['es2024'],
|
|
7
|
+
noEmit: true,
|
|
8
|
+
types: ['mikrojs/runtime'],
|
|
9
|
+
sourceMap: true,
|
|
10
|
+
noUncheckedIndexedAccess: true,
|
|
11
|
+
allowUnreachableCode: false,
|
|
12
|
+
erasableSyntaxOnly: true,
|
|
13
|
+
strict: true,
|
|
14
|
+
verbatimModuleSyntax: true,
|
|
15
|
+
isolatedModules: true,
|
|
16
|
+
noUncheckedSideEffectImports: true,
|
|
17
|
+
moduleDetection: 'force',
|
|
18
|
+
jsx: 'preserve',
|
|
19
|
+
skipLibCheck: true,
|
|
20
|
+
noFallthroughCasesInSwitch: true,
|
|
21
|
+
noUnusedLocals: true,
|
|
22
|
+
forceConsistentCasingInFileNames: true,
|
|
23
|
+
resolveJsonModule: true,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=tsconfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tsconfig.js","sourceRoot":"","sources":["../../../src/templates/_common/tsconfig.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,QAAQ,GAAiB;IACpC,OAAO,EAAE,CAAC,UAAU,CAAC;IACrB,eAAe,EAAE;QACf,MAAM,EAAE,UAAU;QAClB,MAAM,EAAE,QAAQ;QAChB,GAAG,EAAE,CAAC,QAAQ,CAAC;QACf,MAAM,EAAE,IAAI;QACZ,KAAK,EAAE,CAAC,iBAAiB,CAAC;QAC1B,SAAS,EAAE,IAAI;QACf,wBAAwB,EAAE,IAAI;QAC9B,oBAAoB,EAAE,KAAK;QAC3B,kBAAkB,EAAE,IAAI;QACxB,MAAM,EAAE,IAAI;QACZ,oBAAoB,EAAE,IAAI;QAC1B,eAAe,EAAE,IAAI;QACrB,4BAA4B,EAAE,IAAI;QAClC,eAAe,EAAE,OAAO;QACxB,GAAG,EAAE,UAAU;QACf,YAAY,EAAE,IAAI;QAClB,0BAA0B,EAAE,IAAI;QAChC,cAAc,EAAE,IAAI;QACpB,gCAAgC,EAAE,IAAI;QACtC,iBAAiB,EAAE,IAAI;KACxB;CACF,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-mikrojs",
|
|
3
|
+
"version": "0.0.7",
|
|
4
|
+
"description": "Create a new Mikro.js project",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"esp32",
|
|
7
|
+
"javascript",
|
|
8
|
+
"microcontroller",
|
|
9
|
+
"mikrojs",
|
|
10
|
+
"quickjs",
|
|
11
|
+
"typescript"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/mikrojs/mikrojs#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/mikrojs/mikrojs/issues"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": "Bjørge Næss <bjoerge@gmail.com>",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/mikrojs/mikrojs.git"
|
|
22
|
+
},
|
|
23
|
+
"bin": {
|
|
24
|
+
"create-mikrojs": "bin/create-mikrojs.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"src/templates",
|
|
29
|
+
"bin"
|
|
30
|
+
],
|
|
31
|
+
"type": "module",
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"exports": {
|
|
34
|
+
".": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@clack/prompts": "^1.2.0",
|
|
38
|
+
"@optique/core": "^1.0.2",
|
|
39
|
+
"@optique/run": "^1.0.2",
|
|
40
|
+
"type-fest": "^5.6.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^25.6.0",
|
|
44
|
+
"typescript": "^6.0.3"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=24.0.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build:ts": "tsc -p tsconfig.build.json",
|
|
51
|
+
"inspect": "tsx src/inspect.ts",
|
|
52
|
+
"publint": "publint",
|
|
53
|
+
"test": "vitest run",
|
|
54
|
+
"typecheck": "tsc --noEmit"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const envExample = `\
|
|
2
|
+
# Copy this file to .env and add environment variables for your project.
|
|
3
|
+
# .env, .env.development, .env.production, .env.test, and .env.simulator
|
|
4
|
+
# are auto-loaded by \`mikro\` and pushed to the device on deploy.
|
|
5
|
+
# Names must be 15 characters or fewer (NVS key limit).
|
|
6
|
+
|
|
7
|
+
# WIFI_SSID=
|
|
8
|
+
# WIFI_PASSPHRASE=
|
|
9
|
+
`
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type {PackageJson} from 'type-fest'
|
|
2
|
+
|
|
3
|
+
export function packageJson(
|
|
4
|
+
name: string,
|
|
5
|
+
{
|
|
6
|
+
devDependencies,
|
|
7
|
+
dependencies,
|
|
8
|
+
typescript,
|
|
9
|
+
}: {
|
|
10
|
+
dependencies?: PackageJson['devDependencies']
|
|
11
|
+
devDependencies?: PackageJson['dependencies']
|
|
12
|
+
/** Include the tsc predeploy hook. */
|
|
13
|
+
typescript?: boolean
|
|
14
|
+
} = {},
|
|
15
|
+
) {
|
|
16
|
+
return {
|
|
17
|
+
name,
|
|
18
|
+
version: '0.0.0',
|
|
19
|
+
private: true,
|
|
20
|
+
type: 'module',
|
|
21
|
+
main: './app/main.ts',
|
|
22
|
+
scripts: {
|
|
23
|
+
dev: 'mikro dev',
|
|
24
|
+
},
|
|
25
|
+
dependencies: dependencies as {},
|
|
26
|
+
devDependencies: devDependencies as {},
|
|
27
|
+
...(typescript
|
|
28
|
+
? {
|
|
29
|
+
mikrojs: {
|
|
30
|
+
predeploy: ['tsc --noEmit --pretty'],
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
: {}),
|
|
34
|
+
} satisfies PackageJson
|
|
35
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type {PkgManager} from '../../pkg-manager.js'
|
|
2
|
+
|
|
3
|
+
function mikro(pm: PkgManager, cmd: string) {
|
|
4
|
+
if (pm === 'npm') return `npx mikro ${cmd}`
|
|
5
|
+
return `pnpm mikro ${cmd}`
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ReadmeOptions {
|
|
9
|
+
projectName: string
|
|
10
|
+
description: string
|
|
11
|
+
pm: PkgManager
|
|
12
|
+
hardware?: string
|
|
13
|
+
wiring?: string
|
|
14
|
+
setup?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function readme(options: ReadmeOptions) {
|
|
18
|
+
const {projectName, description, pm, hardware, wiring, setup} = options
|
|
19
|
+
|
|
20
|
+
const sections: string[] = []
|
|
21
|
+
|
|
22
|
+
sections.push(`# ${projectName}\n\n${description}`)
|
|
23
|
+
|
|
24
|
+
if (hardware) {
|
|
25
|
+
sections.push(`## Hardware\n\n${hardware}`)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (wiring) {
|
|
29
|
+
sections.push(`## Wiring\n\n${wiring}`)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (setup) {
|
|
33
|
+
sections.push(`## Setup\n\n${setup}`)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
sections.push(`## Getting started
|
|
37
|
+
|
|
38
|
+
Install dependencies:
|
|
39
|
+
|
|
40
|
+
\`\`\`sh
|
|
41
|
+
${pm} install
|
|
42
|
+
\`\`\`
|
|
43
|
+
|
|
44
|
+
Flash firmware and start developing:
|
|
45
|
+
|
|
46
|
+
\`\`\`sh
|
|
47
|
+
${mikro(pm, 'dev')}
|
|
48
|
+
\`\`\``)
|
|
49
|
+
|
|
50
|
+
sections.push(`## Commands
|
|
51
|
+
|
|
52
|
+
- \`${mikro(pm, 'dev')}\` — develop on connected device
|
|
53
|
+
- \`${mikro(pm, 'deploy')}\` — build and deploy to device
|
|
54
|
+
- \`${mikro(pm, 'console')}\` — open REPL on device
|
|
55
|
+
- \`${mikro(pm, 'env set KEY value')}\` — set environment variable on device`)
|
|
56
|
+
|
|
57
|
+
sections.push(`## Learn more
|
|
58
|
+
|
|
59
|
+
- [Mikro.js documentation](https://mikrojs.dev)
|
|
60
|
+
- [API reference](https://mikrojs.dev/api/)
|
|
61
|
+
- [Examples](https://mikrojs.dev/examples/)`)
|
|
62
|
+
|
|
63
|
+
return sections.join('\n\n') + '\n'
|
|
64
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type {TsConfigJson} from 'type-fest'
|
|
2
|
+
|
|
3
|
+
export const tsconfig: TsConfigJson = {
|
|
4
|
+
include: ['app/**/*'],
|
|
5
|
+
compilerOptions: {
|
|
6
|
+
module: 'nodenext',
|
|
7
|
+
target: 'es2024',
|
|
8
|
+
lib: ['es2024'],
|
|
9
|
+
noEmit: true,
|
|
10
|
+
types: ['mikrojs/runtime'],
|
|
11
|
+
sourceMap: true,
|
|
12
|
+
noUncheckedIndexedAccess: true,
|
|
13
|
+
allowUnreachableCode: false,
|
|
14
|
+
erasableSyntaxOnly: true,
|
|
15
|
+
strict: true,
|
|
16
|
+
verbatimModuleSyntax: true,
|
|
17
|
+
isolatedModules: true,
|
|
18
|
+
noUncheckedSideEffectImports: true,
|
|
19
|
+
moduleDetection: 'force',
|
|
20
|
+
jsx: 'preserve',
|
|
21
|
+
skipLibCheck: true,
|
|
22
|
+
noFallthroughCasesInSwitch: true,
|
|
23
|
+
noUnusedLocals: true,
|
|
24
|
+
forceConsistentCasingInFileNames: true,
|
|
25
|
+
resolveJsonModule: true,
|
|
26
|
+
},
|
|
27
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {digitalWrite, pinMode} from 'mikrojs/pin'
|
|
2
|
+
import {sleep} from 'mikrojs/sleep'
|
|
3
|
+
|
|
4
|
+
let value: 0 | 1 = 0
|
|
5
|
+
// GPIO 15 is the built-in LED on XIAO ESP32C6. Replace with your board's LED pin.
|
|
6
|
+
const PIN = 15
|
|
7
|
+
|
|
8
|
+
pinMode(PIN, 'OUTPUT').orPanic('Failed to configure LED pin')
|
|
9
|
+
|
|
10
|
+
while (true) {
|
|
11
|
+
value = value === 0 ? 1 : 0
|
|
12
|
+
const writeResult = digitalWrite(PIN, value)
|
|
13
|
+
if (!writeResult.ok) {
|
|
14
|
+
console.error('Write pin failed: %s', writeResult.error.name)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
await sleep(1000)
|
|
18
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Convert HSV (h: 0–360, s: 0–1, v: 0–1) to RGB tuple */
|
|
2
|
+
export function hsv(h: number, s: number, v: number): [r: number, g: number, b: number] {
|
|
3
|
+
h = h % 360
|
|
4
|
+
const max = v * 255
|
|
5
|
+
const min = max * (1 - s)
|
|
6
|
+
const sector = Math.floor(h / 60)
|
|
7
|
+
const adj = ((max - min) * (h % 60)) / 60
|
|
8
|
+
|
|
9
|
+
switch (sector) {
|
|
10
|
+
case 0:
|
|
11
|
+
return [max, min + adj, min]
|
|
12
|
+
case 1:
|
|
13
|
+
return [max - adj, max, min]
|
|
14
|
+
case 2:
|
|
15
|
+
return [min, max, min + adj]
|
|
16
|
+
case 3:
|
|
17
|
+
return [min, max - adj, max]
|
|
18
|
+
case 4:
|
|
19
|
+
return [min + adj, min, max]
|
|
20
|
+
default:
|
|
21
|
+
return [max, min, max - adj]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {NeoPixel} from 'mikrojs/neopixel'
|
|
2
|
+
|
|
3
|
+
import {breathe} from './patterns/breathe.js'
|
|
4
|
+
import {colorWipe} from './patterns/color-wipe.js'
|
|
5
|
+
import {comet} from './patterns/comet.js'
|
|
6
|
+
import {rainbow} from './patterns/rainbow.js'
|
|
7
|
+
import {sparkle} from './patterns/sparkle.js'
|
|
8
|
+
|
|
9
|
+
const PIN = 8
|
|
10
|
+
const NUM_LEDS = 24
|
|
11
|
+
const BRIGHTNESS = 1
|
|
12
|
+
const PATTERN_DURATION = 8000
|
|
13
|
+
|
|
14
|
+
const pixels = new NeoPixel(PIN, {count: NUM_LEDS})
|
|
15
|
+
|
|
16
|
+
const patterns = [rainbow, comet, breathe, sparkle, colorWipe]
|
|
17
|
+
|
|
18
|
+
while (true) {
|
|
19
|
+
for (const pattern of patterns) {
|
|
20
|
+
;(await pattern(pixels, NUM_LEDS, BRIGHTNESS, PATTERN_DURATION)).orPanic(
|
|
21
|
+
`NeoPixel pattern ${pattern.name} failed`,
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type {NeoPixel} from 'mikrojs/neopixel'
|
|
2
|
+
import {ok} from 'mikrojs/result'
|
|
3
|
+
import {sleep} from 'mikrojs/sleep'
|
|
4
|
+
|
|
5
|
+
import {hsv} from '../color.js'
|
|
6
|
+
|
|
7
|
+
/** Breathe: all LEDs pulse a single color in and out */
|
|
8
|
+
export async function breathe(pixels: NeoPixel, numLeds: number, brightness: number, ms: number) {
|
|
9
|
+
const end = Date.now() + ms
|
|
10
|
+
let t = 0
|
|
11
|
+
while (Date.now() < end) {
|
|
12
|
+
const v = ((Math.sin(t) + 1) / 2) * brightness
|
|
13
|
+
const [r, g, b] = hsv(30, 1, v)
|
|
14
|
+
const fillResult = pixels.fill(r, g, b)
|
|
15
|
+
if (!fillResult.ok) return fillResult
|
|
16
|
+
const showResult = pixels.show()
|
|
17
|
+
if (!showResult.ok) return showResult
|
|
18
|
+
t += 0.06
|
|
19
|
+
await sleep(20)
|
|
20
|
+
}
|
|
21
|
+
return ok(undefined)
|
|
22
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type {NeoPixel} from 'mikrojs/neopixel'
|
|
2
|
+
import {ok} from 'mikrojs/result'
|
|
3
|
+
import {sleep} from 'mikrojs/sleep'
|
|
4
|
+
|
|
5
|
+
import {hsv} from '../color.js'
|
|
6
|
+
|
|
7
|
+
/** Color wipe: fill pixels one by one, then clear one by one */
|
|
8
|
+
export async function colorWipe(pixels: NeoPixel, numLeds: number, brightness: number, ms: number) {
|
|
9
|
+
const colors: Array<[number, number, number]> = [
|
|
10
|
+
hsv(0, 1, brightness),
|
|
11
|
+
hsv(120, 1, brightness),
|
|
12
|
+
hsv(240, 1, brightness),
|
|
13
|
+
]
|
|
14
|
+
const end = Date.now() + ms
|
|
15
|
+
let ci = 0
|
|
16
|
+
while (Date.now() < end) {
|
|
17
|
+
const [r, g, b] = colors[ci % colors.length]!
|
|
18
|
+
for (let i = 0; i < numLeds; i++) {
|
|
19
|
+
const pixelResult = pixels.setPixel(i, r, g, b)
|
|
20
|
+
if (!pixelResult.ok) return pixelResult
|
|
21
|
+
const showResult = pixels.show()
|
|
22
|
+
if (!showResult.ok) return showResult
|
|
23
|
+
await sleep(25)
|
|
24
|
+
}
|
|
25
|
+
for (let i = 0; i < numLeds; i++) {
|
|
26
|
+
const pixelResult = pixels.setPixel(i, 0, 0, 0)
|
|
27
|
+
if (!pixelResult.ok) return pixelResult
|
|
28
|
+
const showResult = pixels.show()
|
|
29
|
+
if (!showResult.ok) return showResult
|
|
30
|
+
await sleep(25)
|
|
31
|
+
}
|
|
32
|
+
ci++
|
|
33
|
+
}
|
|
34
|
+
return ok(undefined)
|
|
35
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type {NeoPixel} from 'mikrojs/neopixel'
|
|
2
|
+
import {ok} from 'mikrojs/result'
|
|
3
|
+
import {sleep} from 'mikrojs/sleep'
|
|
4
|
+
|
|
5
|
+
import {hsv} from '../color.js'
|
|
6
|
+
|
|
7
|
+
/** Comet: a bright head with a fading tail orbits the ring */
|
|
8
|
+
export async function comet(pixels: NeoPixel, numLeds: number, brightness: number, ms: number) {
|
|
9
|
+
const TAIL_LEN = 8
|
|
10
|
+
const end = Date.now() + ms
|
|
11
|
+
let pos = 0
|
|
12
|
+
while (Date.now() < end) {
|
|
13
|
+
const fillResult = pixels.fill(0, 0, 0)
|
|
14
|
+
if (!fillResult.ok) return fillResult
|
|
15
|
+
for (let i = 0; i < TAIL_LEN; i++) {
|
|
16
|
+
const idx = (pos - i + numLeds) % numLeds
|
|
17
|
+
const fade = 1 - i / TAIL_LEN
|
|
18
|
+
const v = fade * fade * brightness
|
|
19
|
+
const [r, g, b] = hsv(200, 1, v)
|
|
20
|
+
const pixelResult = pixels.setPixel(idx, r, g, b)
|
|
21
|
+
if (!pixelResult.ok) return pixelResult
|
|
22
|
+
}
|
|
23
|
+
const showResult = pixels.show()
|
|
24
|
+
if (!showResult.ok) return showResult
|
|
25
|
+
pos = (pos + 1) % numLeds
|
|
26
|
+
await sleep(40)
|
|
27
|
+
}
|
|
28
|
+
return ok(undefined)
|
|
29
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type {NeoPixel} from 'mikrojs/neopixel'
|
|
2
|
+
import {ok} from 'mikrojs/result'
|
|
3
|
+
import {sleep} from 'mikrojs/sleep'
|
|
4
|
+
|
|
5
|
+
import {hsv} from '../color.js'
|
|
6
|
+
|
|
7
|
+
/** Rainbow: rotate a full spectrum around the ring */
|
|
8
|
+
export async function rainbow(pixels: NeoPixel, numLeds: number, brightness: number, ms: number) {
|
|
9
|
+
const end = Date.now() + ms
|
|
10
|
+
let offset = 0
|
|
11
|
+
while (Date.now() < end) {
|
|
12
|
+
for (let i = 0; i < numLeds; i++) {
|
|
13
|
+
const hue = ((i * 360) / numLeds + offset) % 360
|
|
14
|
+
const [r, g, b] = hsv(hue, 1, brightness)
|
|
15
|
+
const pixelResult = pixels.setPixel(i, r, g, b)
|
|
16
|
+
if (!pixelResult.ok) return pixelResult
|
|
17
|
+
}
|
|
18
|
+
const showResult = pixels.show()
|
|
19
|
+
if (!showResult.ok) return showResult
|
|
20
|
+
offset = (offset + 5) % 360
|
|
21
|
+
await sleep(30)
|
|
22
|
+
}
|
|
23
|
+
return ok()
|
|
24
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type {NeoPixel} from 'mikrojs/neopixel'
|
|
2
|
+
import {ok} from 'mikrojs/result'
|
|
3
|
+
import {sleep} from 'mikrojs/sleep'
|
|
4
|
+
|
|
5
|
+
import {hsv} from '../color.js'
|
|
6
|
+
|
|
7
|
+
/** Sparkle: random pixels flash white on a dim background */
|
|
8
|
+
export async function sparkle(pixels: NeoPixel, numLeds: number, brightness: number, ms: number) {
|
|
9
|
+
const end = Date.now() + ms
|
|
10
|
+
while (Date.now() < end) {
|
|
11
|
+
const [br, bg, bb] = hsv(270, 0.8, brightness * 0.15)
|
|
12
|
+
const fillResult = pixels.fill(br, bg, bb)
|
|
13
|
+
if (!fillResult.ok) return fillResult
|
|
14
|
+
for (let s = 0; s < 3; s++) {
|
|
15
|
+
const idx = Math.floor(Math.random() * numLeds)
|
|
16
|
+
const v = brightness * (0.5 + Math.random() * 0.5) * 255
|
|
17
|
+
const pixelResult = pixels.setPixel(idx, v, v, v)
|
|
18
|
+
if (!pixelResult.ok) return pixelResult
|
|
19
|
+
}
|
|
20
|
+
const showResult = pixels.show()
|
|
21
|
+
if (!showResult.ok) return showResult
|
|
22
|
+
await sleep(60)
|
|
23
|
+
}
|
|
24
|
+
return ok()
|
|
25
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {Pwm} from 'mikrojs/pwm'
|
|
2
|
+
|
|
3
|
+
// GPIO 15 is the built-in LED on XIAO ESP32C6. Replace with your board's LED pin.
|
|
4
|
+
const LED_PIN = 15
|
|
5
|
+
|
|
6
|
+
const led = new Pwm(LED_PIN, {freq: 50, duty: 0})
|
|
7
|
+
|
|
8
|
+
// Breathe: smoothly fade in and out forever
|
|
9
|
+
while (true) {
|
|
10
|
+
const fadeIn = await led.fade(1.0, 1000)
|
|
11
|
+
if (!fadeIn.ok) {
|
|
12
|
+
console.error('Fade in failed: %s', fadeIn.error.name)
|
|
13
|
+
break
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const fadeOut = await led.fade(0.0, 1000)
|
|
17
|
+
if (!fadeOut.ok) {
|
|
18
|
+
console.error('Fade out failed: %s', fadeOut.error.name)
|
|
19
|
+
break
|
|
20
|
+
}
|
|
21
|
+
}
|