@cbnventures/nova 0.25.2 → 0.27.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/build/package.json +17 -14
- package/build/src/cli/generate/github/workflows-blueprint-validate.js +1 -1
- package/build/src/cli/generate/github/workflows-blueprint-validate.js.map +1 -1
- package/build/src/cli/generate/github/workflows-blueprint.d.ts +6 -3
- package/build/src/cli/generate/github/workflows-blueprint.d.ts.map +1 -1
- package/build/src/cli/generate/github/workflows-blueprint.js +101 -22
- package/build/src/cli/generate/github/workflows-blueprint.js.map +1 -1
- package/build/src/cli/index.js +105 -28
- package/build/src/cli/index.js.map +1 -1
- package/build/src/cli/recipe/github/gh-commands.d.ts +3 -0
- package/build/src/cli/recipe/github/gh-commands.d.ts.map +1 -0
- package/build/src/cli/recipe/github/gh-commands.js +28 -0
- package/build/src/cli/recipe/github/gh-commands.js.map +1 -0
- package/build/src/cli/recipe/github/sync-actions.d.ts +5 -0
- package/build/src/cli/recipe/github/sync-actions.d.ts.map +1 -0
- package/build/src/cli/recipe/github/sync-actions.js +103 -0
- package/build/src/cli/recipe/github/sync-actions.js.map +1 -0
- package/build/src/cli/recipe/github/sync-features.d.ts.map +1 -1
- package/build/src/cli/recipe/github/sync-features.js +46 -11
- package/build/src/cli/recipe/github/sync-features.js.map +1 -1
- package/build/src/cli/recipe/github/sync-labels.d.ts +5 -0
- package/build/src/cli/recipe/github/sync-labels.d.ts.map +1 -0
- package/build/src/cli/recipe/github/sync-labels.js +40 -0
- package/build/src/cli/recipe/github/sync-labels.js.map +1 -0
- package/build/src/cli/recipe/github/sync-policies.d.ts.map +1 -1
- package/build/src/cli/recipe/github/sync-policies.js +89 -10
- package/build/src/cli/recipe/github/sync-policies.js.map +1 -1
- package/build/src/cli/recipe/github/sync-rulesets.d.ts +5 -0
- package/build/src/cli/recipe/github/sync-rulesets.d.ts.map +1 -0
- package/build/src/cli/recipe/github/sync-rulesets.js +137 -0
- package/build/src/cli/recipe/github/sync-rulesets.js.map +1 -0
- package/build/src/cli/recipe/github/sync-security.d.ts +5 -0
- package/build/src/cli/recipe/github/sync-security.d.ts.map +1 -0
- package/build/src/cli/recipe/github/sync-security.js +69 -0
- package/build/src/cli/recipe/github/sync-security.js.map +1 -0
- package/build/src/cli/recipe/index.d.ts.map +1 -1
- package/build/src/cli/recipe/index.js +25 -0
- package/build/src/cli/recipe/index.js.map +1 -1
- package/build/src/cli/recipe/miscellaneous/fix-markdown-tables.d.ts +10 -0
- package/build/src/cli/recipe/miscellaneous/fix-markdown-tables.d.ts.map +1 -0
- package/build/src/cli/recipe/miscellaneous/fix-markdown-tables.js +252 -0
- package/build/src/cli/recipe/miscellaneous/fix-markdown-tables.js.map +1 -0
- package/build/src/cli/recipe/package-json/normalize-tooling.d.ts.map +1 -1
- package/build/src/cli/recipe/package-json/normalize-tooling.js +40 -0
- package/build/src/cli/recipe/package-json/normalize-tooling.js.map +1 -1
- package/build/src/cli/recipe/package-json/sync-environment.d.ts.map +1 -1
- package/build/src/cli/recipe/package-json/sync-environment.js +16 -15
- package/build/src/cli/recipe/package-json/sync-environment.js.map +1 -1
- package/build/src/cli/scaffold/docs/docusaurus.d.ts +2 -1
- package/build/src/cli/scaffold/docs/docusaurus.d.ts.map +1 -1
- package/build/src/cli/scaffold/docs/docusaurus.js +41 -1
- package/build/src/cli/scaffold/docs/docusaurus.js.map +1 -1
- package/build/src/cli/scaffold/starter/base.d.ts.map +1 -1
- package/build/src/cli/scaffold/starter/base.js +58 -6
- package/build/src/cli/scaffold/starter/base.js.map +1 -1
- package/build/src/cli/utility/changelog.d.ts +1 -0
- package/build/src/cli/utility/changelog.d.ts.map +1 -1
- package/build/src/cli/utility/changelog.js +183 -67
- package/build/src/cli/utility/changelog.js.map +1 -1
- package/build/src/cli/utility/initialize.d.ts.map +1 -1
- package/build/src/cli/utility/initialize.js +133 -45
- package/build/src/cli/utility/initialize.js.map +1 -1
- package/build/src/cli/utility/run-scripts.d.ts +5 -5
- package/build/src/cli/utility/run-scripts.d.ts.map +1 -1
- package/build/src/cli/utility/run-scripts.js +28 -252
- package/build/src/cli/utility/run-scripts.js.map +1 -1
- package/build/src/cli/utility/transpile.d.ts.map +1 -1
- package/build/src/cli/utility/transpile.js +23 -5
- package/build/src/cli/utility/transpile.js.map +1 -1
- package/build/src/cli/utility/type-check.d.ts +2 -4
- package/build/src/cli/utility/type-check.d.ts.map +1 -1
- package/build/src/cli/utility/type-check.js +13 -54
- package/build/src/cli/utility/type-check.js.map +1 -1
- package/build/src/cli/utility/version.d.ts.map +1 -1
- package/build/src/cli/utility/version.js +0 -12
- package/build/src/cli/utility/version.js.map +1 -1
- package/build/src/lib/corepack.d.ts +5 -0
- package/build/src/lib/corepack.d.ts.map +1 -0
- package/build/src/lib/corepack.js +26 -0
- package/build/src/lib/corepack.js.map +1 -0
- package/build/src/lib/item.d.ts.map +1 -1
- package/build/src/lib/item.js +4 -1
- package/build/src/lib/item.js.map +1 -1
- package/build/src/lib/nova-config.d.ts +8 -0
- package/build/src/lib/nova-config.d.ts.map +1 -1
- package/build/src/lib/nova-config.js +329 -7
- package/build/src/lib/nova-config.js.map +1 -1
- package/build/src/lib/regex.d.ts +7 -0
- package/build/src/lib/regex.d.ts.map +1 -1
- package/build/src/lib/regex.js +8 -1
- package/build/src/lib/regex.js.map +1 -1
- package/build/src/lib/release-history.d.ts +5 -0
- package/build/src/lib/release-history.d.ts.map +1 -0
- package/build/src/lib/release-history.js +86 -0
- package/build/src/lib/release-history.js.map +1 -0
- package/build/src/lib/run-scripts.d.ts +10 -0
- package/build/src/lib/run-scripts.d.ts.map +1 -0
- package/build/src/lib/run-scripts.js +310 -0
- package/build/src/lib/run-scripts.js.map +1 -0
- package/build/src/lib/scaffold.d.ts +7 -2
- package/build/src/lib/scaffold.d.ts.map +1 -1
- package/build/src/lib/scaffold.js +489 -53
- package/build/src/lib/scaffold.js.map +1 -1
- package/build/src/lib/type-check.d.ts +3 -0
- package/build/src/lib/type-check.d.ts.map +1 -0
- package/build/src/lib/type-check.js +69 -0
- package/build/src/lib/type-check.js.map +1 -0
- package/build/src/presets/tsconfig/dx-strict.json +0 -1
- package/build/src/presets/tsconfig/fw-homebridge.json +11 -0
- package/build/src/rules/eslint/regex/no-regex-literals.d.ts +1 -0
- package/build/src/rules/eslint/regex/no-regex-literals.d.ts.map +1 -1
- package/build/src/rules/eslint/regex/no-regex-literals.js +20 -1
- package/build/src/rules/eslint/regex/no-regex-literals.js.map +1 -1
- package/build/src/rules/eslint/typescript/no-shared-type-import.d.ts +1 -0
- package/build/src/rules/eslint/typescript/no-shared-type-import.d.ts.map +1 -1
- package/build/src/rules/eslint/typescript/no-shared-type-import.js +19 -1
- package/build/src/rules/eslint/typescript/no-shared-type-import.js.map +1 -1
- package/build/src/toolkit/index.d.ts +1 -0
- package/build/src/toolkit/index.d.ts.map +1 -1
- package/build/src/toolkit/index.js +1 -0
- package/build/src/toolkit/index.js.map +1 -1
- package/build/src/toolkit/vitest-setup.d.ts +6 -0
- package/build/src/toolkit/vitest-setup.d.ts.map +1 -0
- package/build/src/toolkit/vitest-setup.js +21 -0
- package/build/src/toolkit/vitest-setup.js.map +1 -0
- package/build/src/types/cli/generate/github/workflows-blueprint-validate.d.ts +4 -4
- package/build/src/types/cli/generate/github/workflows-blueprint.d.ts +67 -3
- package/build/src/types/cli/index.d.ts +6 -0
- package/build/src/types/cli/recipe/github/gh-commands.d.ts +34 -0
- package/build/src/types/cli/recipe/github/sync-actions.d.ts +43 -0
- package/build/src/types/cli/recipe/github/sync-features.d.ts +16 -2
- package/build/src/types/cli/recipe/github/sync-labels.d.ts +36 -0
- package/build/src/types/cli/recipe/github/sync-policies.d.ts +14 -2
- package/build/src/types/cli/recipe/github/sync-rulesets.d.ts +71 -0
- package/build/src/types/cli/recipe/github/sync-security.d.ts +34 -0
- package/build/src/types/cli/recipe/index.d.ts +2 -1
- package/build/src/types/cli/recipe/miscellaneous/fix-markdown-tables.d.ts +188 -0
- package/build/src/types/cli/recipe/package-json/normalize-tooling.d.ts +28 -2
- package/build/src/types/cli/recipe/package-json/sync-environment.d.ts +3 -0
- package/build/src/types/cli/scaffold/app/expressjs.d.ts +3 -0
- package/build/src/types/cli/scaffold/app/nextjs.d.ts +3 -0
- package/build/src/types/cli/scaffold/app/vite.d.ts +3 -0
- package/build/src/types/cli/scaffold/app/workers.d.ts +3 -0
- package/build/src/types/cli/scaffold/docs/docusaurus.d.ts +15 -0
- package/build/src/types/cli/scaffold/starter/base.d.ts +11 -0
- package/build/src/types/cli/utility/changelog.d.ts +87 -26
- package/build/src/types/cli/utility/initialize.d.ts +39 -29
- package/build/src/types/cli/utility/run-scripts.d.ts +22 -174
- package/build/src/types/cli/utility/transpile.d.ts +9 -1
- package/build/src/types/cli/utility/type-check.d.ts +9 -71
- package/build/src/types/cli/utility/version.d.ts +1 -7
- package/build/src/types/lib/corepack.d.ts +19 -0
- package/build/src/types/lib/nova-config.d.ts +256 -23
- package/build/src/types/lib/regex.d.ts +42 -0
- package/build/src/types/lib/release-history.d.ts +57 -0
- package/build/src/types/lib/run-scripts.d.ts +264 -0
- package/build/src/types/lib/scaffold.d.ts +193 -10
- package/build/src/types/lib/type-check.d.ts +102 -0
- package/build/src/types/rules/eslint/regex/no-regex-literals.d.ts +21 -0
- package/build/src/types/rules/eslint/typescript/no-shared-type-import.d.ts +21 -0
- package/build/src/types/shared.d.ts +264 -22
- package/build/src/types/tests/cli/generate/github/workflows-blueprint.test.d.ts +4 -0
- package/build/src/types/tests/cli/index.test.d.ts +283 -0
- package/build/src/types/tests/cli/recipe/miscellaneous/fix-markdown-tables.test.d.ts +106 -0
- package/build/src/types/tests/cli/recipe/package-json/normalize-tooling.test.d.ts +56 -0
- package/build/src/types/tests/cli/scaffold/app/expressjs.test.d.ts +4 -0
- package/build/src/types/tests/cli/scaffold/app/nextjs.test.d.ts +4 -0
- package/build/src/types/tests/cli/scaffold/app/vite.test.d.ts +48 -0
- package/build/src/types/tests/cli/scaffold/app/workers.test.d.ts +4 -0
- package/build/src/types/tests/cli/scaffold/docs/docusaurus.test.d.ts +10 -2
- package/build/src/types/tests/cli/utility/changelog.test.d.ts +99 -0
- package/build/src/types/tests/cli/utility/initialize.test.d.ts +43 -0
- package/build/src/types/tests/cli/utility/run-scripts.test.d.ts +29 -0
- package/build/src/types/tests/cli/utility/transpile.test.d.ts +28 -0
- package/build/src/types/tests/cli/utility/type-check.test.d.ts +46 -0
- package/build/src/types/tests/lib/nova-config.test.d.ts +19 -19
- package/build/src/types/tests/lib/regex.test.d.ts +7 -0
- package/build/src/types/tests/lib/release-history.test.d.ts +94 -0
- package/build/src/types/tests/lib/scaffold.test.d.ts +88 -0
- package/build/src/types/tests/rules/eslint/regex/no-regex-literals.test.d.ts +46 -0
- package/build/src/types/tests/rules/eslint/typescript/no-shared-type-import.test.d.ts +46 -0
- package/build/src/types/tests/scaffold-output-contract.test.d.ts +155 -0
- package/build/src/types/tests/scaffold-template-source.test.d.ts +42 -0
- package/build/src/types/tests/toolkit/vitest-setup.test.d.ts +36 -0
- package/build/src/types/tests/tsconfig-presets.test.d.ts +81 -0
- package/build/src/types/toolkit/vitest-setup.d.ts +24 -0
- package/build/templates/generators/github/workflows/publish/base.yml +1 -1
- package/build/templates/generators/github/workflows/publish/targets/cloudflare-workers.yml +1 -1
- package/build/templates/generators/must-haves/agent-conventions/PROJECT_RULES.md +11 -11
- package/build/templates/generators/must-haves/agent-conventions/conventions/documentation.md +4 -4
- package/build/templates/scaffold/app/express/package.json +13 -5
- package/build/templates/scaffold/app/express/tsconfig.json +1 -0
- package/build/templates/scaffold/app/nextjs/package.json +20 -12
- package/build/templates/scaffold/app/nextjs/tsconfig.json +3 -2
- package/build/templates/scaffold/app/vite/package.json +15 -6
- package/build/templates/scaffold/app/workers/package.json +15 -7
- package/build/templates/scaffold/app/workers/wrangler.toml +1 -1
- package/build/templates/scaffold/docs/docusaurus/docusaurus.config.ts +14 -12
- package/build/templates/scaffold/docs/docusaurus/package.json +29 -15
- package/build/templates/scaffold/docs/docusaurus/src/pages/index.mdx +8 -0
- package/build/templates/scaffold/docs/docusaurus/tsconfig.json +11 -5
- package/build/templates/scaffold/docs/docusaurus/{vitest.config.ts → vitest.config.mts} +11 -0
- package/build/templates/scaffold/docs/docusaurus/vitest.setup.ts +5 -14
- package/package.json +17 -14
- /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
|
|
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
|
-
|
|
51
|
-
|
|
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: '
|
|
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
|
-
|
|
162
|
-
|
|
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,42 @@ export async function createMonorepoRoot(outputDirectory, projectSlug) {
|
|
|
241
427
|
name: `${projectSlug}-project`,
|
|
242
428
|
version: '0.0.0',
|
|
243
429
|
private: true,
|
|
430
|
+
scripts: {
|
|
431
|
+
'dev': 'nova utility run-scripts --parallel \'dev:*\'',
|
|
432
|
+
'dev:workspaces': 'turbo run dev',
|
|
433
|
+
'prod': 'nova utility run-scripts --sequential \'prod:*\'',
|
|
434
|
+
'prod:workspaces': 'turbo run prod',
|
|
435
|
+
'check': 'nova utility run-scripts --sequential \'check:*\'',
|
|
436
|
+
'check:workspaces': 'turbo run check --concurrency=2',
|
|
437
|
+
'build': 'nova utility run-scripts --sequential \'build:*\'',
|
|
438
|
+
'build:workspaces': 'turbo run build --concurrency=2',
|
|
439
|
+
'deploy': 'nova utility run-scripts --sequential \'deploy:*\'',
|
|
440
|
+
'deploy:workspaces': 'turbo run deploy --concurrency=2',
|
|
441
|
+
'clean': 'nova utility run-scripts --parallel \'clean:*\'',
|
|
442
|
+
'clean:workspaces': 'turbo run clean',
|
|
443
|
+
'changelog': 'nova utility changelog',
|
|
444
|
+
'recipes': 'nova utility run-recipes --replace-file',
|
|
445
|
+
},
|
|
446
|
+
allowScripts: {
|
|
447
|
+
'core-js': false,
|
|
448
|
+
'core-js-pure': false,
|
|
449
|
+
'es5-ext': false,
|
|
450
|
+
'esbuild': false,
|
|
451
|
+
'sharp': false,
|
|
452
|
+
'unrs-resolver': false,
|
|
453
|
+
'workerd': false,
|
|
454
|
+
},
|
|
244
455
|
workspaces: [
|
|
245
456
|
'apps/*',
|
|
246
457
|
'packages/*',
|
|
247
458
|
],
|
|
248
|
-
|
|
249
|
-
'@cbnventures/nova': 'latest',
|
|
250
|
-
},
|
|
459
|
+
packageManager: 'npm@11.18.0',
|
|
251
460
|
engines: {
|
|
252
|
-
node: '
|
|
461
|
+
node: '^22 || ^24',
|
|
462
|
+
},
|
|
463
|
+
devDependencies: {
|
|
464
|
+
'@cbnventures/nova': novaPackageJson['version'],
|
|
465
|
+
'turbo': novaPackageJson['devDependencies']['turbo'],
|
|
253
466
|
},
|
|
254
467
|
};
|
|
255
468
|
const packageJsonPath = join(outputDirectory, 'package.json');
|
|
@@ -259,6 +472,80 @@ export async function createMonorepoRoot(outputDirectory, projectSlug) {
|
|
|
259
472
|
name: 'createMonorepoRoot',
|
|
260
473
|
purpose: 'written',
|
|
261
474
|
}).info(`Created "${packageJsonRelativePath}".`);
|
|
475
|
+
const turboJsonContent = {
|
|
476
|
+
$schema: 'https://turbo.build/schema.json',
|
|
477
|
+
globalDependencies: [
|
|
478
|
+
'package-lock.json',
|
|
479
|
+
'.env',
|
|
480
|
+
],
|
|
481
|
+
noUpdateNotifier: true,
|
|
482
|
+
tasks: {
|
|
483
|
+
dev: {
|
|
484
|
+
cache: false,
|
|
485
|
+
dependsOn: [],
|
|
486
|
+
inputs: [],
|
|
487
|
+
outputs: [],
|
|
488
|
+
persistent: true,
|
|
489
|
+
},
|
|
490
|
+
prod: {
|
|
491
|
+
cache: false,
|
|
492
|
+
dependsOn: [
|
|
493
|
+
'check',
|
|
494
|
+
'build',
|
|
495
|
+
],
|
|
496
|
+
inputs: [],
|
|
497
|
+
outputs: [],
|
|
498
|
+
persistent: true,
|
|
499
|
+
},
|
|
500
|
+
check: {
|
|
501
|
+
cache: false,
|
|
502
|
+
dependsOn: ['^build'],
|
|
503
|
+
inputs: [
|
|
504
|
+
'!./.*/**/*',
|
|
505
|
+
'!./build/**',
|
|
506
|
+
'./**/*',
|
|
507
|
+
],
|
|
508
|
+
outputs: [],
|
|
509
|
+
persistent: false,
|
|
510
|
+
},
|
|
511
|
+
build: {
|
|
512
|
+
cache: false,
|
|
513
|
+
dependsOn: ['^build'],
|
|
514
|
+
inputs: [
|
|
515
|
+
'!./.*/**/*',
|
|
516
|
+
'!./build/**',
|
|
517
|
+
'./**/*',
|
|
518
|
+
],
|
|
519
|
+
outputs: ['./build/**'],
|
|
520
|
+
persistent: false,
|
|
521
|
+
},
|
|
522
|
+
deploy: {
|
|
523
|
+
cache: false,
|
|
524
|
+
dependsOn: [
|
|
525
|
+
'check',
|
|
526
|
+
'build',
|
|
527
|
+
],
|
|
528
|
+
inputs: [],
|
|
529
|
+
outputs: [],
|
|
530
|
+
persistent: false,
|
|
531
|
+
},
|
|
532
|
+
clean: {
|
|
533
|
+
cache: false,
|
|
534
|
+
dependsOn: [],
|
|
535
|
+
inputs: [],
|
|
536
|
+
outputs: [],
|
|
537
|
+
persistent: false,
|
|
538
|
+
},
|
|
539
|
+
},
|
|
540
|
+
ui: 'tui',
|
|
541
|
+
};
|
|
542
|
+
const turboJsonPath = join(outputDirectory, 'turbo.json');
|
|
543
|
+
await fs.writeFile(turboJsonPath, `${JSON.stringify(turboJsonContent, null, 2)}\n`, 'utf-8');
|
|
544
|
+
const turboJsonRelativePath = relative(currentDirectory, turboJsonPath);
|
|
545
|
+
Logger.customize({
|
|
546
|
+
name: 'createMonorepoRoot',
|
|
547
|
+
purpose: 'written',
|
|
548
|
+
}).info(`Created "${turboJsonRelativePath}".`);
|
|
262
549
|
const projectTitle = projectSlug
|
|
263
550
|
.split('-')
|
|
264
551
|
.map((word) => `${word.charAt(0).toUpperCase()}${word.slice(1)}`)
|
|
@@ -446,29 +733,33 @@ export async function registerWorkspaceInConfig(configFilePath, workspaceRelPath
|
|
|
446
733
|
const raw = await fs.readFile(configFilePath, 'utf-8');
|
|
447
734
|
parsedConfig = JSON.parse(raw);
|
|
448
735
|
}
|
|
449
|
-
catch {
|
|
736
|
+
catch (error) {
|
|
737
|
+
reportError('Unable to read nova.config.json while registering the scaffolded workspace.');
|
|
450
738
|
Logger.customize({
|
|
451
739
|
name: 'registerWorkspaceInConfig',
|
|
452
|
-
purpose: '
|
|
453
|
-
}).
|
|
740
|
+
purpose: 'config',
|
|
741
|
+
}).debug(error);
|
|
454
742
|
return;
|
|
455
743
|
}
|
|
456
|
-
if (parsedConfig ===
|
|
744
|
+
if (isPlainObject(parsedConfig) === false) {
|
|
745
|
+
reportError('The root nova.config.json must contain a JSON object.');
|
|
457
746
|
return;
|
|
458
747
|
}
|
|
459
748
|
const project = parsedConfig['project'];
|
|
460
749
|
const projectName = (project !== undefined) ? project['name'] : undefined;
|
|
461
750
|
const projectSlug = (projectName !== undefined) ? projectName['slug'] : undefined;
|
|
462
|
-
if (projectSlug ===
|
|
463
|
-
|
|
464
|
-
name: 'registerWorkspaceInConfig',
|
|
465
|
-
purpose: 'skip',
|
|
466
|
-
}).warn('No project slug found in nova.config.json. Skipping workspace registration.');
|
|
751
|
+
if (typeof projectSlug !== 'string' || LIB_REGEX_PATTERN_SLUG_SIMPLE.test(projectSlug) === false) {
|
|
752
|
+
reportError('The root nova.config.json must define a valid project.name.slug before registering a workspace.');
|
|
467
753
|
return;
|
|
468
754
|
}
|
|
469
755
|
const role = (category === 'docs') ? 'docs' : 'app';
|
|
470
|
-
const configName = (
|
|
471
|
-
const
|
|
756
|
+
const configName = resolveWorkspacePackageName(projectSlug, workspaceName, category);
|
|
757
|
+
const parsedWorkspaces = parsedConfig['workspaces'];
|
|
758
|
+
if (parsedWorkspaces !== undefined && isPlainObject(parsedWorkspaces) === false) {
|
|
759
|
+
reportError('The root nova.config.json "workspaces" field must be an object.');
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
const workspaces = parsedWorkspaces ?? {};
|
|
472
763
|
Reflect.set(workspaces, workspaceRelPath, {
|
|
473
764
|
name: configName,
|
|
474
765
|
role,
|
|
@@ -482,9 +773,10 @@ export async function registerWorkspaceInConfig(configFilePath, workspaceRelPath
|
|
|
482
773
|
}).info(`Registered workspace "${configName}" in nova.config.json.`);
|
|
483
774
|
return;
|
|
484
775
|
}
|
|
485
|
-
export async function runScaffold(options, category, typeName, templateSubpath, importMetaUrl) {
|
|
776
|
+
export async function runScaffold(options, category, typeName, templateSubpath, importMetaUrl, templateQuestions = []) {
|
|
486
777
|
const currentDirectory = process.cwd();
|
|
487
778
|
const isDryRun = options['dryRun'] === true;
|
|
779
|
+
const isNonInteractive = options['nonInteractive'] === true;
|
|
488
780
|
if (isDryRun === true) {
|
|
489
781
|
Logger.customize({
|
|
490
782
|
name: 'CliScaffold.run',
|
|
@@ -492,28 +784,51 @@ export async function runScaffold(options, category, typeName, templateSubpath,
|
|
|
492
784
|
}).warn('Dry run enabled. File changes will not be made in this session.');
|
|
493
785
|
}
|
|
494
786
|
const context = await detectMonorepoContext(currentDirectory);
|
|
787
|
+
if (context['context'] === 'invalid') {
|
|
788
|
+
reportError(`${context['reason']} No scaffold files were written.`);
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
495
791
|
if (context['context'] === 'nested') {
|
|
496
|
-
|
|
497
|
-
name: 'CliScaffold.run',
|
|
498
|
-
purpose: 'context',
|
|
499
|
-
}).error('Re-run this command from the monorepo root directory.');
|
|
500
|
-
process.exitCode = 1;
|
|
792
|
+
reportError('Re-run this command from the monorepo root directory. No scaffold files were written.');
|
|
501
793
|
return;
|
|
502
794
|
}
|
|
503
795
|
if (context['context'] === 'standalone') {
|
|
504
|
-
|
|
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;
|
|
796
|
+
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
797
|
return;
|
|
510
798
|
}
|
|
511
799
|
Logger.customize({
|
|
512
800
|
name: 'CliScaffold.run',
|
|
513
801
|
purpose: 'context',
|
|
514
802
|
}).info(`Detected mode: ${context['context']}.`);
|
|
803
|
+
let existingRoot = undefined;
|
|
804
|
+
if (context['context'] === 'workspace') {
|
|
805
|
+
existingRoot = await loadExistingRoot(context['root']);
|
|
806
|
+
if (existingRoot === undefined) {
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
if (options['name'] !== undefined && options['name'] !== existingRoot['projectSlug']) {
|
|
810
|
+
reportError(`This monorepo's project slug is "${existingRoot['projectSlug']}", not "${options['name']}". Omit --name when adding a workspace. No scaffold files were written.`);
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
if (isNonInteractive === true
|
|
815
|
+
&& (options['output'] === undefined
|
|
816
|
+
|| options['workspaceName'] === undefined)) {
|
|
817
|
+
reportError('Non-interactive scaffolding requires --workspace-name and --output. No scaffold files were written.');
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
if (isNonInteractive === true
|
|
821
|
+
&& context['context'] === 'monorepo'
|
|
822
|
+
&& options['name'] === undefined) {
|
|
823
|
+
reportError('Creating a new monorepo non-interactively also requires --name. No scaffold files were written.');
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
let configNameDefault = options['name'];
|
|
827
|
+
if (context['context'] === 'workspace' && existingRoot !== undefined) {
|
|
828
|
+
configNameDefault = existingRoot['projectSlug'];
|
|
829
|
+
}
|
|
515
830
|
const config = await promptScaffoldOptions(context, {
|
|
516
|
-
name:
|
|
831
|
+
name: configNameDefault,
|
|
517
832
|
output: options['output'],
|
|
518
833
|
typeName,
|
|
519
834
|
workspaceName: options['workspaceName'],
|
|
@@ -525,37 +840,158 @@ export async function runScaffold(options, category, typeName, templateSubpath,
|
|
|
525
840
|
}).warn('Scaffold cancelled.');
|
|
526
841
|
return;
|
|
527
842
|
}
|
|
843
|
+
if (LIB_REGEX_PATTERN_SLUG_SIMPLE.test(config['name']) === false) {
|
|
844
|
+
reportError('The project name must be a lowercase slug containing only letters, numbers, hyphens, or underscores. No scaffold files were written.');
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
847
|
+
if (LIB_REGEX_PATTERN_SLUG_SIMPLE.test(config['workspaceName']) === false) {
|
|
848
|
+
reportError('The workspace name must be a lowercase slug containing only letters, numbers, hyphens, or underscores. No scaffold files were written.');
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
const projectSlug = config['name'];
|
|
852
|
+
const workspacePackageName = resolveWorkspacePackageName(projectSlug, config['workspaceName'], category);
|
|
853
|
+
const configRoot = (config['mode'] === 'monorepo') ? config['outputDirectory'] : currentDirectory;
|
|
854
|
+
const configFilePath = join(configRoot, 'nova.config.json');
|
|
855
|
+
const workspaceDirectory = (config['mode'] === 'monorepo') ? join(configRoot, 'apps', config['workspaceName']) : config['outputDirectory'];
|
|
856
|
+
const workspaceRelPath = normalizeWorkspaceRelativePath(configRoot, workspaceDirectory);
|
|
857
|
+
if (workspaceRelPath === undefined) {
|
|
858
|
+
reportError('The workspace output must be a child directory of the monorepo root. No scaffold files were written.');
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
const normalizedWorkspaceRelPath = workspaceRelPath.slice(2);
|
|
862
|
+
if (existingRoot !== undefined) {
|
|
863
|
+
const existingWorkspaceEntries = Object.entries(existingRoot['workspaces']);
|
|
864
|
+
for (const existingWorkspaceEntry of existingWorkspaceEntries) {
|
|
865
|
+
const existingWorkspacePath = existingWorkspaceEntry[0];
|
|
866
|
+
const existingWorkspaceValue = existingWorkspaceEntry[1];
|
|
867
|
+
const existingWorkspaceNormalizedPath = resolve(configRoot, existingWorkspacePath);
|
|
868
|
+
if (existingWorkspaceNormalizedPath === workspaceDirectory) {
|
|
869
|
+
reportError(`The workspace path "${workspaceRelPath}" is already registered in nova.config.json. No scaffold files were written.`);
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
872
|
+
if (existingWorkspaceNormalizedPath !== configRoot
|
|
873
|
+
&& (workspaceDirectory.startsWith(`${existingWorkspaceNormalizedPath}${sep}`) === true
|
|
874
|
+
|| existingWorkspaceNormalizedPath.startsWith(`${workspaceDirectory}${sep}`) === true)) {
|
|
875
|
+
reportError(`The workspace path "${workspaceRelPath}" overlaps the registered workspace "${existingWorkspacePath}". Workspaces cannot be nested inside one another. No scaffold files were written.`);
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
878
|
+
if (isPlainObject(existingWorkspaceValue) === false) {
|
|
879
|
+
reportError(`The nova.config.json workspace "${existingWorkspacePath}" must be an object. No scaffold files were written.`);
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
882
|
+
const existingWorkspace = existingWorkspaceValue;
|
|
883
|
+
const existingWorkspaceName = existingWorkspace['name'];
|
|
884
|
+
const existingWorkspaceRole = existingWorkspace['role'];
|
|
885
|
+
if (typeof existingWorkspaceName !== 'string' || typeof existingWorkspaceRole !== 'string') {
|
|
886
|
+
reportError(`The nova.config.json workspace "${existingWorkspacePath}" must define string name and role fields. No scaffold files were written.`);
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
889
|
+
if (category === 'docs' && existingWorkspaceRole === 'docs') {
|
|
890
|
+
reportError(`A documentation workspace is already registered at "${existingWorkspacePath}". Nova projects support one canonical docs workspace. No scaffold files were written.`);
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
if (existingWorkspaceName === workspacePackageName) {
|
|
894
|
+
reportError(`The workspace package name "${workspacePackageName}" is already registered in nova.config.json. No scaffold files were written.`);
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
const templateDirectory = resolveTemplatePath(importMetaUrl, templateSubpath);
|
|
900
|
+
const templateEntries = await collectFiles(templateDirectory, '');
|
|
901
|
+
const plannedPaths = templateEntries.map((templateEntry) => join(workspaceDirectory, templateEntry));
|
|
902
|
+
if (config['mode'] === 'monorepo') {
|
|
903
|
+
plannedPaths.push(join(configRoot, 'package.json'), configFilePath, join(configRoot, 'turbo.json'));
|
|
904
|
+
}
|
|
905
|
+
const conflictingPaths = await findFileConflicts(plannedPaths);
|
|
906
|
+
if (conflictingPaths.length > 0) {
|
|
907
|
+
const conflictMessage = conflictingPaths.map((conflictingPath) => relative(configRoot, conflictingPath)).join(', ');
|
|
908
|
+
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.`);
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
911
|
+
let isWorkspaceCovered = existingRoot === undefined;
|
|
912
|
+
if (existingRoot !== undefined) {
|
|
913
|
+
for (const workspacePattern of existingRoot['workspacePatterns']) {
|
|
914
|
+
const normalizedWorkspacePattern = (workspacePattern.startsWith('./') === true) ? workspacePattern.slice(2) : workspacePattern;
|
|
915
|
+
if (minimatch(normalizedWorkspaceRelPath, normalizedWorkspacePattern, { dot: true }) === true) {
|
|
916
|
+
isWorkspaceCovered = true;
|
|
917
|
+
break;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
const templateReplacements = await resolveTemplateAnswers(options, templateQuestions, isNonInteractive);
|
|
922
|
+
if (templateReplacements === undefined) {
|
|
923
|
+
if (process.exitCode !== 1) {
|
|
924
|
+
Logger.customize({
|
|
925
|
+
name: 'CliScaffold.run',
|
|
926
|
+
purpose: 'cancelled',
|
|
927
|
+
}).warn('Scaffold cancelled.');
|
|
928
|
+
}
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
528
931
|
Logger.customize({
|
|
529
932
|
name: 'CliScaffold.run',
|
|
530
933
|
purpose: 'config',
|
|
531
|
-
}).info(`Scaffolding ${category} ${typeName} "${
|
|
934
|
+
}).info(`Scaffolding ${category} ${typeName} workspace "${workspacePackageName}" in "${workspaceDirectory}".`);
|
|
532
935
|
if (isDryRun === true) {
|
|
533
|
-
|
|
936
|
+
if (config['mode'] === 'monorepo') {
|
|
937
|
+
Logger.customize({
|
|
938
|
+
name: 'CliScaffold.run',
|
|
939
|
+
purpose: 'dryRunRoot',
|
|
940
|
+
}).info(`Would create monorepo root at "${configRoot}".`);
|
|
941
|
+
}
|
|
534
942
|
Logger.customize({
|
|
535
943
|
name: 'CliScaffold.run',
|
|
536
|
-
purpose: '
|
|
537
|
-
}).info(`Would create ${
|
|
944
|
+
purpose: 'dryRunWorkspace',
|
|
945
|
+
}).info(`Would create workspace at "${workspaceDirectory}" and register "${workspaceRelPath}".`);
|
|
946
|
+
if (existingRoot !== undefined && isWorkspaceCovered === false) {
|
|
947
|
+
Logger.customize({
|
|
948
|
+
name: 'CliScaffold.run',
|
|
949
|
+
purpose: 'dryRunWorkspaces',
|
|
950
|
+
}).info(`Would add "${normalizedWorkspaceRelPath}" to the root package.json workspaces.`);
|
|
951
|
+
}
|
|
538
952
|
return;
|
|
539
953
|
}
|
|
540
954
|
if (config['mode'] === 'monorepo') {
|
|
541
|
-
await createMonorepoRoot(
|
|
955
|
+
await createMonorepoRoot(configRoot, projectSlug);
|
|
542
956
|
}
|
|
543
|
-
const workspaceDirectory = (config['mode'] === 'monorepo') ? join(config['outputDirectory'], 'apps', config['workspaceName']) : config['outputDirectory'];
|
|
544
957
|
await fs.mkdir(workspaceDirectory, { recursive: true });
|
|
545
|
-
const
|
|
546
|
-
|
|
958
|
+
const replacements = new Map([
|
|
959
|
+
[
|
|
547
960
|
LIB_REGEX_PLACEHOLDER_PROJECT_SLUG,
|
|
548
|
-
|
|
549
|
-
]
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
961
|
+
projectSlug,
|
|
962
|
+
],
|
|
963
|
+
[
|
|
964
|
+
LIB_REGEX_PLACEHOLDER_WORKSPACE_PACKAGE_NAME,
|
|
965
|
+
workspacePackageName,
|
|
966
|
+
],
|
|
967
|
+
...templateReplacements,
|
|
968
|
+
]);
|
|
969
|
+
await writeTemplateFiles(templateDirectory, workspaceDirectory, replacements);
|
|
970
|
+
if (existingRoot !== undefined && isWorkspaceCovered === false) {
|
|
971
|
+
existingRoot['workspacePatterns'].push(normalizedWorkspaceRelPath);
|
|
972
|
+
const rootPackageJsonPath = join(configRoot, 'package.json');
|
|
973
|
+
const rootWorkspacesValue = existingRoot['packageJson']['workspaces'];
|
|
974
|
+
if (isPlainObject(rootWorkspacesValue) === true) {
|
|
975
|
+
const rootWorkspacesObject = rootWorkspacesValue;
|
|
976
|
+
Reflect.set(rootWorkspacesObject, 'packages', existingRoot['workspacePatterns']);
|
|
977
|
+
}
|
|
978
|
+
else {
|
|
979
|
+
Reflect.set(existingRoot['packageJson'], 'workspaces', existingRoot['workspacePatterns']);
|
|
980
|
+
}
|
|
981
|
+
const rootPackageJsonContents = `${JSON.stringify(existingRoot['packageJson'], null, 2)}\n`;
|
|
982
|
+
await fs.writeFile(rootPackageJsonPath, rootPackageJsonContents, 'utf-8');
|
|
983
|
+
Logger.customize({
|
|
984
|
+
name: 'CliScaffold.run',
|
|
985
|
+
purpose: 'workspaces',
|
|
986
|
+
}).info(`Added "${normalizedWorkspaceRelPath}" to the root package.json workspaces.`);
|
|
987
|
+
}
|
|
988
|
+
await registerWorkspaceInConfig(configFilePath, workspaceRelPath, config['workspaceName'], category);
|
|
553
989
|
Logger.customize({
|
|
554
990
|
name: 'CliScaffold.run',
|
|
555
991
|
purpose: 'complete',
|
|
556
992
|
}).info(`Scaffold complete for ${category} ${typeName}.`);
|
|
557
|
-
if (config['mode'] === 'monorepo') {
|
|
558
|
-
await promptPostScaffoldGenerators(
|
|
993
|
+
if (config['mode'] === 'monorepo' && isNonInteractive === false) {
|
|
994
|
+
await promptPostScaffoldGenerators(configRoot);
|
|
559
995
|
}
|
|
560
996
|
return;
|
|
561
997
|
}
|