@shiqianjiang/ceru-plugin-cli 0.2.2 → 0.2.3
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/README.md +2 -0
- package/dist/index.js +1 -1
- package/dist/project.js +27 -9
- package/package.json +1 -1
- package/schemas/config.schema.json +4 -0
- package/templates/snapshot.json +1 -1
package/README.md
CHANGED
|
@@ -24,6 +24,8 @@ ceru-plugin sign dist/plugin.js --key .keys/publisher.private.pem
|
|
|
24
24
|
|
|
25
25
|
Vue/React 生产运行代码会直接打入发行文件,不依赖宿主提供框架。执行 `ceru-plugin preview dist/plugin.js` 可以只加载最终文件验证页面。0.2.0 起发行格式使用静态 `exports.manifest / exports.activate / exports.surfaces`,并支持手写单文件插件。
|
|
26
26
|
|
|
27
|
+
构建产物保留可读的入口名称(如 `LogicMain`、`UiStudioSurface`),并使用 `const` 声明每个 esbuild 入口容器,方便在单文件产物和错误堆栈中定位逻辑。插件源码仍可按需要使用函数或 class;构建器不会强制某一种编程风格。
|
|
28
|
+
|
|
27
29
|
在多根/父目录工作区中,请打开生成的 ceru-plugin.code-workspace 或把插件工程本身加入工作区。已经运行 dev 时选择 Attach to Ceru plugin;Launch 会启动或复用当前项目的 Host。
|
|
28
30
|
|
|
29
31
|
当前 v1 Host 不能直接安装 v2 产物。开发工作台不代替生产凭据保险箱、完整音乐业务或 Guest 安装。
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { createTemplate, generateSigningKeys, parseJsonStrict, PreparedIssuer, r
|
|
|
6
6
|
import { buildProject, scaffoldProject, TEMPLATES, writeAtomic } from './project.js';
|
|
7
7
|
import { runDev } from './dev.js';
|
|
8
8
|
export { buildProject, loadProject, scaffoldProject, TEMPLATES } from './project.js';
|
|
9
|
-
const VERSION = '0.2.
|
|
9
|
+
const VERSION = '0.2.3';
|
|
10
10
|
const HELP = 'Ceru Plugin CLI ' +
|
|
11
11
|
VERSION +
|
|
12
12
|
'\n\n' +
|
package/dist/project.js
CHANGED
|
@@ -9,6 +9,14 @@ import { createRequire } from 'node:module';
|
|
|
9
9
|
import { stylesheetPlugin, vuePlugin, webDistEntry } from './frameworks.js';
|
|
10
10
|
import { hostModulesPlugin, assertBundledDependencies } from './dependencies.js';
|
|
11
11
|
import { encodeArtifact, parseJsonStrict, readArtifact, validateManifest, LIMITS, } from '@shiqianjiang/ceru-plugin-issuer';
|
|
12
|
+
function entryFunctionName(id, suffix) {
|
|
13
|
+
const words = id.split(/[^a-zA-Z0-9]+/).filter(Boolean);
|
|
14
|
+
const name = words
|
|
15
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
16
|
+
.join('');
|
|
17
|
+
const base = name || 'Plugin';
|
|
18
|
+
return base.startsWith(suffix) || base.endsWith(suffix) ? base : base + suffix;
|
|
19
|
+
}
|
|
12
20
|
export async function writeAtomic(path, data, overwrite = false, mode = 0o644) {
|
|
13
21
|
await mkdir(dirname(path), { recursive: true });
|
|
14
22
|
if (!overwrite) {
|
|
@@ -98,6 +106,9 @@ export async function buildProject(project = '.', options = {}) {
|
|
|
98
106
|
const checker = program.getTypeChecker();
|
|
99
107
|
const chunks = new Map();
|
|
100
108
|
const devModules = {};
|
|
109
|
+
const surfaceEntries = new Set((config.manifest.modules.surfaces ?? [])
|
|
110
|
+
.filter((surface) => surface.kind === 'web')
|
|
111
|
+
.map((surface) => surface.entry));
|
|
101
112
|
const plugins = [hostModulesPlugin(), vuePlugin(root, config.framework), stylesheetPlugin()];
|
|
102
113
|
const defines = {
|
|
103
114
|
'process.env.NODE_ENV': '"production"',
|
|
@@ -151,9 +162,15 @@ export async function buildProject(project = '.', options = {}) {
|
|
|
151
162
|
for (const info of Object.values(result.metafile.outputs))
|
|
152
163
|
if (info.imports.length)
|
|
153
164
|
throw new Error('Unbundled import in ' + id);
|
|
154
|
-
const source = result.outputFiles[0].text;
|
|
165
|
+
const source = result.outputFiles[0].text.replace(/(^|\n)var __ceru_entry =/, '$1const __ceru_entry =');
|
|
155
166
|
assertBundledDependencies(source);
|
|
156
|
-
chunks.set(id, 'async function
|
|
167
|
+
chunks.set(id, 'async function ' +
|
|
168
|
+
entryFunctionName(id, id === config.manifest.modules.logic?.entry
|
|
169
|
+
? 'Logic'
|
|
170
|
+
: surfaceEntries.has(id)
|
|
171
|
+
? 'Surface'
|
|
172
|
+
: 'Module') +
|
|
173
|
+
'(ctx) {\n' +
|
|
157
174
|
source +
|
|
158
175
|
'\nif (typeof __ceru_entry.default !== "function") throw new Error("Entry must default-export a function");\nreturn __ceru_entry.default(ctx);\n}');
|
|
159
176
|
if (options.development) {
|
|
@@ -212,9 +229,10 @@ export async function buildProject(project = '.', options = {}) {
|
|
|
212
229
|
const result = await build(base);
|
|
213
230
|
if (result.outputFiles.length !== 1)
|
|
214
231
|
throw new Error('webDist emitted an external file');
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
232
|
+
const source = result.outputFiles[0].text.replace(/(^|\n)var __ceru_entry =/, '$1const __ceru_entry =');
|
|
233
|
+
assertBundledDependencies(source);
|
|
234
|
+
chunks.set(id, 'async function ' + entryFunctionName(id, 'Surface') + '(ctx) {\n' +
|
|
235
|
+
source +
|
|
218
236
|
'\nreturn __ceru_entry.default(ctx);\n}');
|
|
219
237
|
if (options.development) {
|
|
220
238
|
const debug = await build({
|
|
@@ -262,7 +280,7 @@ export async function buildProject(project = '.', options = {}) {
|
|
|
262
280
|
const logic = chunks.get(logicEntry);
|
|
263
281
|
if (!logic)
|
|
264
282
|
throw new Error('Missing compiled logic entry: ' + logicEntry);
|
|
265
|
-
body.push('
|
|
283
|
+
body.push('// Invisible plugin logic\nexports.activate = ' + logic + ';');
|
|
266
284
|
emitted.add(logicEntry);
|
|
267
285
|
}
|
|
268
286
|
const visibleSurfaces = (config.manifest.modules.surfaces ?? []).filter((surface) => surface.kind === 'web');
|
|
@@ -274,14 +292,14 @@ export async function buildProject(project = '.', options = {}) {
|
|
|
274
292
|
emitted.add(surface.entry);
|
|
275
293
|
return JSON.stringify(surface.id) + ': ' + entry;
|
|
276
294
|
});
|
|
277
|
-
body.push('
|
|
295
|
+
body.push('// Visible plugin surfaces\nexports.surfaces = {\n' + entries.join(',\n') + '\n};');
|
|
278
296
|
}
|
|
279
297
|
const modules = [...chunks].filter(([id]) => !emitted.has(id));
|
|
280
298
|
if (modules.length)
|
|
281
|
-
body.push('
|
|
299
|
+
body.push('// Additional plugin modules\nexports.modules = {\n' +
|
|
282
300
|
modules.map(([id, entry]) => JSON.stringify(id) + ': ' + entry).join(',\n') +
|
|
283
301
|
'\n};');
|
|
284
|
-
body.push('
|
|
302
|
+
body.push('// Embedded static resources\nexports.resources = ' + JSON.stringify(resources) + ';');
|
|
285
303
|
const header = {
|
|
286
304
|
formatVersion: 2,
|
|
287
305
|
syntax: 'js',
|
package/package.json
CHANGED
package/templates/snapshot.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 1,
|
|
3
3
|
"source": "https://github.com/CeruMusic/CeruMusic-Plugin-Template",
|
|
4
|
-
"digest": "sha256:
|
|
4
|
+
"digest": "sha256:ae1579ae205e6cc4fc7a80401625b08ee764bd8aca91b5ca63c0d63dba5d8abb",
|
|
5
5
|
"files": [
|
|
6
6
|
"connected-library/js/_gitignore",
|
|
7
7
|
"connected-library/js/.prettierrc.json",
|