@parall/cli 1.74.0 → 1.75.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/dist/commands/apps-add.d.ts +6 -0
- package/dist/commands/apps-add.d.ts.map +1 -0
- package/dist/commands/apps-add.js +93 -0
- package/dist/commands/apps-blocks.d.ts +96 -0
- package/dist/commands/apps-blocks.d.ts.map +1 -0
- package/dist/commands/apps-blocks.js +196 -0
- package/dist/commands/apps-scaffold-actions.d.ts +4 -9
- package/dist/commands/apps-scaffold-actions.d.ts.map +1 -1
- package/dist/commands/apps-scaffold-actions.js +4 -163
- package/dist/commands/apps-scaffold.d.ts +5 -4
- package/dist/commands/apps-scaffold.d.ts.map +1 -1
- package/dist/commands/apps-scaffold.js +24 -144
- package/dist/commands/apps-template.d.ts +15 -0
- package/dist/commands/apps-template.d.ts.map +1 -0
- package/dist/commands/apps-template.js +105 -0
- package/dist/commands/apps-templates.gen.d.ts +5 -0
- package/dist/commands/apps-templates.gen.d.ts.map +1 -0
- package/dist/commands/apps-templates.gen.js +540 -0
- package/dist/commands/apps.d.ts +5 -4
- package/dist/commands/apps.d.ts.map +1 -1
- package/dist/commands/apps.js +7 -4
- package/dist/lib/output.d.ts +11 -0
- package/dist/lib/output.d.ts.map +1 -1
- package/dist/lib/output.js +40 -4
- package/package.json +25 -5
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { promises as fs } from 'node:fs';
|
|
2
2
|
import { join, resolve, sep } from 'node:path';
|
|
3
3
|
import { printError } from '../lib/output.js';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
4
|
+
import { scaffoldProject } from './apps-template.js';
|
|
5
|
+
/** `parall app init`: the scaffold of design §7.4 — Vite + React + TS +
|
|
6
|
+
* Tailwind + shadcn/ui with the host bridge wired (apps-template.ts);
|
|
7
|
+
* `--actions` adds the server-side actions, the schema and an example list
|
|
8
|
+
* that reads and writes through them. Blocks go on top with `parall app add`
|
|
9
|
+
* (apps-add.ts). */
|
|
10
10
|
export function registerAppScaffoldCommands(app) {
|
|
11
11
|
app
|
|
12
12
|
.command('init')
|
|
13
|
-
.description('Scaffold a new Mini App project (Vite + React + TS, bridge wired)')
|
|
13
|
+
.description('Scaffold a new Mini App project (Vite + React + TS + Tailwind + shadcn/ui, bridge wired)')
|
|
14
14
|
.argument('<dir>', 'Directory to create (must be empty or absent)')
|
|
15
|
-
.option('--actions', 'Also scaffold server-side actions (actions/ → dist/_actions/index.js)')
|
|
15
|
+
.option('--actions', 'Also scaffold server-side actions, the schema and an example list wired to them (actions/ → dist/_actions/index.js)')
|
|
16
16
|
.action(async (dir, opts) => {
|
|
17
17
|
try {
|
|
18
18
|
const out = resolve(dir);
|
|
@@ -21,7 +21,7 @@ export function registerAppScaffoldCommands(app) {
|
|
|
21
21
|
throw new Error(`${out} is not empty`);
|
|
22
22
|
}
|
|
23
23
|
const name = out.split(sep).pop() ?? 'mini-app';
|
|
24
|
-
const files =
|
|
24
|
+
const files = scaffoldProject({ name, actions: Boolean(opts.actions) });
|
|
25
25
|
for (const [rel, content] of files) {
|
|
26
26
|
const target = join(out, rel);
|
|
27
27
|
await fs.mkdir(resolve(target, '..'), { recursive: true });
|
|
@@ -32,12 +32,24 @@ export function registerAppScaffoldCommands(app) {
|
|
|
32
32
|
'',
|
|
33
33
|
'Next steps:',
|
|
34
34
|
` cd ${dir} && pnpm install && pnpm build`,
|
|
35
|
-
...(opts.actions ? [' parall app check dist # manifest ↔ actions/'] : []),
|
|
36
35
|
` parall app create --name "${name}"`,
|
|
36
|
+
...(opts.actions
|
|
37
|
+
? [
|
|
38
|
+
' parall app db exec --app <app_…> --file db/schema.sql # create the tables',
|
|
39
|
+
' parall app check dist # manifest ↔ actions/',
|
|
40
|
+
]
|
|
41
|
+
: []),
|
|
37
42
|
` parall app publish dist --app <app_…> --source .`,
|
|
43
|
+
// `app dev` runs until stopped: an agent starts it in the background.
|
|
38
44
|
opts.actions
|
|
39
|
-
? ` parall app dev --dist dist --app <app_…> #
|
|
40
|
-
: ` parall app dev --dist dist
|
|
45
|
+
? ` parall app dev --dist dist --app <app_…> > dev.log 2>&1 & # runs until stopped; actions run on this machine`
|
|
46
|
+
: ` parall app dev --dist dist > dev.log 2>&1 & # runs until stopped; look at it locally first`,
|
|
47
|
+
...(opts.actions
|
|
48
|
+
? [` parall app action run <app_…> <name> --local # one action, then returns`]
|
|
49
|
+
: []),
|
|
50
|
+
...(opts.actions
|
|
51
|
+
? ['', 'Ready-made pages (calendar, kanban, …): parall app add --list']
|
|
52
|
+
: []),
|
|
41
53
|
].join('\n'));
|
|
42
54
|
}
|
|
43
55
|
catch (err) {
|
|
@@ -45,135 +57,3 @@ export function registerAppScaffoldCommands(app) {
|
|
|
45
57
|
}
|
|
46
58
|
});
|
|
47
59
|
}
|
|
48
|
-
function scaffoldFiles(name) {
|
|
49
|
-
return [
|
|
50
|
-
[
|
|
51
|
-
'package.json',
|
|
52
|
-
`${JSON.stringify({
|
|
53
|
-
name,
|
|
54
|
-
private: true,
|
|
55
|
-
type: 'module',
|
|
56
|
-
scripts: { dev: 'vite', build: 'vite build' },
|
|
57
|
-
dependencies: { react: '^19.1.0', 'react-dom': '^19.1.0' },
|
|
58
|
-
devDependencies: {
|
|
59
|
-
'@types/react': '^19.1.2',
|
|
60
|
-
'@types/react-dom': '^19.1.2',
|
|
61
|
-
'@vitejs/plugin-react': '^4.4.1',
|
|
62
|
-
typescript: '^5.8.3',
|
|
63
|
-
vite: '^6.3.5',
|
|
64
|
-
},
|
|
65
|
-
}, null, 2)}\n`,
|
|
66
|
-
],
|
|
67
|
-
[
|
|
68
|
-
'vite.config.ts',
|
|
69
|
-
`import react from '@vitejs/plugin-react';
|
|
70
|
-
import { defineConfig } from 'vite';
|
|
71
|
-
|
|
72
|
-
// Everything must land inside the bundle: the app origin's CSP only allows
|
|
73
|
-
// 'self' for scripts, styles and fonts (no CDN imports, no external URLs).
|
|
74
|
-
export default defineConfig({
|
|
75
|
-
plugins: [react()],
|
|
76
|
-
base: './',
|
|
77
|
-
build: { outDir: 'dist' },
|
|
78
|
-
});
|
|
79
|
-
`,
|
|
80
|
-
],
|
|
81
|
-
[
|
|
82
|
-
'tsconfig.json',
|
|
83
|
-
`${JSON.stringify({
|
|
84
|
-
compilerOptions: {
|
|
85
|
-
target: 'ES2022',
|
|
86
|
-
module: 'ES2022',
|
|
87
|
-
moduleResolution: 'bundler',
|
|
88
|
-
jsx: 'react-jsx',
|
|
89
|
-
lib: ['ES2022', 'DOM'],
|
|
90
|
-
strict: true,
|
|
91
|
-
noEmit: true,
|
|
92
|
-
skipLibCheck: true,
|
|
93
|
-
},
|
|
94
|
-
include: ['src'],
|
|
95
|
-
}, null, 2)}\n`,
|
|
96
|
-
],
|
|
97
|
-
[
|
|
98
|
-
'index.html',
|
|
99
|
-
`<!doctype html>
|
|
100
|
-
<html lang="en">
|
|
101
|
-
<head>
|
|
102
|
-
<meta charset="UTF-8" />
|
|
103
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
104
|
-
<title>${name}</title>
|
|
105
|
-
</head>
|
|
106
|
-
<body>
|
|
107
|
-
<div id="root"></div>
|
|
108
|
-
<script type="module" src="./src/main.tsx"></script>
|
|
109
|
-
</body>
|
|
110
|
-
</html>
|
|
111
|
-
`,
|
|
112
|
-
],
|
|
113
|
-
[
|
|
114
|
-
'public/manifest.json',
|
|
115
|
-
`${JSON.stringify({ entry: 'index.html', sdk_version: '0.1.0', capabilities: [] }, null, 2)}\n`,
|
|
116
|
-
],
|
|
117
|
-
[
|
|
118
|
-
'src/main.tsx',
|
|
119
|
-
`import { StrictMode } from 'react';
|
|
120
|
-
import { createRoot } from 'react-dom/client';
|
|
121
|
-
import { App } from './App';
|
|
122
|
-
|
|
123
|
-
createRoot(document.getElementById('root') as HTMLElement).render(
|
|
124
|
-
<StrictMode>
|
|
125
|
-
<App />
|
|
126
|
-
</StrictMode>,
|
|
127
|
-
);
|
|
128
|
-
`,
|
|
129
|
-
],
|
|
130
|
-
[
|
|
131
|
-
'src/App.tsx',
|
|
132
|
-
`import { useEffect, useState } from 'react';
|
|
133
|
-
import { parall, type ReadyResult } from './parall';
|
|
134
|
-
|
|
135
|
-
export function App() {
|
|
136
|
-
const [host, setHost] = useState<ReadyResult | null>(null);
|
|
137
|
-
const [error, setError] = useState<string | null>(null);
|
|
138
|
-
useEffect(() => {
|
|
139
|
-
parall
|
|
140
|
-
.ready()
|
|
141
|
-
.then(setHost)
|
|
142
|
-
.catch((err: Error) => setError(err.message));
|
|
143
|
-
}, []);
|
|
144
|
-
return (
|
|
145
|
-
<main style={{ fontFamily: 'system-ui', padding: 24 }}>
|
|
146
|
-
<h1>${name}</h1>
|
|
147
|
-
{host ? (
|
|
148
|
-
<p>
|
|
149
|
-
Hello, {host.viewer.display_name} — you are looking at version {host.app.version_seq} of{' '}
|
|
150
|
-
{host.app.name}.
|
|
151
|
-
</p>
|
|
152
|
-
) : error ? (
|
|
153
|
-
<p>Bridge error: {error}</p>
|
|
154
|
-
) : (
|
|
155
|
-
<p>Waiting for the host…</p>
|
|
156
|
-
)}
|
|
157
|
-
</main>
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
`,
|
|
161
|
-
],
|
|
162
|
-
['src/parall.ts', PAGE_VENDORED_HEADER + PAGE_SDK_SOURCE],
|
|
163
|
-
[
|
|
164
|
-
'AGENTS.md',
|
|
165
|
-
`# ${name} — Mini App 约定
|
|
166
|
-
|
|
167
|
-
- 这是一个 Parall Mini App:纯静态 bundle,所有脚本 / 样式 / 字体都必须打进 dist(app origin 的 CSP 只放 'self',任何外部 URL 引用会在 publish 验收时被拒)。
|
|
168
|
-
- \`public/manifest.json\` 随构建进入 dist 根部;entry 固定 index.html。
|
|
169
|
-
- 页面的数据只经 action:\`parall.action(name, params)\` 以看页面的人的身份调本 app 的服务端 action(\`parall app init --actions\` 生成 actions/),\`parall.onDataChanged(fn)\` 在 Database 有新写入时通知页面重新读。桥上没有 SQL、files、clip 方法。
|
|
170
|
-
- 流程:\`pnpm build\` → \`parall app publish dist --app <app_…> --source .\` → 在 Parall 里打开;先 \`parall app dev --dist dist\` 本地看一眼(不带 \`--app\` 时只托管页面、不跑 action)。
|
|
171
|
-
- \`src/parall.ts\` 是 @parall/miniapp-sdk 的 vendored 副本(npm 发布前);不要改。
|
|
172
|
-
`,
|
|
173
|
-
],
|
|
174
|
-
['.gitignore', 'node_modules\ndist\n'],
|
|
175
|
-
];
|
|
176
|
-
}
|
|
177
|
-
const PAGE_VENDORED_HEADER = `// Vendored copy of @parall/miniapp-sdk, written by \`parall app init\`. Do
|
|
178
|
-
// not edit; replace it with the npm package once that ships.
|
|
179
|
-
`;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface ScaffoldOptions {
|
|
2
|
+
/** The app's display name (the directory name). */
|
|
3
|
+
name: string;
|
|
4
|
+
/** Include actions, the schema and the example list. */
|
|
5
|
+
actions: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** The project's files, sorted by path. */
|
|
8
|
+
export declare function scaffoldProject(options: ScaffoldOptions): Array<[string, string]>;
|
|
9
|
+
/** An npm-valid package name from a directory name ("My App" → "my-app"). */
|
|
10
|
+
export declare function packageName(name: string): string;
|
|
11
|
+
/** Objects merge key by key; anything else (arrays included) is replaced. */
|
|
12
|
+
export declare function mergeJSON(base: unknown, over: unknown): unknown;
|
|
13
|
+
/** The same object with its keys in sorted order (package.json style). */
|
|
14
|
+
export declare function sortKeys<T>(record: Record<string, T>): Record<string, T>;
|
|
15
|
+
//# sourceMappingURL=apps-template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apps-template.d.ts","sourceRoot":"","sources":["../../src/commands/apps-template.ts"],"names":[],"mappings":"AA4BA,MAAM,WAAW,eAAe;IAC9B,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,2CAA2C;AAC3C,wBAAgB,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAsBjF;AAMD,6EAA6E;AAC7E,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOhD;AA2BD,6EAA6E;AAC7E,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAO/D;AAED,0EAA0E;AAC1E,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAIxE"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ACTIONS_SDK_SOURCE } from './apps-actions-sdk.generated.js';
|
|
2
|
+
import { PAGE_SDK_SOURCE } from './apps-page-sdk.generated.js';
|
|
3
|
+
import { TEMPLATE_BASE, TEMPLATE_WITH_ACTIONS } from './apps-templates.gen.js';
|
|
4
|
+
/** What `parall app init` writes (design §7.4): the base template — Vite +
|
|
5
|
+
* React + TypeScript + Tailwind + shadcn/ui, a responsive app shell, light
|
|
6
|
+
* and dark themes, loading / empty / error states and typed action hooks —
|
|
7
|
+
* and, with --actions, the server-side actions, the schema and an example
|
|
8
|
+
* list wired to them. The sources live in ts/cli/templates/mini-app and are
|
|
9
|
+
* embedded by scripts/generate-app-templates.mjs (the build checks the
|
|
10
|
+
* embedded copy is current); the two SDK halves are vendored from
|
|
11
|
+
* ts/miniapp-sdk until it is on npm. */
|
|
12
|
+
const PAGE_VENDORED_HEADER = `// Vendored copy of @parall/miniapp-sdk, written by \`parall app init\`. Do
|
|
13
|
+
// not edit; replace it with the npm package once that ships.
|
|
14
|
+
`;
|
|
15
|
+
const ACTIONS_VENDORED_HEADER = `// Vendored copy of @parall/miniapp-sdk/actions, written by
|
|
16
|
+
// \`parall app init --actions\`. Do not edit; replace it with the npm package
|
|
17
|
+
// once that ships.
|
|
18
|
+
`;
|
|
19
|
+
// Not __APP_NAME__: Markdown reads that as bold.
|
|
20
|
+
const NAME_PLACEHOLDER = /\{\{APP_NAME\}\}/g;
|
|
21
|
+
// Template files whose name a package would treat specially are stored
|
|
22
|
+
// under another name and renamed when written.
|
|
23
|
+
const RENAMES = { _gitignore: '.gitignore' };
|
|
24
|
+
/** The project's files, sorted by path. */
|
|
25
|
+
export function scaffoldProject(options) {
|
|
26
|
+
const files = new Map(Object.entries(TEMPLATE_BASE));
|
|
27
|
+
if (options.actions)
|
|
28
|
+
applyOverlay(files, TEMPLATE_WITH_ACTIONS);
|
|
29
|
+
files.set('src/parall.ts', PAGE_VENDORED_HEADER + PAGE_SDK_SOURCE);
|
|
30
|
+
if (options.actions) {
|
|
31
|
+
files.set('actions/parall-actions.ts', ACTIONS_VENDORED_HEADER + ACTIONS_SDK_SOURCE);
|
|
32
|
+
}
|
|
33
|
+
const pkg = JSON.parse(files.get('package.json') ?? '{}');
|
|
34
|
+
pkg.name = packageName(options.name);
|
|
35
|
+
for (const field of ['dependencies', 'devDependencies']) {
|
|
36
|
+
if (pkg[field])
|
|
37
|
+
pkg[field] = sortKeys(pkg[field]);
|
|
38
|
+
}
|
|
39
|
+
files.set('package.json', `${JSON.stringify(pkg, null, 2)}\n`);
|
|
40
|
+
const out = [];
|
|
41
|
+
for (const [path, content] of files) {
|
|
42
|
+
const target = RENAMES[path] ?? path;
|
|
43
|
+
const name = path.endsWith('.html') ? escapeHtml(options.name) : options.name;
|
|
44
|
+
// A function, so a `$&` in the name is not a replacement pattern.
|
|
45
|
+
out.push([target, content.replace(NAME_PLACEHOLDER, () => name)]);
|
|
46
|
+
}
|
|
47
|
+
return out.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
48
|
+
}
|
|
49
|
+
function escapeHtml(text) {
|
|
50
|
+
return text.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
51
|
+
}
|
|
52
|
+
/** An npm-valid package name from a directory name ("My App" → "my-app"). */
|
|
53
|
+
export function packageName(name) {
|
|
54
|
+
const cleaned = name
|
|
55
|
+
.toLowerCase()
|
|
56
|
+
.replace(/[^a-z0-9._-]+/g, '-')
|
|
57
|
+
.replace(/^[._-]+|[-]+$/g, '')
|
|
58
|
+
.slice(0, 214);
|
|
59
|
+
return cleaned || 'mini-app';
|
|
60
|
+
}
|
|
61
|
+
/** Applies the --actions overlay: _overlay.json's remove list drops base
|
|
62
|
+
* paths (a directory drops everything under it), JSON files present in both
|
|
63
|
+
* are deep-merged, AGENTS.md is appended, anything else is added or
|
|
64
|
+
* replaced. */
|
|
65
|
+
function applyOverlay(files, overlay) {
|
|
66
|
+
const meta = JSON.parse(overlay['_overlay.json'] ?? '{}');
|
|
67
|
+
for (const prefix of meta.remove ?? []) {
|
|
68
|
+
for (const path of [...files.keys()]) {
|
|
69
|
+
if (path === prefix || path.startsWith(`${prefix}/`))
|
|
70
|
+
files.delete(path);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for (const [path, content] of Object.entries(overlay)) {
|
|
74
|
+
if (path === '_overlay.json')
|
|
75
|
+
continue;
|
|
76
|
+
const current = files.get(path);
|
|
77
|
+
if (current !== undefined && path === 'AGENTS.md') {
|
|
78
|
+
files.set(path, `${current.trimEnd()}\n\n${content}`);
|
|
79
|
+
}
|
|
80
|
+
else if (current !== undefined && path.endsWith('.json')) {
|
|
81
|
+
const merged = mergeJSON(JSON.parse(current), JSON.parse(content));
|
|
82
|
+
files.set(path, `${JSON.stringify(merged, null, 2)}\n`);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
files.set(path, content);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** Objects merge key by key; anything else (arrays included) is replaced. */
|
|
90
|
+
export function mergeJSON(base, over) {
|
|
91
|
+
if (!isPlainObject(base) || !isPlainObject(over))
|
|
92
|
+
return over;
|
|
93
|
+
const out = { ...base };
|
|
94
|
+
for (const [key, value] of Object.entries(over)) {
|
|
95
|
+
out[key] = key in base ? mergeJSON(base[key], value) : value;
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
/** The same object with its keys in sorted order (package.json style). */
|
|
100
|
+
export function sortKeys(record) {
|
|
101
|
+
return Object.fromEntries(Object.entries(record).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
102
|
+
}
|
|
103
|
+
function isPlainObject(value) {
|
|
104
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
105
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RegistryItem } from './apps-blocks.js';
|
|
2
|
+
export declare const TEMPLATE_BASE: Readonly<Record<string, string>>;
|
|
3
|
+
export declare const TEMPLATE_WITH_ACTIONS: Readonly<Record<string, string>>;
|
|
4
|
+
export declare const TEMPLATE_BLOCKS: readonly RegistryItem[];
|
|
5
|
+
//# sourceMappingURL=apps-templates.gen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apps-templates.gen.d.ts","sourceRoot":"","sources":["../../src/commands/apps-templates.gen.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA0D1D,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAsBlE,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,SAAS,YAAY,EAyclD,CAAC"}
|