@cbnventures/nova 0.25.2 → 0.26.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 (193) hide show
  1. package/build/package.json +10 -8
  2. package/build/src/cli/generate/github/workflows-blueprint-validate.js +1 -1
  3. package/build/src/cli/generate/github/workflows-blueprint-validate.js.map +1 -1
  4. package/build/src/cli/generate/github/workflows-blueprint.d.ts +6 -3
  5. package/build/src/cli/generate/github/workflows-blueprint.d.ts.map +1 -1
  6. package/build/src/cli/generate/github/workflows-blueprint.js +101 -22
  7. package/build/src/cli/generate/github/workflows-blueprint.js.map +1 -1
  8. package/build/src/cli/index.js +79 -28
  9. package/build/src/cli/index.js.map +1 -1
  10. package/build/src/cli/recipe/github/gh-commands.d.ts +3 -0
  11. package/build/src/cli/recipe/github/gh-commands.d.ts.map +1 -0
  12. package/build/src/cli/recipe/github/gh-commands.js +28 -0
  13. package/build/src/cli/recipe/github/gh-commands.js.map +1 -0
  14. package/build/src/cli/recipe/github/sync-actions.d.ts +5 -0
  15. package/build/src/cli/recipe/github/sync-actions.d.ts.map +1 -0
  16. package/build/src/cli/recipe/github/sync-actions.js +103 -0
  17. package/build/src/cli/recipe/github/sync-actions.js.map +1 -0
  18. package/build/src/cli/recipe/github/sync-features.d.ts.map +1 -1
  19. package/build/src/cli/recipe/github/sync-features.js +46 -11
  20. package/build/src/cli/recipe/github/sync-features.js.map +1 -1
  21. package/build/src/cli/recipe/github/sync-labels.d.ts +5 -0
  22. package/build/src/cli/recipe/github/sync-labels.d.ts.map +1 -0
  23. package/build/src/cli/recipe/github/sync-labels.js +40 -0
  24. package/build/src/cli/recipe/github/sync-labels.js.map +1 -0
  25. package/build/src/cli/recipe/github/sync-policies.d.ts.map +1 -1
  26. package/build/src/cli/recipe/github/sync-policies.js +89 -10
  27. package/build/src/cli/recipe/github/sync-policies.js.map +1 -1
  28. package/build/src/cli/recipe/github/sync-rulesets.d.ts +5 -0
  29. package/build/src/cli/recipe/github/sync-rulesets.d.ts.map +1 -0
  30. package/build/src/cli/recipe/github/sync-rulesets.js +137 -0
  31. package/build/src/cli/recipe/github/sync-rulesets.js.map +1 -0
  32. package/build/src/cli/recipe/github/sync-security.d.ts +5 -0
  33. package/build/src/cli/recipe/github/sync-security.d.ts.map +1 -0
  34. package/build/src/cli/recipe/github/sync-security.js +69 -0
  35. package/build/src/cli/recipe/github/sync-security.js.map +1 -0
  36. package/build/src/cli/recipe/index.d.ts.map +1 -1
  37. package/build/src/cli/recipe/index.js +20 -0
  38. package/build/src/cli/recipe/index.js.map +1 -1
  39. package/build/src/cli/recipe/package-json/sync-environment.d.ts.map +1 -1
  40. package/build/src/cli/recipe/package-json/sync-environment.js +16 -15
  41. package/build/src/cli/recipe/package-json/sync-environment.js.map +1 -1
  42. package/build/src/cli/scaffold/docs/docusaurus.d.ts +2 -1
  43. package/build/src/cli/scaffold/docs/docusaurus.d.ts.map +1 -1
  44. package/build/src/cli/scaffold/docs/docusaurus.js +41 -1
  45. package/build/src/cli/scaffold/docs/docusaurus.js.map +1 -1
  46. package/build/src/cli/scaffold/starter/base.d.ts.map +1 -1
  47. package/build/src/cli/scaffold/starter/base.js +57 -6
  48. package/build/src/cli/scaffold/starter/base.js.map +1 -1
  49. package/build/src/cli/utility/changelog.d.ts +1 -0
  50. package/build/src/cli/utility/changelog.d.ts.map +1 -1
  51. package/build/src/cli/utility/changelog.js +183 -67
  52. package/build/src/cli/utility/changelog.js.map +1 -1
  53. package/build/src/cli/utility/initialize.d.ts.map +1 -1
  54. package/build/src/cli/utility/initialize.js +133 -45
  55. package/build/src/cli/utility/initialize.js.map +1 -1
  56. package/build/src/cli/utility/run-scripts.d.ts +5 -5
  57. package/build/src/cli/utility/run-scripts.d.ts.map +1 -1
  58. package/build/src/cli/utility/run-scripts.js +28 -252
  59. package/build/src/cli/utility/run-scripts.js.map +1 -1
  60. package/build/src/cli/utility/transpile.d.ts.map +1 -1
  61. package/build/src/cli/utility/transpile.js +23 -5
  62. package/build/src/cli/utility/transpile.js.map +1 -1
  63. package/build/src/cli/utility/type-check.d.ts +2 -4
  64. package/build/src/cli/utility/type-check.d.ts.map +1 -1
  65. package/build/src/cli/utility/type-check.js +13 -54
  66. package/build/src/cli/utility/type-check.js.map +1 -1
  67. package/build/src/cli/utility/version.d.ts.map +1 -1
  68. package/build/src/cli/utility/version.js +0 -12
  69. package/build/src/cli/utility/version.js.map +1 -1
  70. package/build/src/lib/corepack.d.ts +5 -0
  71. package/build/src/lib/corepack.d.ts.map +1 -0
  72. package/build/src/lib/corepack.js +26 -0
  73. package/build/src/lib/corepack.js.map +1 -0
  74. package/build/src/lib/item.d.ts.map +1 -1
  75. package/build/src/lib/item.js +4 -1
  76. package/build/src/lib/item.js.map +1 -1
  77. package/build/src/lib/nova-config.d.ts +8 -0
  78. package/build/src/lib/nova-config.d.ts.map +1 -1
  79. package/build/src/lib/nova-config.js +329 -7
  80. package/build/src/lib/nova-config.js.map +1 -1
  81. package/build/src/lib/regex.d.ts +7 -0
  82. package/build/src/lib/regex.d.ts.map +1 -1
  83. package/build/src/lib/regex.js +8 -1
  84. package/build/src/lib/regex.js.map +1 -1
  85. package/build/src/lib/release-history.d.ts +5 -0
  86. package/build/src/lib/release-history.d.ts.map +1 -0
  87. package/build/src/lib/release-history.js +86 -0
  88. package/build/src/lib/release-history.js.map +1 -0
  89. package/build/src/lib/run-scripts.d.ts +10 -0
  90. package/build/src/lib/run-scripts.d.ts.map +1 -0
  91. package/build/src/lib/run-scripts.js +310 -0
  92. package/build/src/lib/run-scripts.js.map +1 -0
  93. package/build/src/lib/scaffold.d.ts +7 -2
  94. package/build/src/lib/scaffold.d.ts.map +1 -1
  95. package/build/src/lib/scaffold.js +398 -53
  96. package/build/src/lib/scaffold.js.map +1 -1
  97. package/build/src/lib/type-check.d.ts +3 -0
  98. package/build/src/lib/type-check.d.ts.map +1 -0
  99. package/build/src/lib/type-check.js +69 -0
  100. package/build/src/lib/type-check.js.map +1 -0
  101. package/build/src/presets/tsconfig/dx-strict.json +0 -1
  102. package/build/src/presets/tsconfig/fw-homebridge.json +11 -0
  103. package/build/src/rules/eslint/regex/no-regex-literals.d.ts +1 -0
  104. package/build/src/rules/eslint/regex/no-regex-literals.d.ts.map +1 -1
  105. package/build/src/rules/eslint/regex/no-regex-literals.js +20 -1
  106. package/build/src/rules/eslint/regex/no-regex-literals.js.map +1 -1
  107. package/build/src/rules/eslint/typescript/no-shared-type-import.d.ts +1 -0
  108. package/build/src/rules/eslint/typescript/no-shared-type-import.d.ts.map +1 -1
  109. package/build/src/rules/eslint/typescript/no-shared-type-import.js +19 -1
  110. package/build/src/rules/eslint/typescript/no-shared-type-import.js.map +1 -1
  111. package/build/src/toolkit/index.d.ts +1 -0
  112. package/build/src/toolkit/index.d.ts.map +1 -1
  113. package/build/src/toolkit/index.js +1 -0
  114. package/build/src/toolkit/index.js.map +1 -1
  115. package/build/src/toolkit/vitest-setup.d.ts +6 -0
  116. package/build/src/toolkit/vitest-setup.d.ts.map +1 -0
  117. package/build/src/toolkit/vitest-setup.js +21 -0
  118. package/build/src/toolkit/vitest-setup.js.map +1 -0
  119. package/build/src/types/cli/generate/github/workflows-blueprint-validate.d.ts +4 -4
  120. package/build/src/types/cli/generate/github/workflows-blueprint.d.ts +67 -3
  121. package/build/src/types/cli/recipe/github/gh-commands.d.ts +34 -0
  122. package/build/src/types/cli/recipe/github/sync-actions.d.ts +43 -0
  123. package/build/src/types/cli/recipe/github/sync-features.d.ts +16 -2
  124. package/build/src/types/cli/recipe/github/sync-labels.d.ts +36 -0
  125. package/build/src/types/cli/recipe/github/sync-policies.d.ts +14 -2
  126. package/build/src/types/cli/recipe/github/sync-rulesets.d.ts +71 -0
  127. package/build/src/types/cli/recipe/github/sync-security.d.ts +34 -0
  128. package/build/src/types/cli/recipe/package-json/sync-environment.d.ts +3 -0
  129. package/build/src/types/cli/scaffold/app/expressjs.d.ts +3 -0
  130. package/build/src/types/cli/scaffold/app/nextjs.d.ts +3 -0
  131. package/build/src/types/cli/scaffold/app/vite.d.ts +3 -0
  132. package/build/src/types/cli/scaffold/app/workers.d.ts +3 -0
  133. package/build/src/types/cli/scaffold/docs/docusaurus.d.ts +15 -0
  134. package/build/src/types/cli/scaffold/starter/base.d.ts +11 -0
  135. package/build/src/types/cli/utility/changelog.d.ts +87 -26
  136. package/build/src/types/cli/utility/initialize.d.ts +39 -29
  137. package/build/src/types/cli/utility/run-scripts.d.ts +22 -174
  138. package/build/src/types/cli/utility/transpile.d.ts +9 -1
  139. package/build/src/types/cli/utility/type-check.d.ts +9 -71
  140. package/build/src/types/cli/utility/version.d.ts +1 -7
  141. package/build/src/types/lib/corepack.d.ts +19 -0
  142. package/build/src/types/lib/nova-config.d.ts +256 -23
  143. package/build/src/types/lib/regex.d.ts +42 -0
  144. package/build/src/types/lib/release-history.d.ts +57 -0
  145. package/build/src/types/lib/run-scripts.d.ts +264 -0
  146. package/build/src/types/lib/scaffold.d.ts +187 -10
  147. package/build/src/types/lib/type-check.d.ts +102 -0
  148. package/build/src/types/rules/eslint/regex/no-regex-literals.d.ts +21 -0
  149. package/build/src/types/rules/eslint/typescript/no-shared-type-import.d.ts +21 -0
  150. package/build/src/types/shared.d.ts +264 -22
  151. package/build/src/types/tests/cli/generate/github/workflows-blueprint.test.d.ts +4 -0
  152. package/build/src/types/tests/cli/index.test.d.ts +258 -0
  153. package/build/src/types/tests/cli/recipe/package-json/normalize-tooling.test.d.ts +27 -0
  154. package/build/src/types/tests/cli/scaffold/app/expressjs.test.d.ts +4 -0
  155. package/build/src/types/tests/cli/scaffold/app/nextjs.test.d.ts +4 -0
  156. package/build/src/types/tests/cli/scaffold/app/vite.test.d.ts +48 -0
  157. package/build/src/types/tests/cli/scaffold/app/workers.test.d.ts +4 -0
  158. package/build/src/types/tests/cli/scaffold/docs/docusaurus.test.d.ts +10 -2
  159. package/build/src/types/tests/cli/utility/changelog.test.d.ts +99 -0
  160. package/build/src/types/tests/cli/utility/initialize.test.d.ts +43 -0
  161. package/build/src/types/tests/cli/utility/run-scripts.test.d.ts +29 -0
  162. package/build/src/types/tests/cli/utility/transpile.test.d.ts +28 -0
  163. package/build/src/types/tests/cli/utility/type-check.test.d.ts +33 -0
  164. package/build/src/types/tests/lib/nova-config.test.d.ts +19 -19
  165. package/build/src/types/tests/lib/regex.test.d.ts +7 -0
  166. package/build/src/types/tests/lib/release-history.test.d.ts +94 -0
  167. package/build/src/types/tests/lib/scaffold.test.d.ts +88 -0
  168. package/build/src/types/tests/rules/eslint/regex/no-regex-literals.test.d.ts +46 -0
  169. package/build/src/types/tests/rules/eslint/typescript/no-shared-type-import.test.d.ts +46 -0
  170. package/build/src/types/tests/scaffold-output-contract.test.d.ts +104 -0
  171. package/build/src/types/tests/scaffold-template-source.test.d.ts +42 -0
  172. package/build/src/types/tests/toolkit/vitest-setup.test.d.ts +36 -0
  173. package/build/src/types/tests/tsconfig-presets.test.d.ts +81 -0
  174. package/build/src/types/toolkit/vitest-setup.d.ts +24 -0
  175. package/build/templates/generators/github/workflows/publish/base.yml +1 -1
  176. package/build/templates/generators/github/workflows/publish/targets/cloudflare-workers.yml +1 -1
  177. package/build/templates/generators/must-haves/agent-conventions/PROJECT_RULES.md +11 -11
  178. package/build/templates/generators/must-haves/agent-conventions/conventions/documentation.md +4 -4
  179. package/build/templates/scaffold/app/express/package.json +2 -2
  180. package/build/templates/scaffold/app/express/tsconfig.json +1 -0
  181. package/build/templates/scaffold/app/nextjs/package.json +9 -10
  182. package/build/templates/scaffold/app/nextjs/tsconfig.json +3 -2
  183. package/build/templates/scaffold/app/vite/package.json +3 -3
  184. package/build/templates/scaffold/app/workers/package.json +4 -4
  185. package/build/templates/scaffold/app/workers/wrangler.toml +1 -1
  186. package/build/templates/scaffold/docs/docusaurus/docusaurus.config.ts +14 -12
  187. package/build/templates/scaffold/docs/docusaurus/package.json +13 -9
  188. package/build/templates/scaffold/docs/docusaurus/src/pages/index.mdx +8 -0
  189. package/build/templates/scaffold/docs/docusaurus/tsconfig.json +11 -5
  190. package/build/templates/scaffold/docs/docusaurus/{vitest.config.ts → vitest.config.mts} +11 -0
  191. package/build/templates/scaffold/docs/docusaurus/vitest.setup.ts +5 -14
  192. package/package.json +10 -8
  193. /package/build/templates/scaffold/docs/docusaurus/docs/{intro.md → intro.mdx} +0 -0
@@ -1,9 +1,126 @@
1
1
  import { promises as fs } from 'node:fs';
2
- import { join, relative, resolve } from 'node:path';
2
+ import { isAbsolute, join, relative, resolve, sep, } from 'node:path';
3
+ import { minimatch } from 'minimatch';
3
4
  import prompts from 'prompts';
5
+ import novaPackageJson from '../../package.json' with { type: 'json' };
4
6
  import { Logger } from '../toolkit/index.js';
5
- import { LIB_REGEX_PLACEHOLDER_PROJECT_SLUG } from './regex.js';
6
- import { discoverPathsWithFile, resolveTemplatePath, saveGeneratedFile } from './utility.js';
7
+ import { LIB_REGEX_PATTERN_SLUG_SIMPLE, LIB_REGEX_PLACEHOLDER_PROJECT_SLUG, LIB_REGEX_PLACEHOLDER_WORKSPACE_PACKAGE_NAME, } from './regex.js';
8
+ import { discoverPathsWithFile, isPlainObject, pathExists, resolveTemplatePath, saveGeneratedFile, } from './utility.js';
9
+ function reportError(message) {
10
+ Logger.customize({
11
+ name: 'CliScaffold.run',
12
+ purpose: 'validate',
13
+ }).error(message);
14
+ process.exitCode = 1;
15
+ return;
16
+ }
17
+ export function resolveWorkspacePackageName(projectSlug, workspaceName, category) {
18
+ return (category === 'docs') ? `${projectSlug}-docs` : `${projectSlug}-app-${workspaceName}`;
19
+ }
20
+ export function normalizeWorkspaceRelativePath(rootDirectory, workspaceDirectory) {
21
+ const relativePath = relative(rootDirectory, workspaceDirectory);
22
+ if (relativePath === ''
23
+ || relativePath === '..'
24
+ || relativePath.startsWith(`..${sep}`) === true
25
+ || isAbsolute(relativePath) === true) {
26
+ return undefined;
27
+ }
28
+ const normalizedPath = relativePath.split(sep).join('/');
29
+ return `./${normalizedPath}`;
30
+ }
31
+ export async function findFileConflicts(plannedPaths) {
32
+ const exists = await Promise.all(plannedPaths.map((plannedPath) => pathExists(plannedPath)));
33
+ return plannedPaths.filter((_plannedPath, index) => exists[index] === true);
34
+ }
35
+ export async function loadExistingRoot(rootDirectory) {
36
+ const packageJsonPath = join(rootDirectory, 'package.json');
37
+ const configFilePath = join(rootDirectory, 'nova.config.json');
38
+ let parsedPackageJson = undefined;
39
+ try {
40
+ const packageJsonRaw = await fs.readFile(packageJsonPath, 'utf-8');
41
+ parsedPackageJson = JSON.parse(packageJsonRaw);
42
+ }
43
+ catch (error) {
44
+ reportError('The root package.json is missing or contains invalid JSON. No scaffold files were written.');
45
+ Logger.customize({
46
+ name: 'loadExistingRoot',
47
+ purpose: 'packageJson',
48
+ }).debug(error);
49
+ return undefined;
50
+ }
51
+ if (isPlainObject(parsedPackageJson) === false) {
52
+ reportError('The root package.json must contain a JSON object. No scaffold files were written.');
53
+ return undefined;
54
+ }
55
+ const packageJson = parsedPackageJson;
56
+ const workspacesValue = packageJson['workspaces'];
57
+ let workspacePatterns = undefined;
58
+ if (Array.isArray(workspacesValue) === true
59
+ && workspacesValue.every((workspacePattern) => typeof workspacePattern === 'string' && workspacePattern.trim() !== '') === true) {
60
+ workspacePatterns = workspacesValue;
61
+ }
62
+ else if (isPlainObject(workspacesValue) === true) {
63
+ const workspacesObject = workspacesValue;
64
+ const workspacePatternsValue = workspacesObject['packages'];
65
+ if (Array.isArray(workspacePatternsValue) === true
66
+ && workspacePatternsValue.every((workspacePattern) => typeof workspacePattern === 'string' && workspacePattern.trim() !== '') === true) {
67
+ workspacePatterns = workspacePatternsValue;
68
+ }
69
+ }
70
+ if (workspacePatterns === undefined) {
71
+ reportError('The root package.json "workspaces" field must be a string array or an object with a string "packages" array. No scaffold files were written.');
72
+ return undefined;
73
+ }
74
+ let parsedConfig = undefined;
75
+ try {
76
+ const configRaw = await fs.readFile(configFilePath, 'utf-8');
77
+ parsedConfig = JSON.parse(configRaw);
78
+ }
79
+ catch (error) {
80
+ reportError('A readable nova.config.json is required at the monorepo root. Run "nova utility initialize" before adding a workspace. No scaffold files were written.');
81
+ Logger.customize({
82
+ name: 'loadExistingRoot',
83
+ purpose: 'novaConfig',
84
+ }).debug(error);
85
+ return undefined;
86
+ }
87
+ if (isPlainObject(parsedConfig) === false) {
88
+ reportError('The root nova.config.json must contain a JSON object. No scaffold files were written.');
89
+ return undefined;
90
+ }
91
+ const config = parsedConfig;
92
+ const projectValue = config['project'];
93
+ if (isPlainObject(projectValue) === false) {
94
+ reportError('The root nova.config.json must define project.name.slug before adding a workspace. No scaffold files were written.');
95
+ return undefined;
96
+ }
97
+ const project = projectValue;
98
+ const projectNameValue = project['name'];
99
+ if (isPlainObject(projectNameValue) === false) {
100
+ reportError('The root nova.config.json must define project.name.slug before adding a workspace. No scaffold files were written.');
101
+ return undefined;
102
+ }
103
+ const projectName = projectNameValue;
104
+ const projectSlugValue = projectName['slug'];
105
+ if (typeof projectSlugValue !== 'string' || LIB_REGEX_PATTERN_SLUG_SIMPLE.test(projectSlugValue) === false) {
106
+ reportError('The root nova.config.json project.name.slug must be a lowercase slug before adding a workspace. No scaffold files were written.');
107
+ return undefined;
108
+ }
109
+ const projectSlug = projectSlugValue;
110
+ const configWorkspacesValue = config['workspaces'];
111
+ if (configWorkspacesValue !== undefined && isPlainObject(configWorkspacesValue) === false) {
112
+ reportError('The root nova.config.json "workspaces" field must be an object. No scaffold files were written.');
113
+ return undefined;
114
+ }
115
+ const configWorkspaces = (configWorkspacesValue === undefined) ? {} : configWorkspacesValue;
116
+ return {
117
+ config,
118
+ packageJson,
119
+ projectSlug,
120
+ workspacePatterns,
121
+ workspaces: configWorkspaces,
122
+ };
123
+ }
7
124
  export async function detectMonorepoContext(currentWorkingDirectory) {
8
125
  const locations = await discoverPathsWithFile('package.json', 'backward');
9
126
  if (locations.length === 0) {
@@ -14,7 +131,24 @@ export async function detectMonorepoContext(currentWorkingDirectory) {
14
131
  && locations[0] !== currentWorkingDirectory)) {
15
132
  return { context: 'nested' };
16
133
  }
17
- const parsedPackageJson = JSON.parse(await fs.readFile(join(currentWorkingDirectory, 'package.json'), 'utf-8'));
134
+ const packageJsonPath = join(currentWorkingDirectory, 'package.json');
135
+ let parsedPackageJson = {};
136
+ try {
137
+ const packageJsonRaw = await fs.readFile(packageJsonPath, 'utf-8');
138
+ parsedPackageJson = JSON.parse(packageJsonRaw);
139
+ }
140
+ catch {
141
+ return {
142
+ context: 'invalid',
143
+ reason: 'The current package.json contains invalid JSON.',
144
+ };
145
+ }
146
+ if (isPlainObject(parsedPackageJson) === false) {
147
+ return {
148
+ context: 'invalid',
149
+ reason: 'The current package.json must contain a JSON object.',
150
+ };
151
+ }
18
152
  if (parsedPackageJson['workspaces'] !== undefined) {
19
153
  return {
20
154
  context: 'workspace',
@@ -47,9 +181,12 @@ export async function promptScaffoldOptions(context, defaults) {
47
181
  initial: defaults['typeName'],
48
182
  });
49
183
  }
50
- const monorepoPromptsAnswers = await prompts(monorepoQuestions, {
51
- onCancel: () => false,
52
- });
184
+ let monorepoPromptsAnswers = {};
185
+ if (monorepoQuestions.length > 0) {
186
+ monorepoPromptsAnswers = await prompts(monorepoQuestions, {
187
+ onCancel: () => false,
188
+ });
189
+ }
53
190
  if (monorepoNameValue === undefined && monorepoPromptsAnswers['name'] === undefined) {
54
191
  cancelled = true;
55
192
  }
@@ -134,7 +271,7 @@ export async function promptScaffoldOptions(context, defaults) {
134
271
  questions.push({
135
272
  type: 'text',
136
273
  name: 'name',
137
- message: 'Package name (slug):',
274
+ message: 'Project name (slug):',
138
275
  initial: defaults['typeName'],
139
276
  });
140
277
  }
@@ -158,9 +295,12 @@ export async function promptScaffoldOptions(context, defaults) {
158
295
  initial: resolveInitialOutput,
159
296
  });
160
297
  }
161
- const promptsAnswers = await prompts(questions, {
162
- onCancel: () => false,
163
- });
298
+ let promptsAnswers = {};
299
+ if (questions.length > 0) {
300
+ promptsAnswers = await prompts(questions, {
301
+ onCancel: () => false,
302
+ });
303
+ }
164
304
  if (nameValue === undefined && promptsAnswers['name'] === undefined) {
165
305
  cancelled = true;
166
306
  }
@@ -183,6 +323,52 @@ export async function promptScaffoldOptions(context, defaults) {
183
323
  outputDirectory: resolve(currentDirectory, resolvedOutput),
184
324
  };
185
325
  }
326
+ export async function resolveTemplateAnswers(options, questions, isNonInteractive) {
327
+ const replacements = new Map();
328
+ for (const question of questions) {
329
+ const providedValue = Reflect.get(options, question['name']);
330
+ let resolvedValue = undefined;
331
+ if (providedValue !== undefined) {
332
+ if (typeof providedValue !== 'string'
333
+ || question['choices'].some((choice) => choice['value'] === providedValue) !== true) {
334
+ const allowedValues = question['choices'].map((choice) => choice['value']).join(', ');
335
+ Logger.customize({
336
+ name: 'resolveTemplateAnswers',
337
+ purpose: 'validate',
338
+ }).error(`Invalid ${question['flag']} value "${String(providedValue)}". Expected one of: ${allowedValues}.`);
339
+ process.exitCode = 1;
340
+ return undefined;
341
+ }
342
+ resolvedValue = providedValue;
343
+ }
344
+ else if (isNonInteractive === true) {
345
+ Logger.customize({
346
+ name: 'resolveTemplateAnswers',
347
+ purpose: 'validate',
348
+ }).error(`Non-interactive scaffolding requires ${question['flag']}.`);
349
+ process.exitCode = 1;
350
+ return undefined;
351
+ }
352
+ else {
353
+ const answers = await prompts({
354
+ type: 'select',
355
+ name: question['name'],
356
+ message: question['message'],
357
+ choices: question['choices'],
358
+ initial: question['initial'],
359
+ }, {
360
+ onCancel: () => false,
361
+ });
362
+ const answer = answers[question['name']];
363
+ if (typeof answer !== 'string') {
364
+ return undefined;
365
+ }
366
+ resolvedValue = answer;
367
+ }
368
+ replacements.set(question['placeholder'], resolvedValue);
369
+ }
370
+ return replacements;
371
+ }
186
372
  export async function createWorkspaceDirectory(basePath, workspaceName) {
187
373
  const workspaceDirectory = join(basePath, workspaceName);
188
374
  await fs.mkdir(workspaceDirectory, { recursive: true });
@@ -241,15 +427,25 @@ export async function createMonorepoRoot(outputDirectory, projectSlug) {
241
427
  name: `${projectSlug}-project`,
242
428
  version: '0.0.0',
243
429
  private: true,
430
+ allowScripts: {
431
+ 'core-js': false,
432
+ 'core-js-pure': false,
433
+ 'es5-ext': false,
434
+ 'esbuild': false,
435
+ 'sharp': false,
436
+ 'unrs-resolver': false,
437
+ 'workerd': false,
438
+ },
244
439
  workspaces: [
245
440
  'apps/*',
246
441
  'packages/*',
247
442
  ],
248
- devDependencies: {
249
- '@cbnventures/nova': 'latest',
250
- },
443
+ packageManager: 'npm@11.18.0',
251
444
  engines: {
252
- node: '>=18.0.0',
445
+ node: '^22 || ^24',
446
+ },
447
+ devDependencies: {
448
+ '@cbnventures/nova': novaPackageJson['version'],
253
449
  },
254
450
  };
255
451
  const packageJsonPath = join(outputDirectory, 'package.json');
@@ -446,29 +642,33 @@ export async function registerWorkspaceInConfig(configFilePath, workspaceRelPath
446
642
  const raw = await fs.readFile(configFilePath, 'utf-8');
447
643
  parsedConfig = JSON.parse(raw);
448
644
  }
449
- catch {
645
+ catch (error) {
646
+ reportError('Unable to read nova.config.json while registering the scaffolded workspace.');
450
647
  Logger.customize({
451
648
  name: 'registerWorkspaceInConfig',
452
- purpose: 'skip',
453
- }).warn('No nova.config.json found. Skipping workspace registration.');
649
+ purpose: 'config',
650
+ }).debug(error);
454
651
  return;
455
652
  }
456
- if (parsedConfig === undefined) {
653
+ if (isPlainObject(parsedConfig) === false) {
654
+ reportError('The root nova.config.json must contain a JSON object.');
457
655
  return;
458
656
  }
459
657
  const project = parsedConfig['project'];
460
658
  const projectName = (project !== undefined) ? project['name'] : undefined;
461
659
  const projectSlug = (projectName !== undefined) ? projectName['slug'] : undefined;
462
- if (projectSlug === undefined) {
463
- Logger.customize({
464
- name: 'registerWorkspaceInConfig',
465
- purpose: 'skip',
466
- }).warn('No project slug found in nova.config.json. Skipping workspace registration.');
660
+ if (typeof projectSlug !== 'string' || LIB_REGEX_PATTERN_SLUG_SIMPLE.test(projectSlug) === false) {
661
+ reportError('The root nova.config.json must define a valid project.name.slug before registering a workspace.');
467
662
  return;
468
663
  }
469
664
  const role = (category === 'docs') ? 'docs' : 'app';
470
- const configName = (role === 'docs') ? `${projectSlug}-docs` : `${projectSlug}-app-${workspaceName}`;
471
- const workspaces = parsedConfig['workspaces'] ?? {};
665
+ const configName = resolveWorkspacePackageName(projectSlug, workspaceName, category);
666
+ const parsedWorkspaces = parsedConfig['workspaces'];
667
+ if (parsedWorkspaces !== undefined && isPlainObject(parsedWorkspaces) === false) {
668
+ reportError('The root nova.config.json "workspaces" field must be an object.');
669
+ return;
670
+ }
671
+ const workspaces = parsedWorkspaces ?? {};
472
672
  Reflect.set(workspaces, workspaceRelPath, {
473
673
  name: configName,
474
674
  role,
@@ -482,9 +682,10 @@ export async function registerWorkspaceInConfig(configFilePath, workspaceRelPath
482
682
  }).info(`Registered workspace "${configName}" in nova.config.json.`);
483
683
  return;
484
684
  }
485
- export async function runScaffold(options, category, typeName, templateSubpath, importMetaUrl) {
685
+ export async function runScaffold(options, category, typeName, templateSubpath, importMetaUrl, templateQuestions = []) {
486
686
  const currentDirectory = process.cwd();
487
687
  const isDryRun = options['dryRun'] === true;
688
+ const isNonInteractive = options['nonInteractive'] === true;
488
689
  if (isDryRun === true) {
489
690
  Logger.customize({
490
691
  name: 'CliScaffold.run',
@@ -492,28 +693,51 @@ export async function runScaffold(options, category, typeName, templateSubpath,
492
693
  }).warn('Dry run enabled. File changes will not be made in this session.');
493
694
  }
494
695
  const context = await detectMonorepoContext(currentDirectory);
696
+ if (context['context'] === 'invalid') {
697
+ reportError(`${context['reason']} No scaffold files were written.`);
698
+ return;
699
+ }
495
700
  if (context['context'] === 'nested') {
496
- Logger.customize({
497
- name: 'CliScaffold.run',
498
- purpose: 'context',
499
- }).error('Re-run this command from the monorepo root directory.');
500
- process.exitCode = 1;
701
+ reportError('Re-run this command from the monorepo root directory. No scaffold files were written.');
501
702
  return;
502
703
  }
503
704
  if (context['context'] === 'standalone') {
504
- Logger.customize({
505
- name: 'CliScaffold.run',
506
- purpose: 'context',
507
- }).error('Found a standalone project. Run from an empty directory to create a new monorepo, or add a "workspaces" field to use workspace mode.');
508
- process.exitCode = 1;
705
+ reportError('Found a standalone project. Run from an empty directory to create a new monorepo, or add a valid "workspaces" field to use workspace mode. No scaffold files were written.');
509
706
  return;
510
707
  }
511
708
  Logger.customize({
512
709
  name: 'CliScaffold.run',
513
710
  purpose: 'context',
514
711
  }).info(`Detected mode: ${context['context']}.`);
712
+ let existingRoot = undefined;
713
+ if (context['context'] === 'workspace') {
714
+ existingRoot = await loadExistingRoot(context['root']);
715
+ if (existingRoot === undefined) {
716
+ return;
717
+ }
718
+ if (options['name'] !== undefined && options['name'] !== existingRoot['projectSlug']) {
719
+ reportError(`This monorepo's project slug is "${existingRoot['projectSlug']}", not "${options['name']}". Omit --name when adding a workspace. No scaffold files were written.`);
720
+ return;
721
+ }
722
+ }
723
+ if (isNonInteractive === true
724
+ && (options['output'] === undefined
725
+ || options['workspaceName'] === undefined)) {
726
+ reportError('Non-interactive scaffolding requires --workspace-name and --output. No scaffold files were written.');
727
+ return;
728
+ }
729
+ if (isNonInteractive === true
730
+ && context['context'] === 'monorepo'
731
+ && options['name'] === undefined) {
732
+ reportError('Creating a new monorepo non-interactively also requires --name. No scaffold files were written.');
733
+ return;
734
+ }
735
+ let configNameDefault = options['name'];
736
+ if (context['context'] === 'workspace' && existingRoot !== undefined) {
737
+ configNameDefault = existingRoot['projectSlug'];
738
+ }
515
739
  const config = await promptScaffoldOptions(context, {
516
- name: options['name'],
740
+ name: configNameDefault,
517
741
  output: options['output'],
518
742
  typeName,
519
743
  workspaceName: options['workspaceName'],
@@ -525,37 +749,158 @@ export async function runScaffold(options, category, typeName, templateSubpath,
525
749
  }).warn('Scaffold cancelled.');
526
750
  return;
527
751
  }
752
+ if (LIB_REGEX_PATTERN_SLUG_SIMPLE.test(config['name']) === false) {
753
+ reportError('The project name must be a lowercase slug containing only letters, numbers, hyphens, or underscores. No scaffold files were written.');
754
+ return;
755
+ }
756
+ if (LIB_REGEX_PATTERN_SLUG_SIMPLE.test(config['workspaceName']) === false) {
757
+ reportError('The workspace name must be a lowercase slug containing only letters, numbers, hyphens, or underscores. No scaffold files were written.');
758
+ return;
759
+ }
760
+ const projectSlug = config['name'];
761
+ const workspacePackageName = resolveWorkspacePackageName(projectSlug, config['workspaceName'], category);
762
+ const configRoot = (config['mode'] === 'monorepo') ? config['outputDirectory'] : currentDirectory;
763
+ const configFilePath = join(configRoot, 'nova.config.json');
764
+ const workspaceDirectory = (config['mode'] === 'monorepo') ? join(configRoot, 'apps', config['workspaceName']) : config['outputDirectory'];
765
+ const workspaceRelPath = normalizeWorkspaceRelativePath(configRoot, workspaceDirectory);
766
+ if (workspaceRelPath === undefined) {
767
+ reportError('The workspace output must be a child directory of the monorepo root. No scaffold files were written.');
768
+ return;
769
+ }
770
+ const normalizedWorkspaceRelPath = workspaceRelPath.slice(2);
771
+ if (existingRoot !== undefined) {
772
+ const existingWorkspaceEntries = Object.entries(existingRoot['workspaces']);
773
+ for (const existingWorkspaceEntry of existingWorkspaceEntries) {
774
+ const existingWorkspacePath = existingWorkspaceEntry[0];
775
+ const existingWorkspaceValue = existingWorkspaceEntry[1];
776
+ const existingWorkspaceNormalizedPath = resolve(configRoot, existingWorkspacePath);
777
+ if (existingWorkspaceNormalizedPath === workspaceDirectory) {
778
+ reportError(`The workspace path "${workspaceRelPath}" is already registered in nova.config.json. No scaffold files were written.`);
779
+ return;
780
+ }
781
+ if (existingWorkspaceNormalizedPath !== configRoot
782
+ && (workspaceDirectory.startsWith(`${existingWorkspaceNormalizedPath}${sep}`) === true
783
+ || existingWorkspaceNormalizedPath.startsWith(`${workspaceDirectory}${sep}`) === true)) {
784
+ reportError(`The workspace path "${workspaceRelPath}" overlaps the registered workspace "${existingWorkspacePath}". Workspaces cannot be nested inside one another. No scaffold files were written.`);
785
+ return;
786
+ }
787
+ if (isPlainObject(existingWorkspaceValue) === false) {
788
+ reportError(`The nova.config.json workspace "${existingWorkspacePath}" must be an object. No scaffold files were written.`);
789
+ return;
790
+ }
791
+ const existingWorkspace = existingWorkspaceValue;
792
+ const existingWorkspaceName = existingWorkspace['name'];
793
+ const existingWorkspaceRole = existingWorkspace['role'];
794
+ if (typeof existingWorkspaceName !== 'string' || typeof existingWorkspaceRole !== 'string') {
795
+ reportError(`The nova.config.json workspace "${existingWorkspacePath}" must define string name and role fields. No scaffold files were written.`);
796
+ return;
797
+ }
798
+ if (category === 'docs' && existingWorkspaceRole === 'docs') {
799
+ reportError(`A documentation workspace is already registered at "${existingWorkspacePath}". Nova projects support one canonical docs workspace. No scaffold files were written.`);
800
+ return;
801
+ }
802
+ if (existingWorkspaceName === workspacePackageName) {
803
+ reportError(`The workspace package name "${workspacePackageName}" is already registered in nova.config.json. No scaffold files were written.`);
804
+ return;
805
+ }
806
+ }
807
+ }
808
+ const templateDirectory = resolveTemplatePath(importMetaUrl, templateSubpath);
809
+ const templateEntries = await collectFiles(templateDirectory, '');
810
+ const plannedPaths = templateEntries.map((templateEntry) => join(workspaceDirectory, templateEntry));
811
+ if (config['mode'] === 'monorepo') {
812
+ plannedPaths.push(join(configRoot, 'package.json'), configFilePath);
813
+ }
814
+ const conflictingPaths = await findFileConflicts(plannedPaths);
815
+ if (conflictingPaths.length > 0) {
816
+ const conflictMessage = conflictingPaths.map((conflictingPath) => relative(configRoot, conflictingPath)).join(', ');
817
+ reportError(`Scaffolding would overwrite files Nova does not own: ${conflictMessage}. Move or remove those files, then run the command again. No scaffold files were written.`);
818
+ return;
819
+ }
820
+ let isWorkspaceCovered = existingRoot === undefined;
821
+ if (existingRoot !== undefined) {
822
+ for (const workspacePattern of existingRoot['workspacePatterns']) {
823
+ const normalizedWorkspacePattern = (workspacePattern.startsWith('./') === true) ? workspacePattern.slice(2) : workspacePattern;
824
+ if (minimatch(normalizedWorkspaceRelPath, normalizedWorkspacePattern, { dot: true }) === true) {
825
+ isWorkspaceCovered = true;
826
+ break;
827
+ }
828
+ }
829
+ }
830
+ const templateReplacements = await resolveTemplateAnswers(options, templateQuestions, isNonInteractive);
831
+ if (templateReplacements === undefined) {
832
+ if (process.exitCode !== 1) {
833
+ Logger.customize({
834
+ name: 'CliScaffold.run',
835
+ purpose: 'cancelled',
836
+ }).warn('Scaffold cancelled.');
837
+ }
838
+ return;
839
+ }
528
840
  Logger.customize({
529
841
  name: 'CliScaffold.run',
530
842
  purpose: 'config',
531
- }).info(`Scaffolding ${category} ${typeName} "${config['name']}" in "${config['outputDirectory']}".`);
843
+ }).info(`Scaffolding ${category} ${typeName} workspace "${workspacePackageName}" in "${workspaceDirectory}".`);
532
844
  if (isDryRun === true) {
533
- const modePrefix = (config['mode'] === 'monorepo') ? 'monorepo root + ' : '';
845
+ if (config['mode'] === 'monorepo') {
846
+ Logger.customize({
847
+ name: 'CliScaffold.run',
848
+ purpose: 'dryRunRoot',
849
+ }).info(`Would create monorepo root at "${configRoot}".`);
850
+ }
534
851
  Logger.customize({
535
852
  name: 'CliScaffold.run',
536
- purpose: 'dryRun',
537
- }).info(`Would create ${modePrefix}workspace at "${config['outputDirectory']}".`);
853
+ purpose: 'dryRunWorkspace',
854
+ }).info(`Would create workspace at "${workspaceDirectory}" and register "${workspaceRelPath}".`);
855
+ if (existingRoot !== undefined && isWorkspaceCovered === false) {
856
+ Logger.customize({
857
+ name: 'CliScaffold.run',
858
+ purpose: 'dryRunWorkspaces',
859
+ }).info(`Would add "${normalizedWorkspaceRelPath}" to the root package.json workspaces.`);
860
+ }
538
861
  return;
539
862
  }
540
863
  if (config['mode'] === 'monorepo') {
541
- await createMonorepoRoot(config['outputDirectory'], config['name']);
864
+ await createMonorepoRoot(configRoot, projectSlug);
542
865
  }
543
- const workspaceDirectory = (config['mode'] === 'monorepo') ? join(config['outputDirectory'], 'apps', config['workspaceName']) : config['outputDirectory'];
544
866
  await fs.mkdir(workspaceDirectory, { recursive: true });
545
- const templateDirectory = resolveTemplatePath(importMetaUrl, templateSubpath);
546
- await writeTemplateFiles(templateDirectory, workspaceDirectory, new Map([[
867
+ const replacements = new Map([
868
+ [
547
869
  LIB_REGEX_PLACEHOLDER_PROJECT_SLUG,
548
- config['name'],
549
- ]]));
550
- const configRoot = (config['mode'] === 'monorepo') ? config['outputDirectory'] : currentDirectory;
551
- const configFilePath = join(configRoot, 'nova.config.json');
552
- await registerWorkspaceInConfig(configFilePath, `./${relative(configRoot, workspaceDirectory)}`, config['workspaceName'], category);
870
+ projectSlug,
871
+ ],
872
+ [
873
+ LIB_REGEX_PLACEHOLDER_WORKSPACE_PACKAGE_NAME,
874
+ workspacePackageName,
875
+ ],
876
+ ...templateReplacements,
877
+ ]);
878
+ await writeTemplateFiles(templateDirectory, workspaceDirectory, replacements);
879
+ if (existingRoot !== undefined && isWorkspaceCovered === false) {
880
+ existingRoot['workspacePatterns'].push(normalizedWorkspaceRelPath);
881
+ const rootPackageJsonPath = join(configRoot, 'package.json');
882
+ const rootWorkspacesValue = existingRoot['packageJson']['workspaces'];
883
+ if (isPlainObject(rootWorkspacesValue) === true) {
884
+ const rootWorkspacesObject = rootWorkspacesValue;
885
+ Reflect.set(rootWorkspacesObject, 'packages', existingRoot['workspacePatterns']);
886
+ }
887
+ else {
888
+ Reflect.set(existingRoot['packageJson'], 'workspaces', existingRoot['workspacePatterns']);
889
+ }
890
+ const rootPackageJsonContents = `${JSON.stringify(existingRoot['packageJson'], null, 2)}\n`;
891
+ await fs.writeFile(rootPackageJsonPath, rootPackageJsonContents, 'utf-8');
892
+ Logger.customize({
893
+ name: 'CliScaffold.run',
894
+ purpose: 'workspaces',
895
+ }).info(`Added "${normalizedWorkspaceRelPath}" to the root package.json workspaces.`);
896
+ }
897
+ await registerWorkspaceInConfig(configFilePath, workspaceRelPath, config['workspaceName'], category);
553
898
  Logger.customize({
554
899
  name: 'CliScaffold.run',
555
900
  purpose: 'complete',
556
901
  }).info(`Scaffold complete for ${category} ${typeName}.`);
557
- if (config['mode'] === 'monorepo') {
558
- await promptPostScaffoldGenerators(config['outputDirectory']);
902
+ if (config['mode'] === 'monorepo' && isNonInteractive === false) {
903
+ await promptPostScaffoldGenerators(configRoot);
559
904
  }
560
905
  return;
561
906
  }