@codenotch/codenotch.cli 1.0.40 → 1.0.42

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 (104) hide show
  1. package/README.md +78 -28
  2. package/dist/commands/generate/app.js +6 -0
  3. package/dist/commands/generate/app.js.map +1 -1
  4. package/dist/commands/generate/appmanifest.js +5 -0
  5. package/dist/commands/generate/appmanifest.js.map +1 -1
  6. package/dist/commands/generate/dbcontext.js +6 -2
  7. package/dist/commands/generate/dbcontext.js.map +1 -1
  8. package/dist/commands/generate/i18n.js +5 -0
  9. package/dist/commands/generate/i18n.js.map +1 -1
  10. package/dist/commands/generate/index.js +8 -1
  11. package/dist/commands/generate/index.js.map +1 -1
  12. package/dist/commands/generate/manifest.js +4 -0
  13. package/dist/commands/generate/manifest.js.map +1 -1
  14. package/dist/commands/generate/openapi.js +5 -1
  15. package/dist/commands/generate/openapi.js.map +1 -1
  16. package/dist/commands/generate/pkg.js +4 -0
  17. package/dist/commands/generate/pkg.js.map +1 -1
  18. package/dist/commands/generate/process.js +6 -0
  19. package/dist/commands/generate/process.js.map +1 -1
  20. package/dist/commands/project/deploy.js +9 -2
  21. package/dist/commands/project/deploy.js.map +1 -1
  22. package/dist/commands/project/index.js +8 -1
  23. package/dist/commands/project/index.js.map +1 -1
  24. package/dist/commands/project/inspect.js +65 -1
  25. package/dist/commands/project/inspect.js.map +1 -1
  26. package/dist/commands/project/new.js +7 -1
  27. package/dist/commands/project/new.js.map +1 -1
  28. package/dist/commands/project/remove.js +6 -1
  29. package/dist/commands/project/remove.js.map +1 -1
  30. package/dist/commands/react/build.js +22 -1
  31. package/dist/commands/react/build.js.map +1 -1
  32. package/dist/commands/react/clean.js +7 -2
  33. package/dist/commands/react/clean.js.map +1 -1
  34. package/dist/commands/react/dev.js +6 -0
  35. package/dist/commands/react/dev.js.map +1 -1
  36. package/dist/commands/react/index.js +11 -1
  37. package/dist/commands/react/index.js.map +1 -1
  38. package/dist/commands/react/package.d.ts +2 -0
  39. package/dist/commands/react/package.js +47 -0
  40. package/dist/commands/react/package.js.map +1 -0
  41. package/dist/commands/react/serve.js +5 -0
  42. package/dist/commands/react/serve.js.map +1 -1
  43. package/dist/commands/runtime/clear.js +5 -0
  44. package/dist/commands/runtime/clear.js.map +1 -1
  45. package/dist/commands/runtime/index.js +8 -1
  46. package/dist/commands/runtime/index.js.map +1 -1
  47. package/dist/commands/system/docs.d.ts +2 -0
  48. package/dist/commands/system/docs.js +57 -0
  49. package/dist/commands/system/docs.js.map +1 -0
  50. package/dist/commands/system/index.js +2 -0
  51. package/dist/commands/system/index.js.map +1 -1
  52. package/dist/commands/system/read.js +2 -1
  53. package/dist/commands/system/read.js.map +1 -1
  54. package/dist/commands/validation/files/ScriptValidator.js +9 -8
  55. package/dist/commands/validation/files/ScriptValidator.js.map +1 -1
  56. package/dist/commands/validation/validate.js +4 -13
  57. package/dist/commands/validation/validate.js.map +1 -1
  58. package/dist/index.js +12 -2
  59. package/dist/index.js.map +1 -1
  60. package/dist/utils/BuildUtils.d.ts +53 -5
  61. package/dist/utils/BuildUtils.js +233 -21
  62. package/dist/utils/BuildUtils.js.map +1 -1
  63. package/dist/utils/ConsoleUtils.d.ts +0 -2
  64. package/dist/utils/ConsoleUtils.js +0 -8
  65. package/dist/utils/ConsoleUtils.js.map +1 -1
  66. package/dist/utils/DbSchemaUtils.d.ts +16 -10
  67. package/dist/utils/DbSchemaUtils.js +82 -30
  68. package/dist/utils/DbSchemaUtils.js.map +1 -1
  69. package/dist/utils/DocsUtils.d.ts +34 -0
  70. package/dist/utils/DocsUtils.js +76 -0
  71. package/dist/utils/DocsUtils.js.map +1 -0
  72. package/dist/utils/OsUtils.d.ts +6 -0
  73. package/dist/utils/OsUtils.js +26 -0
  74. package/dist/utils/OsUtils.js.map +1 -1
  75. package/dist/utils/PackageUtils.d.ts +101 -0
  76. package/dist/utils/PackageUtils.js +538 -0
  77. package/dist/utils/PackageUtils.js.map +1 -0
  78. package/dist/utils/ProcessBundlerUtils.d.ts +103 -0
  79. package/dist/utils/ProcessBundlerUtils.js +336 -0
  80. package/dist/utils/ProcessBundlerUtils.js.map +1 -0
  81. package/dist/utils/ProjectCompilationUtils.d.ts +14 -2
  82. package/dist/utils/ProjectCompilationUtils.js +75 -3
  83. package/dist/utils/ProjectCompilationUtils.js.map +1 -1
  84. package/dist/utils/ProjectGeneratorUtils.d.ts +2 -1
  85. package/dist/utils/ProjectGeneratorUtils.js +21 -14
  86. package/dist/utils/ProjectGeneratorUtils.js.map +1 -1
  87. package/dist/utils/ProjectTemplates.d.ts +2 -2
  88. package/dist/utils/ProjectTemplates.js +12 -6
  89. package/dist/utils/ProjectTemplates.js.map +1 -1
  90. package/dist/utils/ProjectUtils.d.ts +18 -1
  91. package/dist/utils/ProjectUtils.js +33 -28
  92. package/dist/utils/ProjectUtils.js.map +1 -1
  93. package/dist/utils/ServeUtils.js +1 -2
  94. package/dist/utils/ServeUtils.js.map +1 -1
  95. package/dist/utils/TemplateUtils.d.ts +29 -0
  96. package/dist/utils/TemplateUtils.js +96 -3
  97. package/dist/utils/TemplateUtils.js.map +1 -1
  98. package/package.json +78 -71
  99. package/resources/docs/apps.md +109 -0
  100. package/resources/docs/i18n.md +51 -0
  101. package/resources/docs/processes.md +87 -0
  102. package/resources/docs/project.md +101 -0
  103. package/resources/docs/queries.md +54 -0
  104. package/resources/docs/tables.md +97 -0
@@ -48,13 +48,42 @@ export default abstract class TemplateUtils {
48
48
  '@types/react'?: string | undefined;
49
49
  '@types/react-dom'?: string | undefined;
50
50
  '@vitejs/plugin-react'?: string | undefined;
51
+ '@codenotch/process': string;
51
52
  };
52
53
  };
53
54
  /**
54
55
  * Folders of a new project, relative to its root
55
56
  */
56
57
  static readonly PROJECT_FOLDERS: string[];
58
+ /**
59
+ * tsconfig.json of a Codenotch project.
60
+ *
61
+ * Its 'include' must cover the generated 'db-schema.d.ts': the declaration merging it carries
62
+ * only applies to files of the same TypeScript program, and without a tsconfig the editor
63
+ * builds an inferred program out of the open files alone, so a d.ts nobody imports would
64
+ * never be loaded and `ctx.tables` would stay untyped.
65
+ *
66
+ * '**' takes the whole workspace, so a folder the developer adds is typed like the rest. A
67
+ * wildcard never walks into 'node_modules' nor into a folder whose name starts with a dot
68
+ * ('.codenotch', '.git', '.vscode', ...), so only the rest has to be listed in 'exclude' -
69
+ * they are named there anyway, as the cli also reads it to know what not to package.
70
+ * 'compiled' holds the process bundles of 'cn project compile': generated .js that would
71
+ * otherwise join the program through allowJs.
72
+ */
73
+ static createTsConfigJson(): string;
57
74
  static createGitignore(): string;
75
+ /**
76
+ * AGENTS.md of a new project: the entry point of AI coding agents (Claude Code reads it
77
+ * through CLAUDE.md). Kept short on purpose: the reference documentation ships with the CLI
78
+ * and is read through 'cn docs <topic>', so it follows the installed CLI instead of being
79
+ * frozen at the version that created the project.
80
+ */
81
+ static createAgentsMd(projectName: string, serviceName: string): string;
82
+ /**
83
+ * CLAUDE.md of a new project: Claude Code reads this file, the '@' import pulls the shared
84
+ * AGENTS.md in so both stay one single source of truth
85
+ */
86
+ static createClaudeMd(): string;
58
87
  /**
59
88
  * readme.md of a new project: what the generated files are and how to work with them
60
89
  */
@@ -91,6 +91,7 @@ class TemplateUtils {
91
91
  ...extra.dependencies
92
92
  },
93
93
  devDependencies: {
94
+ '@codenotch/process': '0.1.4',
94
95
  ...(withReact ? {
95
96
  '@types/react': '^19.2.18',
96
97
  '@types/react-dom': '^19.2.4',
@@ -105,22 +106,112 @@ class TemplateUtils {
105
106
  * Folders of a new project, relative to its root
106
107
  */
107
108
  static PROJECT_FOLDERS = ['processes', 'apps', 'documents', 'tables'];
109
+ /**
110
+ * tsconfig.json of a Codenotch project.
111
+ *
112
+ * Its 'include' must cover the generated 'db-schema.d.ts': the declaration merging it carries
113
+ * only applies to files of the same TypeScript program, and without a tsconfig the editor
114
+ * builds an inferred program out of the open files alone, so a d.ts nobody imports would
115
+ * never be loaded and `ctx.tables` would stay untyped.
116
+ *
117
+ * '**' takes the whole workspace, so a folder the developer adds is typed like the rest. A
118
+ * wildcard never walks into 'node_modules' nor into a folder whose name starts with a dot
119
+ * ('.codenotch', '.git', '.vscode', ...), so only the rest has to be listed in 'exclude' -
120
+ * they are named there anyway, as the cli also reads it to know what not to package.
121
+ * 'compiled' holds the process bundles of 'cn project compile': generated .js that would
122
+ * otherwise join the program through allowJs.
123
+ */
124
+ static createTsConfigJson() {
125
+ return JSON.stringify({
126
+ compilerOptions: BuildUtils_1.default.defaultCompilerOptions(),
127
+ include: ['**/*'],
128
+ exclude: ['node_modules', '.codenotch', 'compiled']
129
+ }, null, 4) + '\n';
130
+ }
108
131
  static createGitignore() {
109
132
  return [
110
133
  'package-lock.json',
111
134
  '',
112
135
  '# Generated by the cli, regenerate them with the commands of the readme',
113
136
  // Anchored with a leading slash: these three only ever sit at the root of the project
114
- '/db-schema.ts',
137
+ '/db-schema.d.ts',
115
138
  '/db-schema.xml',
116
139
  '/openapi.json',
117
140
  // No slash: a translation file can sit anywhere, and its class is generated next to it
118
141
  '*.i18n.ts',
142
+ // Process bundles of 'cn project compile'
143
+ '/compiled',
119
144
  '',
120
145
  '/.codenotch',
121
146
  '/node_modules'
122
147
  ].join('\n') + '\n';
123
148
  }
149
+ /**
150
+ * AGENTS.md of a new project: the entry point of AI coding agents (Claude Code reads it
151
+ * through CLAUDE.md). Kept short on purpose: the reference documentation ships with the CLI
152
+ * and is read through 'cn docs <topic>', so it follows the installed CLI instead of being
153
+ * frozen at the version that created the project.
154
+ */
155
+ static createAgentsMd(projectName, serviceName) {
156
+ return `# Instructions for AI coding agents
157
+
158
+ This is **${projectName}**, a [Codenotch](https://codenotch.com/) project: TypeScript end to
159
+ end, built and deployed on a Codenotch runtime by the \`cn\` CLI (\`npm install -g @codenotch/codenotch.cli\`).
160
+ The website is not up to date — trust \`cn docs\` and the files of this project over it.
161
+ Its service name is \`${serviceName}\` (see \`manifest.json\`): it identifies the project on the
162
+ runtime and is part of its URL — never rename it on your own.
163
+
164
+ ## The reference documentation lives in the CLI
165
+
166
+ Run \`cn docs\` to list the topics, and **read the topic before writing a file of that kind** —
167
+ this file does not repeat the reference, and the docs follow the installed CLI version:
168
+
169
+ | Command | Read before touching |
170
+ | --- | --- |
171
+ | \`cn docs project\` | anything — anatomy, manifest, generated files, lifecycle |
172
+ | \`cn docs tables\` | \`tables/*.ts\`, \`documents/*.ts\` (\`defineEntity\`, \`defineDocument\`) |
173
+ | \`cn docs processes\` | \`processes/*.ts\` (\`process({...})\` declarations) |
174
+ | \`cn docs queries\` | \`queries/*.cnql\` |
175
+ | \`cn docs apps\` | \`apps/*.tsx\` and their manifests |
176
+ | \`cn docs i18n\` | \`*.i18n.csv\` |
177
+
178
+ ## Rules
179
+
180
+ 1. **Never edit generated files**: \`db-schema.xml\`, \`db-schema.d.ts\`, \`openapi.json\`,
181
+ \`*.i18n.ts\`, \`compiled/\`, \`.codenotch/\`. Fix the source they are generated from, then
182
+ regenerate.
183
+ 2. **Regenerate after changing sources** — tables or documents:
184
+ \`cn generate dbcontext -f .\`; processes exposing endpoints: \`cn generate openapi -f .\`;
185
+ translations: \`cn generate i18n -f <file>.i18n.csv\`.
186
+ 3. **Keep the TODO policy**: where the runtime API is not settled yet (the client-side call of a
187
+ process, the CNQL filter syntax), the sources carry an explicit \`TODO\` comment instead of a
188
+ guess. Never invent those APIs; carry the TODO and tell the user.
189
+ 4. **Check your work**: \`cn validate .\` reports hints, warnings and errors of every file, and
190
+ \`cn project compile\` typechecks and bundles the processes without deploying anything.
191
+ \`cn validate\`, \`cn project inspect\`, \`cn runtime info\` and \`cn docs\` take \`--json\`
192
+ for machine-readable output.
193
+
194
+ ## Everyday commands
195
+
196
+ | Command | What it does |
197
+ | --- | --- |
198
+ | \`cn project start\` | build, deploy and start the project on the local runtime |
199
+ | \`cn project refresh\` | after a change: sync the project with the running runtime |
200
+ | \`cn project inspect\` | parse the project and display everything the CLI discovered |
201
+ | \`cn project test\` | run the tests of the project |
202
+ | \`cn react dev [app]\` | Vite dev server with HMR for one app |
203
+ | \`cn runtime start\` / \`cn runtime info\` | start the local runtime / its status |
204
+
205
+ Run \`cn --help\` (or \`cn <command> --help\`) for the complete list.
206
+ `;
207
+ }
208
+ /**
209
+ * CLAUDE.md of a new project: Claude Code reads this file, the '@' import pulls the shared
210
+ * AGENTS.md in so both stay one single source of truth
211
+ */
212
+ static createClaudeMd() {
213
+ return `@AGENTS.md\n`;
214
+ }
124
215
  /**
125
216
  * readme.md of a new project: what the generated files are and how to work with them
126
217
  */
@@ -137,7 +228,7 @@ Renaming it later means updating every reference to it, so it is better chosen o
137
228
  ## Requirements
138
229
 
139
230
  ${fence}sh
140
- npm install -g codenotch-cli # the 'cn' command
231
+ npm install -g @codenotch/codenotch.cli # the 'cn' command
141
232
  cn runtime update # install (or update) the local Codenotch runtime
142
233
  ${fence}
143
234
 
@@ -153,7 +244,7 @@ The files the cli derives from the sources are not versioned (see \`.gitignore\`
153
244
  fresh clone they have to be written again before the project compiles:
154
245
 
155
246
  ${fence}sh
156
- cn generate dbcontext -f . # db-schema.xml + db-schema.ts, when the project has tables
247
+ cn generate dbcontext -f . # db-schema.xml + db-schema.d.ts, when the project has tables or documents
157
248
  cn generate openapi -f . # openapi.json, when processes expose endpoints
158
249
  cn generate i18n -f <file>.i18n.csv # the typed class of each translation file
159
250
  ${fence}
@@ -170,11 +261,13 @@ ${fence}
170
261
  | --- | --- |
171
262
  | \`manifest.json\` | project name, service name, version, languages and roles |
172
263
  | \`package.json\` | npm dependencies, React and \`@codenotch/codenotch.react\` |
264
+ | \`tsconfig.json\` | covers the sources and the generated \`db-schema.d.ts\`, which types \`ctx.tables\` |
173
265
  | \`processes/\` | server side processes, one TypeScript file each |
174
266
  | \`tables/\` | SQL table definitions |
175
267
  | \`documents/\` | NoSQL document schemas |
176
268
  | \`apps/\` | React apps: \`<App>.tsx\` and its \`<App>.manifest.json\` |
177
269
  | \`*.i18n.csv\` | translations, one column per language |
270
+ | \`AGENTS.md\` | instructions for AI coding agents (\`CLAUDE.md\` imports it) |
178
271
 
179
272
  ## Apps
180
273
 
@@ -1 +1 @@
1
- {"version":3,"file":"TemplateUtils.js","sourceRoot":"","sources":["../../src/utils/TemplateUtils.ts"],"names":[],"mappings":";;;;;;AACA,8DAAsC;AAEtC;;GAEG;AACU,QAAA,gBAAgB,GAAG,oBAAoB,CAAC;AAErD;;;;;;GAMG;AACH,MAA8B,aAAa;IAEvC,MAAM,CAAC,cAAc,CAAC,OAAe;QACjC,OAAO,wBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,OAAe;QAC/B,OAAO;YACH,4BAA4B;YAC5B,4DAA4D;YAC5D,EAAE;YACF,SAAS,OAAO,0BAA0B;YAC1C,8BAA8B;YAC9B,EAAE;YACF,gBAAgB;YAChB,mCAAmC;YACnC,kDAAkD;YAClD,UAAU;YACV,IAAI;YACJ,EAAE;YACF,kBAAkB,OAAO,GAAG;YAC5B,EAAE;SACL,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,iBAAiB,CAAC,OAAe;QACpC,OAAO;YACH,GAAG,EAAE;gBACD,IAAI,EAAE,OAAO;aAChB;YACD,IAAI,EAAE;gBACF,KAAK,EAAE,OAAO;aACjB;YACD,GAAG,EAAE;gBACD,IAAI,EAAE,OAAO;gBACb,OAAO,EAAE,YAAY;gBACrB,gBAAgB,EAAE;oBACd,yBAAyB;iBAC5B;gBACD,SAAS,EAAE,IAAI;gBACf,KAAK,EAAE;oBACH,EAAE,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE;oBAC3D,EAAE,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE;iBAC9D;aACJ;SACJ,CAAC;IACN,CAAC;IAED;;;;;OAKG;IACH,MAAM,CA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;;AA9TL,gCA+TC"}
package/package.json CHANGED
@@ -1,71 +1,78 @@
1
- {
2
- "name": "@codenotch/codenotch.cli",
3
- "version": "1.0.40",
4
- "description": "A CLI tool for code management",
5
- "main": "dist/index.js",
6
- "files": [
7
- "dist"
8
- ],
9
- "bin": {
10
- "codenotch-cli": "./dist/bin/cli.js",
11
- "cn": "./dist/bin/cli.js"
12
- },
13
- "scripts": {
14
- "build": "tsc",
15
- "dev": "tsx src/index.ts",
16
- "start": "node dist/index.js",
17
- "clean": "rimraf dist",
18
- "prebuild": "npm run clean",
19
- "prepare": "npm run build",
20
- "pack:check": "npm pack --dry-run",
21
- "release": "npm run build && npm run pack:check && npm publish",
22
- "test": "vitest run",
23
- "test:watch": "vitest",
24
- "test:coverage": "vitest run --coverage"
25
- },
26
- "keywords": [
27
- "cli",
28
- "tool",
29
- "code"
30
- ],
31
- "author": "Codenotch SA",
32
- "license": "MIT",
33
- "repository": {
34
- "type": "git",
35
- "url": "https://github.com/EchinoHub/codenotch-cli.git"
36
- },
37
- "publishConfig": {
38
- "access": "public"
39
- },
40
- "dependencies": {
41
- "@codenotch/codenotch.core": "1.0.25",
42
- "@octokit/auth-oauth-device": "^8.0.3",
43
- "@types/express": "^5.0.6",
44
- "adm-zip": "^0.5.17",
45
- "chalk": "^5.3.0",
46
- "commander": "^12.0.0",
47
- "cross-keychain": "^1.1.0",
48
- "decompress": "^4.2.1",
49
- "dotenv": "^17.4.2",
50
- "ignore": "^7.0.6",
51
- "express": "^5.2.1",
52
- "fs-extra": "^10.0.0",
53
- "js2xmlparser": "^5.0.0",
54
- "node-fetch": "^3.3.2",
55
- "papaparse": "^5.3.1",
56
- "typescript": "^5.9.3"
57
- },
58
- "devDependencies": {
59
- "@types/adm-zip": "^0.5.8",
60
- "@types/decompress": "^4.2.7",
61
- "@types/fs-extra": "^9.0.13",
62
- "@types/json-schema": "^7.0.6",
63
- "@types/node": "^20.19.34",
64
- "@types/papaparse": "^5.3.1",
65
- "@vitest/coverage-v8": "^4.1.10",
66
- "rimraf": "^5.0.0",
67
- "ts-node": "^10.9.2",
68
- "tsx": "^4.21.0",
69
- "vitest": "^4.1.10"
70
- }
71
- }
1
+ {
2
+ "name": "@codenotch/codenotch.cli",
3
+ "version": "1.0.42",
4
+ "description": "The Codenotch CLI ('cn'): scaffold, run, validate, package and deploy full-stack TypeScript Codenotch projects - processes, tables, documents and React apps - on a local Codenotch runtime",
5
+ "main": "dist/index.js",
6
+ "files": [
7
+ "dist",
8
+ "resources"
9
+ ],
10
+ "bin": {
11
+ "codenotch-cli": "./dist/bin/cli.js",
12
+ "cn": "./dist/bin/cli.js"
13
+ },
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "dev": "tsx src/index.ts",
17
+ "start": "node dist/index.js",
18
+ "clean": "rimraf dist",
19
+ "prebuild": "npm run clean",
20
+ "prepare": "npm run build",
21
+ "pack:check": "npm pack --dry-run",
22
+ "release": "npm run build && npm run pack:check && npm publish",
23
+ "test": "vitest run",
24
+ "test:watch": "vitest",
25
+ "test:coverage": "vitest run --coverage"
26
+ },
27
+ "keywords": [
28
+ "codenotch",
29
+ "cn",
30
+ "cli",
31
+ "fullstack",
32
+ "typescript",
33
+ "react",
34
+ "scaffold",
35
+ "runtime"
36
+ ],
37
+ "author": "Codenotch SA",
38
+ "license": "MIT",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/EchinoHub/codenotch-cli.git"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "dependencies": {
47
+ "@codenotch/codenotch.core": "1.0.25",
48
+ "@octokit/auth-oauth-device": "^8.0.3",
49
+ "@types/express": "^5.0.6",
50
+ "adm-zip": "^0.5.17",
51
+ "chalk": "^5.3.0",
52
+ "commander": "^12.0.0",
53
+ "cross-keychain": "^1.1.0",
54
+ "decompress": "^4.2.1",
55
+ "dotenv": "^17.4.2",
56
+ "esbuild": "0.28.2",
57
+ "express": "^5.2.1",
58
+ "fs-extra": "^10.0.0",
59
+ "ignore": "^7.0.6",
60
+ "js2xmlparser": "^5.0.0",
61
+ "node-fetch": "^3.3.2",
62
+ "papaparse": "^5.3.1",
63
+ "typescript": "^5.9.3"
64
+ },
65
+ "devDependencies": {
66
+ "@types/adm-zip": "^0.5.8",
67
+ "@types/decompress": "^4.2.7",
68
+ "@types/fs-extra": "^9.0.13",
69
+ "@types/json-schema": "^7.0.6",
70
+ "@types/node": "^20.19.34",
71
+ "@types/papaparse": "^5.3.1",
72
+ "@vitest/coverage-v8": "^4.1.10",
73
+ "rimraf": "^5.0.0",
74
+ "ts-node": "^10.9.2",
75
+ "tsx": "^4.21.0",
76
+ "vitest": "^4.1.10"
77
+ }
78
+ }
@@ -0,0 +1,109 @@
1
+ # React apps
2
+
3
+ How the React apps of a project are structured, the `useCodenotch()` runtime bridge, styling with Scss or Tailwind, and the `cn react` commands.
4
+
5
+ ## An app is a pair of files
6
+
7
+ An app is a `<Name>.tsx` and its sibling `<Name>.manifest.json`, both under `apps/`. The name
8
+ must be a valid JavaScript identifier — it is also the React component name and how the
9
+ `cn react` commands address the app. The `.tsx` default-exports the component:
10
+
11
+ ```tsx
12
+ import React from 'react';
13
+ import { useCodenotch } from '@codenotch/codenotch.react';
14
+
15
+ const index: React.FC<{}> = () => {
16
+ const cn = useCodenotch();
17
+ return <div>
18
+ <h1>My new Codenotch App</h1>
19
+ <pre>{JSON.stringify(cn.env, null, 4)}</pre>
20
+ </div>;
21
+ };
22
+
23
+ export default index;
24
+ ```
25
+
26
+ The manifest carries the display and PWA settings:
27
+
28
+ ```json
29
+ {
30
+ "app": { "name": "index" },
31
+ "html": { "title": "My Project" },
32
+ "pwa": {
33
+ "name": "index",
34
+ "display": "standalone",
35
+ "display_override": ["window-controls-overlay"],
36
+ "start_url": "./",
37
+ "icons": [
38
+ { "src": "logo512.png", "sizes": "512x512", "type": "image/png" },
39
+ { "src": "logo192.png", "sizes": "192x192", "type": "image/png" }
40
+ ]
41
+ }
42
+ }
43
+ ```
44
+
45
+ `cn generate app -n <Name>` scaffolds the pair.
46
+
47
+ ## Stack
48
+
49
+ - **React 19** — the only supported major.
50
+ - **react-router 7** for multi-page apps, with `HashRouter`: it keeps the routing client side
51
+ whatever URL the runtime serves the app from.
52
+ - **`@codenotch/codenotch.react`** — the bridge to the runtime, through `useCodenotch()`.
53
+
54
+ ## useCodenotch()
55
+
56
+ What the generated code relies on:
57
+
58
+ | Member | Meaning |
59
+ | --- | --- |
60
+ | `cn.env` | the environment the runtime gave the app |
61
+ | `cn.getTheme()` / `cn.setTheme('light' \| 'dark')` | theme; `setTheme` toggles the `dark` class on `<html>` |
62
+ | `cn.getLanguage()` / `cn.setLanguage(lang)` / `cn.getLanguages()` | languages, from `manifest.json` |
63
+ | `cn.startProcess(processId, input)` | call a server-side process — **not implemented yet** in `@codenotch/codenotch.react` 2.0.1 (it throws `Not implemented.`) |
64
+
65
+ For the full surface, read the typings in
66
+ `node_modules/@codenotch/codenotch.react/dist/`. Because `startProcess` is not settled, generated
67
+ projects wrap it in one typed `apps/api.ts` module carrying a `TODO` comment — keep that pattern
68
+ instead of scattering direct calls.
69
+
70
+ ## Styling
71
+
72
+ Every template styles through a `.scss` imported by the app entry (`import './index.scss'`).
73
+ The Tailwind flavour uses **Tailwind CSS 4**:
74
+
75
+ ```scss
76
+ // @use rather than @import: sass deprecates @import (gone in dart sass 3)
77
+ @use "tailwindcss";
78
+
79
+ /* setTheme('dark') toggles the 'dark' class on <html>: key the dark: variants on it */
80
+ @custom-variant dark (&:where(.dark, .dark *));
81
+ ```
82
+
83
+ plus a `postcss.config.js` with the `@tailwindcss/postcss` plugin, picked up by the Vite build.
84
+ No CSS modules.
85
+
86
+ ## Translations in the UI
87
+
88
+ Import the class generated from a `*.i18n.csv` and follow the runtime language (see
89
+ `cn docs i18n`):
90
+
91
+ ```tsx
92
+ import globals from '../../globals.i18n';
93
+
94
+ globals.setLanguage(cn.getLanguage() ?? 'en');
95
+ <h1>{globals.appTitle()}</h1>
96
+ ```
97
+
98
+ ## Commands
99
+
100
+ | Command | What it does |
101
+ | --- | --- |
102
+ | `cn react dev [app]` | Vite dev server with HMR on the real project sources |
103
+ | `cn react build [app]` | production bundle (options for a static or PWA build) |
104
+ | `cn react serve [target]` | serve a build locally |
105
+ | `cn react clean [app]` | delete the build staging of the app |
106
+ | `cn react package [app]` | desktop installer (Tauri) |
107
+
108
+ Apps are addressed by the `app.name` of their manifest; with a single app the name can be
109
+ omitted.
@@ -0,0 +1,51 @@
1
+ # Translations
2
+
3
+ The `*.i18n.csv` translation files, and the typed class `cn generate i18n` derives from each of them.
4
+
5
+ ## The csv
6
+
7
+ A `*.i18n.csv` holds one `key` column plus one column per language, matching the `languages` of
8
+ `manifest.json`:
9
+
10
+ ```csv
11
+ key,en,de,fr
12
+ appTitle,My todo lists,Meine Aufgabenlisten,Mes listes de tâches
13
+ todoCount,"{0} todo(s), {1} done","{0} Aufgabe(n), {1} erledigt","{0} tâche(s), {1} terminée(s)"
14
+ ```
15
+
16
+ - `{0}`, `{1}`, ... are the placeholders of the arguments.
17
+ - Standard CSV quoting: wrap a value containing a comma, a quote or a newline in double quotes.
18
+ - Rows without a key are ignored (a leading empty row after the header is tolerated).
19
+ - Best practice: one global file at the project root (e.g. `globals.i18n.csv`) rather than many
20
+ scattered ones.
21
+
22
+ Keys should be valid identifiers (they become method names): a key that is not is converted with
23
+ a warning, and the names `values`, `lang`, `setLanguage`, `getValue` are reserved.
24
+
25
+ ## The generated class
26
+
27
+ ```sh
28
+ cn generate i18n -f globals.i18n.csv
29
+ ```
30
+
31
+ writes `globals.i18n.ts` next to the csv — generated, gitignored, never edit it; regenerate after
32
+ every change to the csv. The class name comes from the file name, and it exposes one static
33
+ method per key:
34
+
35
+ ```tsx
36
+ import globals from './globals.i18n';
37
+
38
+ globals.setLanguage('de');
39
+ globals.appTitle(); // 'Meine Aufgabenlisten'
40
+ globals.todoCount('3', '1'); // '3 Aufgabe(n), 1 erledigt'
41
+ ```
42
+
43
+ Behavior of the generated methods:
44
+
45
+ - the argument count of a method is the highest `{n}` placeholder across all languages, plus one;
46
+ - a language without a value falls back to the first language column of the csv;
47
+ - an unknown key returns `KEY '<key>' NOT EXISTS` rather than throwing — a visible marker in the
48
+ UI instead of a crash.
49
+
50
+ In an app, follow the runtime language: `globals.setLanguage(cn.getLanguage() ?? 'en')` (see
51
+ `cn docs apps`).
@@ -0,0 +1,87 @@
1
+ # Processes
2
+
3
+ How to write the server-side processes of a project with `@codenotch/process`, what `ctx` offers, and the constraints coming from how they are bundled and executed.
4
+
5
+ ## Declaring a process
6
+
7
+ A process is a `process({...})` declaration, conventionally grouped by domain in files under
8
+ `processes/`:
9
+
10
+ ```ts
11
+ import { process, api, Context } from '@codenotch/process'
12
+ import type { ITodoList } from '../tables/todolist'
13
+
14
+ export const createTodoList = process({
15
+ id: 'CreateTodoList',
16
+ description: 'Creates an empty todo list',
17
+ auth: { scope: 'internal' },
18
+ trigger: api.post('/todolists'),
19
+ run: async (ctx: Context, input: { name: string }): Promise<{ id: string }> => {
20
+ const id = ctx.uuid()
21
+ await ctx.tables.todolists.write(id, { name: input.name })
22
+ return { id }
23
+ },
24
+ })
25
+ ```
26
+
27
+ | Property | Meaning |
28
+ | --- | --- |
29
+ | `id` | Unique across the project, a **string literal**. The registry key and the `ctx.call` target. |
30
+ | `description` | One line, shown in diagnostics and OpenAPI. |
31
+ | `auth.scope` | Who may start it: `'public'`, `'internal'`, `'system'`. |
32
+ | `trigger` | How it starts (below). Omitted: only reachable through `ctx.call` from another process. |
33
+ | `run` | `async (ctx, input) => output`. Always returns a Promise. |
34
+
35
+ Triggers:
36
+
37
+ | Trigger | Starts the process |
38
+ | --- | --- |
39
+ | `api.get('/route')` / `api.post` / `api.put` / `api.delete` | as an HTTP endpoint; `:param` segments land in `input` |
40
+ | `timer('0 7 * * *')` | on a cron schedule |
41
+ | `signal('some.ref')` | when that signal is raised |
42
+ | `install({ ... })` | at installation of the project |
43
+
44
+ Type the `input` parameter and the return type of `run`: the CLI turns those annotations into
45
+ JSON schemas used for payload validation and `openapi.json` (`cn generate openapi -f .`).
46
+
47
+ ## What `ctx` offers
48
+
49
+ The capabilities the generated code relies on:
50
+
51
+ | Member | Meaning |
52
+ | --- | --- |
53
+ | `ctx.tables.<collection>.write(id, patch)` | insert or update a row (only the fields present in the patch are written) |
54
+ | `ctx.tables.<collection>.require(id)` | one row, throws when the id is unknown — an `api` process turns that into a 404 |
55
+ | `ctx.tables.<collection>.delete(id)` | delete a row (relations with `linkBehaviour('Delete')` cascade) |
56
+ | `ctx.query<T>('queries/x.cnql', params)` | run a read query, see `cn docs queries` |
57
+ | `ctx.uuid()` | a new UUID |
58
+ | `ctx.call` | start another process by its `id` |
59
+ | `ctx.log.info(message, data)` | structured logging |
60
+
61
+ `ctx.tables` is typed by the generated `db-schema.d.ts` — regenerate it after changing a table
62
+ (`cn generate dbcontext -f .`), otherwise the collections stay untyped.
63
+
64
+ ## Rules — a process that breaks them is skipped with a warning, never guessed
65
+
66
+ - **Export the variable** (`export const createTodoList = ...`): a non-exported process is not
67
+ reachable.
68
+ - **Literal, unique `id`**: an id that is missing, computed at runtime, or already used by
69
+ another process gets the declaration skipped.
70
+
71
+ ## Bundling constraints
72
+
73
+ At packaging time each process becomes one self-contained `.js` artifact executed in a bare V8
74
+ engine — no Node, no module system. Consequences for the code you write:
75
+
76
+ - **No Node standard library** (`fs`, `node:crypto`, ...): importing one is a compile error, it
77
+ cannot exist in the runtime's engine.
78
+ - **npm dependencies are inlined** into each artifact: only pure-JS packages can work (no native
79
+ addons, no Node API inside).
80
+ - `@codenotch/*` packages are **provided by the runtime**, never inlined.
81
+ - **Module-level state is per process**: a top-level cache in a shared helper exists once per
82
+ artifact, it is never shared between processes.
83
+ - The whole project is **typechecked before bundling**: type errors fail the packaging.
84
+
85
+ `cn project compile` runs the same typecheck and bundling without packaging — the quick way to
86
+ check the processes build. `cn generate process` scaffolds boilerplate processes (CRUD, api) for
87
+ a discovered table (`-m api|insert|insert-full|update|upsert|delete|clean`).