@shiqianjiang/ceru-plugin-cli 0.1.0
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/ASSET_LICENSE +238 -0
- package/LICENSE +21 -0
- package/NOTICE +1 -0
- package/README.md +29 -0
- package/assets/catalog.json +1 -0
- package/assets/electron-app/main.cjs +1 -0
- package/assets/electron-app/package.json +8 -0
- package/assets/electron.cjs +42 -0
- package/assets/index.html +93 -0
- package/assets/originals/account.svg +1 -0
- package/assets/originals/add.svg +1 -0
- package/assets/originals/app.logo.svg +10 -0
- package/assets/originals/chart.svg +1 -0
- package/assets/originals/close.svg +1 -0
- package/assets/originals/cloud.svg +1 -0
- package/assets/originals/download.svg +1 -0
- package/assets/originals/heart.svg +1 -0
- package/assets/originals/import.svg +1 -0
- package/assets/originals/info.svg +1 -0
- package/assets/originals/library.svg +1 -0
- package/assets/originals/music-note.svg +1 -0
- package/assets/originals/pause.svg +1 -0
- package/assets/originals/placeholder.avatar.webp +0 -0
- package/assets/originals/placeholder.cover.png +0 -0
- package/assets/originals/platform.all.svg +1 -0
- package/assets/originals/platform.kg.svg +1 -0
- package/assets/originals/platform.kw.svg +1 -0
- package/assets/originals/platform.local.svg +1 -0
- package/assets/originals/platform.mg.svg +1 -0
- package/assets/originals/platform.tx.svg +1 -0
- package/assets/originals/platform.wy.svg +1 -0
- package/assets/originals/play.svg +1 -0
- package/assets/originals/refresh.svg +1 -0
- package/assets/originals/search.svg +1 -0
- package/assets/originals/server.svg +1 -0
- package/assets/originals/settings.svg +1 -0
- package/assets/originals/share.svg +1 -0
- package/assets/playground.js +446 -0
- package/assets/sandbox.js +36 -0
- package/assets/shared-react.js +77 -0
- package/assets/shared-vue.js +44 -0
- package/assets/style.css +264 -0
- package/assets/vendor-licenses/lodash-es.txt +47 -0
- package/assets/vendor-licenses/react-dom.txt +21 -0
- package/assets/vendor-licenses/react.txt +21 -0
- package/assets/vendor-licenses/scheduler.txt +21 -0
- package/assets/vendor-licenses/vue.txt +21 -0
- package/assets/vendor-licenses/vue_reactivity.txt +21 -0
- package/assets/vendor-licenses/vue_runtime-core.txt +21 -0
- package/assets/vendor-licenses/vue_runtime-dom.txt +21 -0
- package/assets/vendor-licenses/vue_shared.txt +21 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +6 -0
- package/dist/dev.d.ts +7 -0
- package/dist/dev.js +507 -0
- package/dist/frameworks.d.ts +9 -0
- package/dist/frameworks.js +310 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +206 -0
- package/dist/project.d.ts +34 -0
- package/dist/project.js +342 -0
- package/package.json +67 -0
- package/schemas/config.schema.json +610 -0
- package/templates/connected-library/js/.prettierrc.json +5 -0
- package/templates/connected-library/js/.vscode/ceru.code-snippets +27 -0
- package/templates/connected-library/js/.vscode/extensions.json +3 -0
- package/templates/connected-library/js/.vscode/launch.json +30 -0
- package/templates/connected-library/js/.vscode/settings.json +20 -0
- package/templates/connected-library/js/.vscode/tasks.json +36 -0
- package/templates/connected-library/js/README.md +38 -0
- package/templates/connected-library/js/_gitignore +6 -0
- package/templates/connected-library/js/ceru.plugin.json +76 -0
- package/templates/connected-library/js/package.json +21 -0
- package/templates/connected-library/js/src/index.js +38 -0
- package/templates/connected-library/js/tsconfig.json +16 -0
- package/templates/connected-library/js/ui/settings.json +24 -0
- package/templates/connected-library/ts/.prettierrc.json +5 -0
- package/templates/connected-library/ts/.vscode/ceru.code-snippets +27 -0
- package/templates/connected-library/ts/.vscode/extensions.json +3 -0
- package/templates/connected-library/ts/.vscode/launch.json +30 -0
- package/templates/connected-library/ts/.vscode/settings.json +20 -0
- package/templates/connected-library/ts/.vscode/tasks.json +36 -0
- package/templates/connected-library/ts/README.md +38 -0
- package/templates/connected-library/ts/_gitignore +6 -0
- package/templates/connected-library/ts/ceru.plugin.json +76 -0
- package/templates/connected-library/ts/package.json +21 -0
- package/templates/connected-library/ts/src/index.ts +38 -0
- package/templates/connected-library/ts/tsconfig.json +16 -0
- package/templates/connected-library/ts/ui/settings.json +24 -0
- package/templates/guest-adapter/js/.prettierrc.json +5 -0
- package/templates/guest-adapter/js/.vscode/ceru.code-snippets +27 -0
- package/templates/guest-adapter/js/.vscode/extensions.json +3 -0
- package/templates/guest-adapter/js/.vscode/launch.json +30 -0
- package/templates/guest-adapter/js/.vscode/settings.json +20 -0
- package/templates/guest-adapter/js/.vscode/tasks.json +36 -0
- package/templates/guest-adapter/js/README.md +38 -0
- package/templates/guest-adapter/js/_gitignore +6 -0
- package/templates/guest-adapter/js/ceru.plugin.json +95 -0
- package/templates/guest-adapter/js/package.json +21 -0
- package/templates/guest-adapter/js/src/guest.js +6 -0
- package/templates/guest-adapter/js/src/index.js +8 -0
- package/templates/guest-adapter/js/tsconfig.json +16 -0
- package/templates/guest-adapter/js/ui/settings.json +14 -0
- package/templates/guest-adapter/ts/.prettierrc.json +5 -0
- package/templates/guest-adapter/ts/.vscode/ceru.code-snippets +27 -0
- package/templates/guest-adapter/ts/.vscode/extensions.json +3 -0
- package/templates/guest-adapter/ts/.vscode/launch.json +30 -0
- package/templates/guest-adapter/ts/.vscode/settings.json +20 -0
- package/templates/guest-adapter/ts/.vscode/tasks.json +36 -0
- package/templates/guest-adapter/ts/README.md +38 -0
- package/templates/guest-adapter/ts/_gitignore +6 -0
- package/templates/guest-adapter/ts/ceru.plugin.json +95 -0
- package/templates/guest-adapter/ts/package.json +21 -0
- package/templates/guest-adapter/ts/src/guest.ts +6 -0
- package/templates/guest-adapter/ts/src/index.ts +8 -0
- package/templates/guest-adapter/ts/tsconfig.json +16 -0
- package/templates/guest-adapter/ts/ui/settings.json +14 -0
- package/templates/importer/js/.prettierrc.json +5 -0
- package/templates/importer/js/.vscode/ceru.code-snippets +27 -0
- package/templates/importer/js/.vscode/extensions.json +3 -0
- package/templates/importer/js/.vscode/launch.json +30 -0
- package/templates/importer/js/.vscode/settings.json +20 -0
- package/templates/importer/js/.vscode/tasks.json +36 -0
- package/templates/importer/js/README.md +38 -0
- package/templates/importer/js/_gitignore +6 -0
- package/templates/importer/js/ceru.plugin.json +63 -0
- package/templates/importer/js/package.json +21 -0
- package/templates/importer/js/src/index.js +37 -0
- package/templates/importer/js/tsconfig.json +16 -0
- package/templates/importer/js/ui/settings.json +24 -0
- package/templates/importer/ts/.prettierrc.json +5 -0
- package/templates/importer/ts/.vscode/ceru.code-snippets +27 -0
- package/templates/importer/ts/.vscode/extensions.json +3 -0
- package/templates/importer/ts/.vscode/launch.json +30 -0
- package/templates/importer/ts/.vscode/settings.json +20 -0
- package/templates/importer/ts/.vscode/tasks.json +36 -0
- package/templates/importer/ts/README.md +38 -0
- package/templates/importer/ts/_gitignore +6 -0
- package/templates/importer/ts/ceru.plugin.json +63 -0
- package/templates/importer/ts/package.json +21 -0
- package/templates/importer/ts/src/index.ts +37 -0
- package/templates/importer/ts/tsconfig.json +16 -0
- package/templates/importer/ts/ui/settings.json +24 -0
- package/templates/react/js/.prettierrc.json +5 -0
- package/templates/react/js/.vscode/ceru.code-snippets +27 -0
- package/templates/react/js/.vscode/extensions.json +3 -0
- package/templates/react/js/.vscode/launch.json +30 -0
- package/templates/react/js/.vscode/settings.json +20 -0
- package/templates/react/js/.vscode/tasks.json +36 -0
- package/templates/react/js/README.md +36 -0
- package/templates/react/js/_gitignore +6 -0
- package/templates/react/js/ceru.plugin.json +60 -0
- package/templates/react/js/package.json +25 -0
- package/templates/react/js/src/App.jsx +22 -0
- package/templates/react/js/src/index.js +7 -0
- package/templates/react/js/src/view.jsx +8 -0
- package/templates/react/js/tsconfig.json +16 -0
- package/templates/react/ts/.prettierrc.json +5 -0
- package/templates/react/ts/.vscode/ceru.code-snippets +27 -0
- package/templates/react/ts/.vscode/extensions.json +3 -0
- package/templates/react/ts/.vscode/launch.json +30 -0
- package/templates/react/ts/.vscode/settings.json +20 -0
- package/templates/react/ts/.vscode/tasks.json +36 -0
- package/templates/react/ts/README.md +36 -0
- package/templates/react/ts/_gitignore +6 -0
- package/templates/react/ts/ceru.plugin.json +60 -0
- package/templates/react/ts/package.json +25 -0
- package/templates/react/ts/src/App.tsx +23 -0
- package/templates/react/ts/src/index.ts +7 -0
- package/templates/react/ts/src/view.tsx +8 -0
- package/templates/react/ts/tsconfig.json +16 -0
- package/templates/snapshot.json +257 -0
- package/templates/source/js/.prettierrc.json +5 -0
- package/templates/source/js/.vscode/ceru.code-snippets +27 -0
- package/templates/source/js/.vscode/extensions.json +3 -0
- package/templates/source/js/.vscode/launch.json +30 -0
- package/templates/source/js/.vscode/settings.json +20 -0
- package/templates/source/js/.vscode/tasks.json +36 -0
- package/templates/source/js/README.md +38 -0
- package/templates/source/js/_gitignore +6 -0
- package/templates/source/js/ceru.plugin.json +51 -0
- package/templates/source/js/package.json +21 -0
- package/templates/source/js/src/index.js +50 -0
- package/templates/source/js/tsconfig.json +16 -0
- package/templates/source/ts/.prettierrc.json +5 -0
- package/templates/source/ts/.vscode/ceru.code-snippets +27 -0
- package/templates/source/ts/.vscode/extensions.json +3 -0
- package/templates/source/ts/.vscode/launch.json +30 -0
- package/templates/source/ts/.vscode/settings.json +20 -0
- package/templates/source/ts/.vscode/tasks.json +36 -0
- package/templates/source/ts/README.md +38 -0
- package/templates/source/ts/_gitignore +6 -0
- package/templates/source/ts/ceru.plugin.json +51 -0
- package/templates/source/ts/package.json +21 -0
- package/templates/source/ts/src/index.ts +50 -0
- package/templates/source/ts/tsconfig.json +16 -0
- package/templates/vue/js/.prettierrc.json +5 -0
- package/templates/vue/js/.vscode/ceru.code-snippets +27 -0
- package/templates/vue/js/.vscode/extensions.json +3 -0
- package/templates/vue/js/.vscode/launch.json +30 -0
- package/templates/vue/js/.vscode/settings.json +20 -0
- package/templates/vue/js/.vscode/tasks.json +36 -0
- package/templates/vue/js/README.md +36 -0
- package/templates/vue/js/_gitignore +6 -0
- package/templates/vue/js/ceru.plugin.json +59 -0
- package/templates/vue/js/package.json +22 -0
- package/templates/vue/js/src/App.vue +31 -0
- package/templates/vue/js/src/env.d.ts +5 -0
- package/templates/vue/js/src/index.js +7 -0
- package/templates/vue/js/src/view.js +8 -0
- package/templates/vue/js/tsconfig.json +17 -0
- package/templates/vue/ts/.prettierrc.json +5 -0
- package/templates/vue/ts/.vscode/ceru.code-snippets +27 -0
- package/templates/vue/ts/.vscode/extensions.json +3 -0
- package/templates/vue/ts/.vscode/launch.json +30 -0
- package/templates/vue/ts/.vscode/settings.json +20 -0
- package/templates/vue/ts/.vscode/tasks.json +36 -0
- package/templates/vue/ts/README.md +36 -0
- package/templates/vue/ts/_gitignore +6 -0
- package/templates/vue/ts/ceru.plugin.json +59 -0
- package/templates/vue/ts/package.json +22 -0
- package/templates/vue/ts/src/App.vue +32 -0
- package/templates/vue/ts/src/env.d.ts +5 -0
- package/templates/vue/ts/src/index.ts +7 -0
- package/templates/vue/ts/src/view.ts +8 -0
- package/templates/vue/ts/tsconfig.json +17 -0
- package/templates/vue-tsx/js/.prettierrc.json +5 -0
- package/templates/vue-tsx/js/.vscode/ceru.code-snippets +27 -0
- package/templates/vue-tsx/js/.vscode/extensions.json +3 -0
- package/templates/vue-tsx/js/.vscode/launch.json +30 -0
- package/templates/vue-tsx/js/.vscode/settings.json +20 -0
- package/templates/vue-tsx/js/.vscode/tasks.json +36 -0
- package/templates/vue-tsx/js/README.md +36 -0
- package/templates/vue-tsx/js/_gitignore +6 -0
- package/templates/vue-tsx/js/ceru.plugin.json +59 -0
- package/templates/vue-tsx/js/package.json +22 -0
- package/templates/vue-tsx/js/src/App.jsx +14 -0
- package/templates/vue-tsx/js/src/env.d.ts +5 -0
- package/templates/vue-tsx/js/src/index.js +7 -0
- package/templates/vue-tsx/js/src/view.js +8 -0
- package/templates/vue-tsx/js/tsconfig.json +17 -0
- package/templates/vue-tsx/ts/.prettierrc.json +5 -0
- package/templates/vue-tsx/ts/.vscode/ceru.code-snippets +27 -0
- package/templates/vue-tsx/ts/.vscode/extensions.json +3 -0
- package/templates/vue-tsx/ts/.vscode/launch.json +30 -0
- package/templates/vue-tsx/ts/.vscode/settings.json +20 -0
- package/templates/vue-tsx/ts/.vscode/tasks.json +36 -0
- package/templates/vue-tsx/ts/README.md +36 -0
- package/templates/vue-tsx/ts/_gitignore +6 -0
- package/templates/vue-tsx/ts/ceru.plugin.json +59 -0
- package/templates/vue-tsx/ts/package.json +22 -0
- package/templates/vue-tsx/ts/src/App.tsx +15 -0
- package/templates/vue-tsx/ts/src/env.d.ts +5 -0
- package/templates/vue-tsx/ts/src/index.ts +7 -0
- package/templates/vue-tsx/ts/src/view.ts +8 -0
- package/templates/vue-tsx/ts/tsconfig.json +17 -0
- package/templates/web-dist/js/.prettierrc.json +5 -0
- package/templates/web-dist/js/.vscode/ceru.code-snippets +27 -0
- package/templates/web-dist/js/.vscode/extensions.json +3 -0
- package/templates/web-dist/js/.vscode/launch.json +30 -0
- package/templates/web-dist/js/.vscode/settings.json +20 -0
- package/templates/web-dist/js/.vscode/tasks.json +36 -0
- package/templates/web-dist/js/README.md +38 -0
- package/templates/web-dist/js/_gitignore +6 -0
- package/templates/web-dist/js/ceru.plugin.json +57 -0
- package/templates/web-dist/js/package.json +21 -0
- package/templates/web-dist/js/src/index.js +7 -0
- package/templates/web-dist/js/tsconfig.json +16 -0
- package/templates/web-dist/js/web-dist/index.html +14 -0
- package/templates/web-dist/js/web-dist/main.js +4 -0
- package/templates/web-dist/js/web-dist/sample.png +0 -0
- package/templates/web-dist/js/web-dist/style.css +11 -0
- package/templates/web-dist/ts/.prettierrc.json +5 -0
- package/templates/web-dist/ts/.vscode/ceru.code-snippets +27 -0
- package/templates/web-dist/ts/.vscode/extensions.json +3 -0
- package/templates/web-dist/ts/.vscode/launch.json +30 -0
- package/templates/web-dist/ts/.vscode/settings.json +20 -0
- package/templates/web-dist/ts/.vscode/tasks.json +36 -0
- package/templates/web-dist/ts/README.md +38 -0
- package/templates/web-dist/ts/_gitignore +6 -0
- package/templates/web-dist/ts/ceru.plugin.json +57 -0
- package/templates/web-dist/ts/package.json +21 -0
- package/templates/web-dist/ts/src/index.ts +7 -0
- package/templates/web-dist/ts/tsconfig.json +16 -0
- package/templates/web-dist/ts/web-dist/index.html +14 -0
- package/templates/web-dist/ts/web-dist/main.js +4 -0
- package/templates/web-dist/ts/web-dist/sample.png +0 -0
- package/templates/web-dist/ts/web-dist/style.css +11 -0
- package/templates/web-surface/js/.prettierrc.json +5 -0
- package/templates/web-surface/js/.vscode/ceru.code-snippets +27 -0
- package/templates/web-surface/js/.vscode/extensions.json +3 -0
- package/templates/web-surface/js/.vscode/launch.json +30 -0
- package/templates/web-surface/js/.vscode/settings.json +20 -0
- package/templates/web-surface/js/.vscode/tasks.json +36 -0
- package/templates/web-surface/js/README.md +36 -0
- package/templates/web-surface/js/_gitignore +6 -0
- package/templates/web-surface/js/ceru.plugin.json +55 -0
- package/templates/web-surface/js/package.json +21 -0
- package/templates/web-surface/js/src/index.js +7 -0
- package/templates/web-surface/js/src/view.js +8 -0
- package/templates/web-surface/js/tsconfig.json +16 -0
- package/templates/web-surface/ts/.prettierrc.json +5 -0
- package/templates/web-surface/ts/.vscode/ceru.code-snippets +27 -0
- package/templates/web-surface/ts/.vscode/extensions.json +3 -0
- package/templates/web-surface/ts/.vscode/launch.json +30 -0
- package/templates/web-surface/ts/.vscode/settings.json +20 -0
- package/templates/web-surface/ts/.vscode/tasks.json +36 -0
- package/templates/web-surface/ts/README.md +36 -0
- package/templates/web-surface/ts/_gitignore +6 -0
- package/templates/web-surface/ts/ceru.plugin.json +55 -0
- package/templates/web-surface/ts/package.json +21 -0
- package/templates/web-surface/ts/src/index.ts +7 -0
- package/templates/web-surface/ts/src/view.ts +8 -0
- package/templates/web-surface/ts/tsconfig.json +16 -0
package/dist/project.js
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { readFile, realpath, mkdir, writeFile, rename, readdir, stat, unlink, } from 'node:fs/promises';
|
|
2
|
+
import { dirname, resolve, relative, isAbsolute, sep, extname, basename } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
import { build } from 'esbuild';
|
|
6
|
+
import ts from 'typescript';
|
|
7
|
+
import { spawnSync } from 'node:child_process';
|
|
8
|
+
import { createRequire } from 'node:module';
|
|
9
|
+
import { sharedPlugin, vuePlugin, webDistEntry } from './frameworks.js';
|
|
10
|
+
import { encodeArtifact, parseJsonStrict, readArtifact, validateManifest, LIMITS, } from '@shiqianjiang/ceru-plugin-issuer';
|
|
11
|
+
export async function writeAtomic(path, data, overwrite = false, mode = 0o644) {
|
|
12
|
+
await mkdir(dirname(path), { recursive: true });
|
|
13
|
+
if (!overwrite) {
|
|
14
|
+
// Exclusive creation avoids overwriting user files, including a symlink target.
|
|
15
|
+
await writeFile(path, data, { flag: 'wx', mode });
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const tmp = path + '.' + randomUUID() + '.tmp';
|
|
19
|
+
try {
|
|
20
|
+
await writeFile(tmp, data, { flag: 'wx', mode });
|
|
21
|
+
await rename(tmp, path);
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
await unlink(tmp).catch((e) => {
|
|
25
|
+
if (e.code !== 'ENOENT')
|
|
26
|
+
throw e;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function inside(root, path) {
|
|
31
|
+
if (isAbsolute(path))
|
|
32
|
+
throw new Error('Project input must be relative: ' + path);
|
|
33
|
+
const realRoot = await realpath(root);
|
|
34
|
+
const target = await realpath(resolve(root, path));
|
|
35
|
+
const rel = relative(realRoot, target);
|
|
36
|
+
if (rel === '..' || rel.startsWith('..' + sep) || isAbsolute(rel))
|
|
37
|
+
throw new Error('Input escapes project root: ' + path);
|
|
38
|
+
return target;
|
|
39
|
+
}
|
|
40
|
+
export async function loadProject(project) {
|
|
41
|
+
const root = await realpath(resolve(project));
|
|
42
|
+
const raw = parseJsonStrict(await readFile(resolve(root, 'ceru.plugin.json'), 'utf8'));
|
|
43
|
+
for (const key of Object.keys(raw))
|
|
44
|
+
if (![
|
|
45
|
+
'manifest',
|
|
46
|
+
'entries',
|
|
47
|
+
'resources',
|
|
48
|
+
'output',
|
|
49
|
+
'framework',
|
|
50
|
+
'sharedLibraries',
|
|
51
|
+
'webDist',
|
|
52
|
+
].includes(key))
|
|
53
|
+
throw new Error('Unknown build config key: ' + key);
|
|
54
|
+
if (raw.sharedLibraries !== undefined)
|
|
55
|
+
raw.manifest.engines.libraries = raw.sharedLibraries;
|
|
56
|
+
if (raw.framework && !['vanilla', 'vue', 'react'].includes(raw.framework))
|
|
57
|
+
throw new Error('Unsupported framework');
|
|
58
|
+
validateManifest(raw.manifest);
|
|
59
|
+
if (!raw.entries || typeof raw.entries !== 'object' || Array.isArray(raw.entries))
|
|
60
|
+
throw new Error('entries must map module IDs to source paths');
|
|
61
|
+
if (Object.keys(raw.entries).length > 128)
|
|
62
|
+
throw new Error('Too many entry points');
|
|
63
|
+
for (const [id, path] of Object.entries(raw.entries)) {
|
|
64
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/.test(id) || typeof path !== 'string')
|
|
65
|
+
throw new Error('Invalid module entry: ' + id);
|
|
66
|
+
}
|
|
67
|
+
return { root, config: raw };
|
|
68
|
+
}
|
|
69
|
+
function checkTypes(root) {
|
|
70
|
+
const path = resolve(root, 'tsconfig.json');
|
|
71
|
+
const read = ts.readConfigFile(path, ts.sys.readFile);
|
|
72
|
+
if (read.error)
|
|
73
|
+
throw new Error(ts.flattenDiagnosticMessageText(read.error.messageText, '\n'));
|
|
74
|
+
const config = ts.parseJsonConfigFileContent(read.config, ts.sys, root);
|
|
75
|
+
const program = ts.createProgram(config.fileNames, { ...config.options, noEmit: true });
|
|
76
|
+
const diagnostics = [...config.errors, ...ts.getPreEmitDiagnostics(program)];
|
|
77
|
+
if (diagnostics.length) {
|
|
78
|
+
throw new Error(ts.formatDiagnosticsWithColorAndContext(diagnostics, {
|
|
79
|
+
getCurrentDirectory: () => root,
|
|
80
|
+
getCanonicalFileName: (f) => f,
|
|
81
|
+
getNewLine: () => '\n',
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
return program;
|
|
85
|
+
}
|
|
86
|
+
export async function buildProject(project = '.', options = {}) {
|
|
87
|
+
const { root, config } = await loadProject(project);
|
|
88
|
+
if (config.framework === 'vue') {
|
|
89
|
+
const executable = createRequire(import.meta.url).resolve('vue-tsc/bin/vue-tsc.js');
|
|
90
|
+
const result = spawnSync(process.execPath, [executable, '--noEmit', '--pretty', 'false', '-p', resolve(root, 'tsconfig.json')], { cwd: root, encoding: 'utf8', maxBuffer: 4 * 1024 * 1024 });
|
|
91
|
+
if (result.status !== 0)
|
|
92
|
+
throw new Error(result.stdout + result.stderr);
|
|
93
|
+
}
|
|
94
|
+
const program = checkTypes(root);
|
|
95
|
+
const checker = program.getTypeChecker();
|
|
96
|
+
const chunks = [];
|
|
97
|
+
const devModules = {};
|
|
98
|
+
const plugins = [sharedPlugin(config.sharedLibraries), vuePlugin(root, config.framework)];
|
|
99
|
+
const defines = {
|
|
100
|
+
'process.env.NODE_ENV': '"production"',
|
|
101
|
+
__VUE_OPTIONS_API__: 'true',
|
|
102
|
+
__VUE_PROD_DEVTOOLS__: 'false',
|
|
103
|
+
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'false',
|
|
104
|
+
};
|
|
105
|
+
for (const [id, file] of Object.entries(config.entries)) {
|
|
106
|
+
const entry = await inside(root, file);
|
|
107
|
+
const sourceFile = program.getSourceFile(entry);
|
|
108
|
+
const moduleSymbol = sourceFile && checker.getSymbolAtLocation(sourceFile);
|
|
109
|
+
const defaultExport = moduleSymbol &&
|
|
110
|
+
checker.getExportsOfModule(moduleSymbol).find((symbol) => symbol.name === 'default');
|
|
111
|
+
if (!sourceFile ||
|
|
112
|
+
!defaultExport ||
|
|
113
|
+
!checker.getSignaturesOfType(checker.getTypeOfSymbolAtLocation(defaultExport, sourceFile), ts.SignatureKind.Call).length) {
|
|
114
|
+
throw new Error('Entry must be included in tsconfig and default-export a function: ' + file);
|
|
115
|
+
}
|
|
116
|
+
const result = await build({
|
|
117
|
+
absWorkingDir: root,
|
|
118
|
+
entryPoints: [entry],
|
|
119
|
+
bundle: true,
|
|
120
|
+
write: false,
|
|
121
|
+
format: 'iife',
|
|
122
|
+
globalName: '__ceru_entry',
|
|
123
|
+
platform: 'browser',
|
|
124
|
+
target: 'es2022',
|
|
125
|
+
charset: 'utf8',
|
|
126
|
+
minify: false,
|
|
127
|
+
sourcemap: false,
|
|
128
|
+
splitting: false,
|
|
129
|
+
metafile: true,
|
|
130
|
+
logLevel: 'silent',
|
|
131
|
+
tsconfig: resolve(root, 'tsconfig.json'),
|
|
132
|
+
outfile: 'entry.js',
|
|
133
|
+
legalComments: 'inline',
|
|
134
|
+
plugins,
|
|
135
|
+
define: defines,
|
|
136
|
+
loader: {
|
|
137
|
+
'.svg': 'text',
|
|
138
|
+
'.css': 'text',
|
|
139
|
+
'.png': 'dataurl',
|
|
140
|
+
'.jpg': 'dataurl',
|
|
141
|
+
'.jpeg': 'dataurl',
|
|
142
|
+
'.webp': 'dataurl',
|
|
143
|
+
'.woff2': 'dataurl',
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
if (result.outputFiles.length !== 1)
|
|
147
|
+
throw new Error('Entry emitted sidecar files: ' + id);
|
|
148
|
+
for (const info of Object.values(result.metafile.outputs))
|
|
149
|
+
if (info.imports.length)
|
|
150
|
+
throw new Error('Unbundled import in ' + id);
|
|
151
|
+
const source = result.outputFiles[0].text;
|
|
152
|
+
chunks.push(JSON.stringify(id) +
|
|
153
|
+
': async function(ctx) {\n' +
|
|
154
|
+
source +
|
|
155
|
+
'\nif (typeof __ceru_entry.default !== "function") throw new Error("Entry must default-export a function");\nreturn __ceru_entry.default(ctx);\n}');
|
|
156
|
+
if (options.development) {
|
|
157
|
+
const debug = await build({
|
|
158
|
+
absWorkingDir: root,
|
|
159
|
+
entryPoints: [entry],
|
|
160
|
+
bundle: true,
|
|
161
|
+
write: false,
|
|
162
|
+
format: 'iife',
|
|
163
|
+
globalName: '__ceru_entry',
|
|
164
|
+
platform: 'browser',
|
|
165
|
+
target: 'es2022',
|
|
166
|
+
charset: 'utf8',
|
|
167
|
+
sourcemap: 'inline',
|
|
168
|
+
sourcesContent: true,
|
|
169
|
+
sourceRoot: 'ceru:///',
|
|
170
|
+
logLevel: 'silent',
|
|
171
|
+
tsconfig: resolve(root, 'tsconfig.json'),
|
|
172
|
+
outfile: 'entry.js',
|
|
173
|
+
plugins,
|
|
174
|
+
define: defines,
|
|
175
|
+
footer: { js: 'globalThis.__ceruStart(__ceru_entry.default);' },
|
|
176
|
+
loader: {
|
|
177
|
+
'.svg': 'text',
|
|
178
|
+
'.css': 'text',
|
|
179
|
+
'.png': 'dataurl',
|
|
180
|
+
'.jpg': 'dataurl',
|
|
181
|
+
'.webp': 'dataurl',
|
|
182
|
+
'.woff2': 'dataurl',
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
devModules[id] = debug.outputFiles[0].text;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
for (const [id, dir] of Object.entries(config.webDist ?? {})) {
|
|
189
|
+
if (config.entries[id])
|
|
190
|
+
throw new Error('Duplicate source/webDist entry: ' + id);
|
|
191
|
+
const directory = await inside(root, dir);
|
|
192
|
+
const web = await webDistEntry(directory);
|
|
193
|
+
const base = {
|
|
194
|
+
absWorkingDir: root,
|
|
195
|
+
entryPoints: [web.entry],
|
|
196
|
+
bundle: true,
|
|
197
|
+
write: false,
|
|
198
|
+
format: 'iife',
|
|
199
|
+
globalName: '__ceru_entry',
|
|
200
|
+
platform: 'browser',
|
|
201
|
+
target: 'es2022',
|
|
202
|
+
charset: 'utf8',
|
|
203
|
+
plugins: [web.plugin, ...plugins],
|
|
204
|
+
define: defines,
|
|
205
|
+
outfile: 'entry.js',
|
|
206
|
+
logLevel: 'silent',
|
|
207
|
+
};
|
|
208
|
+
const result = await build(base);
|
|
209
|
+
if (result.outputFiles.length !== 1)
|
|
210
|
+
throw new Error('webDist emitted an external file');
|
|
211
|
+
chunks.push(JSON.stringify(id) +
|
|
212
|
+
': async function(ctx) {\n' +
|
|
213
|
+
result.outputFiles[0].text +
|
|
214
|
+
'\nreturn __ceru_entry.default(ctx);\n}');
|
|
215
|
+
if (options.development) {
|
|
216
|
+
const debug = await build({
|
|
217
|
+
...base,
|
|
218
|
+
sourcemap: 'inline',
|
|
219
|
+
sourceRoot: 'ceru:///',
|
|
220
|
+
footer: { js: 'globalThis.__ceruStart(__ceru_entry.default);' },
|
|
221
|
+
});
|
|
222
|
+
devModules[id] = debug.outputFiles[0].text;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const resources = Object.create(null);
|
|
226
|
+
for (const [id, input] of Object.entries(config.resources ?? {})) {
|
|
227
|
+
if (!input ||
|
|
228
|
+
!['json', 'text', 'base64'].includes(input.type) ||
|
|
229
|
+
typeof input.path !== 'string')
|
|
230
|
+
throw new Error('Invalid resource: ' + id);
|
|
231
|
+
const path = await inside(root, input.path);
|
|
232
|
+
if ((await stat(path)).size > LIMITS.resources)
|
|
233
|
+
throw new Error('Resource too large: ' + id);
|
|
234
|
+
const bytes = await readFile(path);
|
|
235
|
+
if (input.type === 'json')
|
|
236
|
+
resources[id] = {
|
|
237
|
+
type: 'json',
|
|
238
|
+
value: parseJsonStrict(new TextDecoder('utf-8', { fatal: true }).decode(bytes)),
|
|
239
|
+
};
|
|
240
|
+
else if (input.type === 'text')
|
|
241
|
+
resources[id] = {
|
|
242
|
+
type: 'text',
|
|
243
|
+
value: new TextDecoder('utf-8', { fatal: true }).decode(bytes),
|
|
244
|
+
...(input.mime ? { mime: input.mime } : {}),
|
|
245
|
+
};
|
|
246
|
+
else
|
|
247
|
+
resources[id] = {
|
|
248
|
+
type: 'base64',
|
|
249
|
+
value: bytes.toString('base64'),
|
|
250
|
+
mime: input.mime ?? 'application/octet-stream',
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
const body = 'CeruPlugin.define({\nmodules: {\n' +
|
|
254
|
+
chunks.join(',\n') +
|
|
255
|
+
'\n},\nresources: ' +
|
|
256
|
+
JSON.stringify(resources) +
|
|
257
|
+
'\n})\n';
|
|
258
|
+
const header = {
|
|
259
|
+
formatVersion: 2,
|
|
260
|
+
syntax: 'js',
|
|
261
|
+
manifest: config.manifest,
|
|
262
|
+
signature: null,
|
|
263
|
+
};
|
|
264
|
+
const artifact = encodeArtifact(header, body);
|
|
265
|
+
readArtifact(artifact);
|
|
266
|
+
const output = resolve(root, options.out ?? config.output ?? 'dist/plugin.js');
|
|
267
|
+
if (!['.js', '.jsx'].includes(extname(output)))
|
|
268
|
+
throw new Error('Final output must be a .js or .jsx file containing compiled JavaScript');
|
|
269
|
+
const rel = relative(root, output);
|
|
270
|
+
if (rel === '..' || rel.startsWith('..' + sep) || isAbsolute(rel))
|
|
271
|
+
throw new Error('Build output must stay inside project');
|
|
272
|
+
await writeAtomic(output, artifact, options.overwrite ?? true);
|
|
273
|
+
return { path: output, bytes: artifact.length, devModules };
|
|
274
|
+
}
|
|
275
|
+
export const TEMPLATES = [
|
|
276
|
+
'source',
|
|
277
|
+
'connected-library',
|
|
278
|
+
'importer',
|
|
279
|
+
'guest-adapter',
|
|
280
|
+
'web-surface',
|
|
281
|
+
'vue',
|
|
282
|
+
'vue-tsx',
|
|
283
|
+
'react',
|
|
284
|
+
'web-dist',
|
|
285
|
+
];
|
|
286
|
+
export async function scaffoldProject(destination, options = {}) {
|
|
287
|
+
const template = options.template ?? 'source';
|
|
288
|
+
const language = options.language ?? 'ts';
|
|
289
|
+
if (!TEMPLATES.includes(template))
|
|
290
|
+
throw new Error('Unknown template. Choose: ' + TEMPLATES.join(', '));
|
|
291
|
+
if (!['ts', 'js'].includes(language))
|
|
292
|
+
throw new Error('--lang must be ts or js');
|
|
293
|
+
const root = resolve(destination);
|
|
294
|
+
try {
|
|
295
|
+
if ((await readdir(root)).length)
|
|
296
|
+
throw new Error('Destination is not empty: ' + root);
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
if (error.code !== 'ENOENT')
|
|
300
|
+
throw error;
|
|
301
|
+
}
|
|
302
|
+
const slug = basename(root)
|
|
303
|
+
.toLowerCase()
|
|
304
|
+
.replace(/[^a-z0-9-]/g, '-')
|
|
305
|
+
.replace(/^-+|-+$/g, '') || 'my-plugin';
|
|
306
|
+
const base = fileURLToPath(new URL('../templates/', import.meta.url));
|
|
307
|
+
const snapshot = JSON.parse(await readFile(resolve(base, 'snapshot.json'), 'utf8'));
|
|
308
|
+
const prefix = template + '/' + language + '/';
|
|
309
|
+
const files = snapshot.files.filter((path) => path.startsWith(prefix));
|
|
310
|
+
if (!files.length)
|
|
311
|
+
throw new Error('Template snapshot is missing: ' + prefix);
|
|
312
|
+
for (const path of files) {
|
|
313
|
+
if (path.includes('..') || path.includes('\\') || isAbsolute(path))
|
|
314
|
+
throw new Error('Invalid template snapshot path');
|
|
315
|
+
const rel = path.slice(prefix.length);
|
|
316
|
+
const name = rel === '_gitignore' ? '.gitignore' : rel;
|
|
317
|
+
const bytes = await readFile(resolve(base, path));
|
|
318
|
+
let contents = bytes;
|
|
319
|
+
if (name === 'package.json') {
|
|
320
|
+
const pkg = JSON.parse(bytes.toString('utf8'));
|
|
321
|
+
pkg.name = slug;
|
|
322
|
+
contents = JSON.stringify(pkg, null, 2) + '\n';
|
|
323
|
+
}
|
|
324
|
+
if (name === 'ceru.plugin.json') {
|
|
325
|
+
const cfg = JSON.parse(bytes.toString('utf8'));
|
|
326
|
+
const old = cfg.manifest.name;
|
|
327
|
+
cfg.manifest.id = 'local.' + slug;
|
|
328
|
+
cfg.manifest.name = slug;
|
|
329
|
+
for (const provider of cfg.manifest.contributes?.providers ?? [])
|
|
330
|
+
if (provider.name === old)
|
|
331
|
+
provider.name = slug;
|
|
332
|
+
for (const item of cfg.manifest.contributes?.sidebarItems ?? [])
|
|
333
|
+
if (item.title === old)
|
|
334
|
+
item.title = slug;
|
|
335
|
+
contents = JSON.stringify(cfg, null, 2) + '\n';
|
|
336
|
+
}
|
|
337
|
+
if (name === 'README.md')
|
|
338
|
+
contents = bytes.toString('utf8').replace(/^# .*/, '# ' + slug);
|
|
339
|
+
await writeAtomic(resolve(root, name), contents);
|
|
340
|
+
}
|
|
341
|
+
return realpath(root);
|
|
342
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shiqianjiang/ceru-plugin-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript scaffolding, single-file build, watch, validation, signing and issuance for Ceru plugins",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"ceru-plugin": "./dist/bin.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"assets",
|
|
21
|
+
"schemas",
|
|
22
|
+
"templates",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE",
|
|
25
|
+
"ASSET_LICENSE",
|
|
26
|
+
"NOTICE"
|
|
27
|
+
],
|
|
28
|
+
"license": "MIT AND AGPL-3.0-only",
|
|
29
|
+
"author": "澜音团队",
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=22.12.0"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@shiqianjiang/ceru-plugin-issuer": "0.1.0",
|
|
35
|
+
"@babel/core": "^7.29.7",
|
|
36
|
+
"@vue/babel-plugin-jsx": "^2.0.1",
|
|
37
|
+
"@vue/compiler-sfc": "3.5.43",
|
|
38
|
+
"esbuild": "^0.28.2",
|
|
39
|
+
"lodash-es": "^4.18.1",
|
|
40
|
+
"parse5": "^8.0.1",
|
|
41
|
+
"semver": "^7.7.0",
|
|
42
|
+
"vue": "3.5.43",
|
|
43
|
+
"vue-tsc": "^3.3.11",
|
|
44
|
+
"react": "19.3.0",
|
|
45
|
+
"react-dom": "19.3.0",
|
|
46
|
+
"typescript": "~5.9.3"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public",
|
|
50
|
+
"registry": "https://registry.npmjs.org/"
|
|
51
|
+
},
|
|
52
|
+
"repository": {
|
|
53
|
+
"type": "git",
|
|
54
|
+
"url": "git+https://github.com/CeruMusic/CeruMusic-Plugin-Cli.git",
|
|
55
|
+
"directory": "packages/cli"
|
|
56
|
+
},
|
|
57
|
+
"bugs": {
|
|
58
|
+
"url": "https://github.com/CeruMusic/CeruMusic-Plugin-Cli/issues"
|
|
59
|
+
},
|
|
60
|
+
"homepage": "https://github.com/CeruMusic/CeruMusic-Plugin-Cli#readme",
|
|
61
|
+
"keywords": [
|
|
62
|
+
"ceru-music",
|
|
63
|
+
"plugin",
|
|
64
|
+
"typescript",
|
|
65
|
+
"electron"
|
|
66
|
+
]
|
|
67
|
+
}
|