@parall/cli 1.79.0 → 1.80.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.
Files changed (38) hide show
  1. package/dist/commands/apps-access.d.ts.map +1 -1
  2. package/dist/commands/apps-access.js +19 -9
  3. package/dist/commands/apps-actions-sdk.generated.d.ts +1 -1
  4. package/dist/commands/apps-actions-sdk.generated.d.ts.map +1 -1
  5. package/dist/commands/apps-actions-sdk.generated.js +1 -1
  6. package/dist/commands/apps-actions.js +6 -1
  7. package/dist/commands/apps-add.js +1 -1
  8. package/dist/commands/apps-blocks.d.ts.map +1 -1
  9. package/dist/commands/apps-blocks.js +8 -0
  10. package/dist/commands/apps-placement.d.ts +13 -0
  11. package/dist/commands/apps-placement.d.ts.map +1 -0
  12. package/dist/commands/apps-placement.js +20 -0
  13. package/dist/commands/apps-scaffold.d.ts +7 -1
  14. package/dist/commands/apps-scaffold.d.ts.map +1 -1
  15. package/dist/commands/apps-scaffold.js +88 -30
  16. package/dist/commands/apps-template-catalog.d.ts +85 -0
  17. package/dist/commands/apps-template-catalog.d.ts.map +1 -0
  18. package/dist/commands/apps-template-catalog.gen.d.ts +3 -0
  19. package/dist/commands/apps-template-catalog.gen.d.ts.map +1 -0
  20. package/dist/commands/apps-template-catalog.gen.js +228 -0
  21. package/dist/commands/apps-template-catalog.js +49 -0
  22. package/dist/commands/apps-template-init.d.ts +39 -0
  23. package/dist/commands/apps-template-init.d.ts.map +1 -0
  24. package/dist/commands/apps-template-init.js +118 -0
  25. package/dist/commands/apps-template.d.ts +11 -0
  26. package/dist/commands/apps-template.d.ts.map +1 -1
  27. package/dist/commands/apps-template.js +18 -7
  28. package/dist/commands/apps-templates.gen.d.ts +1 -0
  29. package/dist/commands/apps-templates.gen.d.ts.map +1 -1
  30. package/dist/commands/apps-templates.gen.js +10 -1
  31. package/dist/commands/apps.d.ts.map +1 -1
  32. package/dist/commands/apps.js +6 -2
  33. package/dist/commands/db-plane.d.ts.map +1 -1
  34. package/dist/commands/db-plane.js +10 -6
  35. package/dist/commands/dbs.d.ts +3 -2
  36. package/dist/commands/dbs.d.ts.map +1 -1
  37. package/dist/commands/dbs.js +10 -5
  38. package/package.json +5 -5
@@ -1,59 +1,117 @@
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 { dialectOf } from './apps-placement.js';
4
5
  import { scaffoldProject } from './apps-template.js';
6
+ import { cliVersion, findAppTemplate, registerAppTemplatesCommand, unknownTemplateError, } from './apps-template-catalog.js';
7
+ import { resolveInitTarget, templateBlocks, templateNextSteps, templateProject, templateRefusal, writeTemplateProject, } from './apps-template-init.js';
5
8
  /** `parall app init`: the scaffold of design §7.4 — Vite + React + TS +
6
9
  * Tailwind + shadcn/ui with the host bridge wired (apps-template.ts);
7
10
  * `--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`
11
+ * that reads and writes through them. `--app` names the app the project is
12
+ * for: the scaffold's SQL is written in the dialect of that app's Database
13
+ * (MySQL on TiDB, PostgreSQL otherwise; mini-app-tidb-placement-design.md
14
+ * §6.7) and the next steps name the app. Without it the SQL is PostgreSQL,
15
+ * as before. `--template` starts from an app template instead of the
16
+ * example (apps-template-init.ts), listed by `parall app templates`
17
+ * (apps-template-catalog.ts). Blocks go on top with `parall app add`
9
18
  * (apps-add.ts). */
10
19
  export function registerAppScaffoldCommands(app) {
20
+ registerAppTemplatesCommand(app);
11
21
  app
12
22
  .command('init')
13
23
  .description('Scaffold a new Mini App project (Vite + React + TS + Tailwind + shadcn/ui, bridge wired)')
14
24
  .argument('<dir>', 'Directory to create (must be empty or absent)')
15
25
  .option('--actions', 'Also scaffold server-side actions, the schema and an example list wired to them (actions/ → dist/_actions/index.js)')
16
- .action(async (dir, opts) => {
26
+ .option('--template <id>', 'Start from an app template (parall app templates) instead of the example: its pages, actions and schema over the --actions scaffold, and its skill as SKILL.md. Needs --app; read the skill first (parall app templates show <id>)')
27
+ .option('--app <appId>', "The app the project is for (app_… or prll://app_…; create it first with parall app create): the SQL is written for its Database — MySQL when the Database's placement is tidb, PostgreSQL otherwise — the next steps name the app, and --template checks its Database")
28
+ .action(async (dir, opts, command) => {
17
29
  try {
18
30
  const out = resolve(dir);
19
- await fs.mkdir(out, { recursive: true });
20
- if ((await fs.readdir(out)).length > 0) {
31
+ const entries = await fs.readdir(out).catch((err) => {
32
+ if (err.code === 'ENOENT')
33
+ return [];
34
+ throw err;
35
+ });
36
+ if (entries.length > 0)
21
37
  throw new Error(`${out} is not empty`);
22
- }
23
38
  const name = out.split(sep).pop() ?? 'mini-app';
24
- const files = scaffoldProject({ name, actions: Boolean(opts.actions) });
39
+ if (opts.template !== undefined) {
40
+ await initFromTemplate({ dir, out, name, id: opts.template, app: opts.app, command });
41
+ return;
42
+ }
43
+ // Before anything is written: an app that cannot be read leaves no
44
+ // half-made project behind.
45
+ const forApp = opts.app === undefined ? undefined : await resolveInitTarget(opts.app);
46
+ await fs.mkdir(out, { recursive: true });
47
+ const actions = Boolean(opts.actions);
48
+ const files = scaffoldProject({ name, actions, dialect: dialectOf(forApp?.placement) });
25
49
  for (const [rel, content] of files) {
26
50
  const target = join(out, rel);
27
51
  await fs.mkdir(resolve(target, '..'), { recursive: true });
28
52
  await fs.writeFile(target, content);
29
53
  }
30
- console.error([
31
- `Scaffolded ${name} in ${out}`,
32
- '',
33
- 'Next steps:',
34
- ` cd ${dir} && pnpm install && pnpm build`,
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
- : []),
42
- ` parall app publish dist --app <app_…> --source .`,
43
- // `app dev` runs until stopped: an agent starts it in the background.
44
- opts.actions
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
- : []),
53
- ].join('\n'));
54
+ console.error(nextSteps({
55
+ name,
56
+ dir,
57
+ out,
58
+ actions,
59
+ target: forApp,
60
+ schemaFiles: files.map(([rel]) => rel).filter((rel) => rel.startsWith('db/')),
61
+ }));
54
62
  }
55
63
  catch (err) {
56
64
  printError(err);
57
65
  }
58
66
  });
59
67
  }
68
+ /** init --template: refused before anything is written when the id is
69
+ * unknown, --app is missing or the app's Database cannot take the template. */
70
+ async function initFromTemplate(p) {
71
+ const template = findAppTemplate(p.id);
72
+ if (!template)
73
+ throw unknownTemplateError(p.id, cliVersion(p.command));
74
+ if (p.app === undefined) {
75
+ throw new Error(`--template needs --app: create the app first (parall app create --name "<name>"), then parall app init ${p.dir} --template ${template.id} --app <app_…>`);
76
+ }
77
+ const target = await resolveInitTarget(p.app);
78
+ const refusal = templateRefusal(template, target);
79
+ if (refusal)
80
+ throw new Error(refusal);
81
+ await writeTemplateProject(p.out, templateProject(p.name, template), templateBlocks(template));
82
+ console.error(templateNextSteps({ ...p, template, target }));
83
+ }
84
+ function nextSteps(p) {
85
+ const app = p.target?.appId ?? '<app_…>';
86
+ const mysql = dialectOf(p.target?.placement) === 'mysql';
87
+ const header = p.target
88
+ ? `Scaffolded ${p.name} in ${p.out} for ${p.target.appId}: its Database ${p.target.databaseId} has placement ${p.target.placement}, so the SQL here is ${mysql ? 'MySQL (TiDB)' : 'PostgreSQL'}`
89
+ : `Scaffolded ${p.name} in ${p.out}`;
90
+ const tables = !p.actions
91
+ ? []
92
+ : mysql
93
+ ? p.schemaFiles.map((file, i) => ` parall app db exec --app ${app} --file ${file}${i === 0 ? ' # create the tables: one schema change per exec on TiDB, in order' : ''}`)
94
+ : [` parall app db exec --app ${app} --file db/schema.sql # create the tables`];
95
+ return [
96
+ header,
97
+ '',
98
+ 'Next steps:',
99
+ ` cd ${p.dir} && pnpm install && pnpm build`,
100
+ ...(p.target ? [] : [` parall app create --name "${p.name}"`]),
101
+ ...tables,
102
+ ...(p.actions ? [' parall app check dist # manifest ↔ actions/'] : []),
103
+ ` parall app publish dist --app ${app} --source .`,
104
+ // `app dev` runs until stopped: an agent starts it in the background.
105
+ p.actions
106
+ ? ` parall app dev --dist dist --app ${app} > dev.log 2>&1 & # runs until stopped; actions run on this machine`
107
+ : ` parall app dev --dist dist > dev.log 2>&1 & # runs until stopped; look at it locally first`,
108
+ ...(p.actions
109
+ ? [` parall app action run ${app} <name> --local # one action, then returns`]
110
+ : []),
111
+ // The blocks are written for PostgreSQL (apps-add.ts refuses a MySQL
112
+ // project).
113
+ ...(p.actions && !mysql
114
+ ? ['', 'Ready-made pages (calendar, kanban, …): parall app add --list']
115
+ : []),
116
+ ].join('\n');
117
+ }
@@ -0,0 +1,85 @@
1
+ import type { Command } from 'commander';
2
+ /**
3
+ * The app templates this CLI carries (docs/engineering-design/
4
+ * mini-app-templates-design.md §3–§5): ready-made apps a person picks and an
5
+ * agent builds with the organization's own data. Each is an introduction
6
+ * for people (template.json; the Web reads the same file), a skill for the
7
+ * agent and reference source laid over the `--actions` scaffold. The
8
+ * sources live in ts/cli/templates/mini-app/apps and are embedded by
9
+ * scripts/generate-app-template-catalog.mjs. `parall app templates` lists
10
+ * them, `templates show <id>` prints a skill, and `parall app init --template`
11
+ * (apps-template-init.ts) writes a project from one.
12
+ */
13
+ /** A text people read, in both languages the product speaks. */
14
+ export interface Bilingual {
15
+ en: string;
16
+ zh: string;
17
+ }
18
+ /** A template's introduction (template.json). */
19
+ export interface AppTemplateIntro {
20
+ id: string;
21
+ /** The first CLI release that carries the template. */
22
+ cli: string;
23
+ name: Bilingual;
24
+ /** The one line under the name. */
25
+ summary: Bilingual;
26
+ /** A shorter line for small cards. */
27
+ short: Bilingual;
28
+ /** What the agent looking after the app does day to day. */
29
+ agent: Bilingual;
30
+ /** The app's pages; id is the page's id in its links. */
31
+ pages: Array<{
32
+ id: string;
33
+ icon: string;
34
+ name: Bilingual;
35
+ description: Bilingual;
36
+ }>;
37
+ /** What the agent asks first. */
38
+ questions: Bilingual[];
39
+ /** The data it may read: channels, tasks, wiki, connections. */
40
+ data: Array<{
41
+ kind: string;
42
+ name: Bilingual;
43
+ text: Bilingual;
44
+ }>;
45
+ /** Under the data: what it agrees with the person first. */
46
+ data_note: Bilingual;
47
+ /** Who sees what goes into the app. */
48
+ visibility: Bilingual;
49
+ /** What the agent does once the app runs. */
50
+ routine: Bilingual[];
51
+ /** What wakes it: data_changed, daily. */
52
+ wake: Array<{
53
+ kind: string;
54
+ name: Bilingual;
55
+ text: Bilingual;
56
+ }>;
57
+ /** What the app cannot do. */
58
+ limits: Array<{
59
+ kind: string;
60
+ text: Bilingual;
61
+ }>;
62
+ }
63
+ export interface AppTemplate {
64
+ id: string;
65
+ intro: AppTemplateIntro;
66
+ /** skill.md: SKILL.md in the project. */
67
+ skill: string;
68
+ /** overlay/, path → content: laid over the --actions scaffold the way
69
+ * with-actions is laid over base (_overlay.json: `remove`, `blocks`). */
70
+ overlay: Readonly<Record<string, string>>;
71
+ }
72
+ export declare function findAppTemplate(id: string): AppTemplate | undefined;
73
+ /** What `parall app templates` prints. */
74
+ export declare function listAppTemplates(): {
75
+ id: string;
76
+ name: Bilingual;
77
+ summary: Bilingual;
78
+ }[];
79
+ /** The version of the CLI that runs (the root command's). */
80
+ export declare function cliVersion(command: Command): string;
81
+ /** The error for an id this CLI does not carry: what it has, and that the
82
+ * template may be newer than this CLI. */
83
+ export declare function unknownTemplateError(id: string, version: string): Error;
84
+ export declare function registerAppTemplatesCommand(app: Command): void;
85
+ //# sourceMappingURL=apps-template-catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apps-template-catalog.d.ts","sourceRoot":"","sources":["../../src/commands/apps-template-catalog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK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KAAE,CAAC,CAAC;CAClD;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,gBAAgB,CAAC;IACxB,yCAAyC;IACzC,KAAK,EAAE,MAAM,CAAC;IACd;6EACyE;IACzE,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC3C;AAED,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAEnE;AAED,0CAA0C;AAC1C,wBAAgB,gBAAgB;;;;IAE/B;AAED,6DAA6D;AAC7D,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAInD;AAED;0CAC0C;AAC1C,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAUvE;AAED,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,OAAO,QA8BvD"}
@@ -0,0 +1,3 @@
1
+ import type { AppTemplate } from './apps-template-catalog.js';
2
+ export declare const APP_TEMPLATES: readonly AppTemplate[];
3
+ //# sourceMappingURL=apps-template-catalog.gen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apps-template-catalog.gen.d.ts","sourceRoot":"","sources":["../../src/commands/apps-template-catalog.gen.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAE9D,eAAO,MAAM,aAAa,EAAE,SAAS,WAAW,EAmO/C,CAAC"}