@flarum/cli 2.0.0-beta.13 → 2.0.0-beta.16
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/README.md +136 -39
- package/bin/run +2 -1
- package/bin/splitsh-lite-darwin +0 -0
- package/bin/splitsh-lite-linux +0 -0
- package/boilerplate/skeleton/extension/.gitattributes +16 -14
- package/boilerplate/skeleton/extension/.github/workflows/backend.yml +1 -1
- package/boilerplate/skeleton/extension/.github/workflows/frontend.yml +3 -1
- package/boilerplate/skeleton/extension/LICENSE.md +1 -1
- package/boilerplate/skeleton/extension/composer.json +6 -4
- package/boilerplate/skeleton/extension/js/package.json +5 -1
- package/boilerplate/skeleton/extension/js/tsconfig.json +10 -2
- package/boilerplate/skeleton/extension/locale/en.yml +1 -1
- package/boilerplate/skeleton/extension/tests/phpunit.integration.xml +1 -0
- package/lib/base-command.d.ts +3 -1
- package/lib/base-command.js +44 -31
- package/lib/boilersmith/io.d.ts +28 -8
- package/lib/boilersmith/io.js +4 -2
- package/lib/boilersmith/paths.d.ts +2 -2
- package/lib/boilersmith/paths.js +7 -7
- package/lib/boilersmith/scaffolding/audit-step-factory.js +11 -11
- package/lib/boilersmith/scaffolding/infra-step-factory.js +2 -2
- package/lib/boilersmith/scaffolding/init-step-factory.js +5 -5
- package/lib/boilersmith/scaffolding/module.d.ts +19 -8
- package/lib/boilersmith/scaffolding/module.js +56 -19
- package/lib/boilersmith/scaffolding/scaffolder.d.ts +4 -1
- package/lib/boilersmith/scaffolding/scaffolder.js +32 -32
- package/lib/boilersmith/scaffolding/template-param.d.ts +1 -1
- package/lib/boilersmith/scaffolding/template-param.js +2 -2
- package/lib/boilersmith/step-manager.d.ts +0 -1
- package/lib/boilersmith/step-manager.js +10 -20
- package/lib/boilersmith/steps/stub-base.js +3 -3
- package/lib/boilersmith/utils/clone-and-fill.js +1 -1
- package/lib/boilersmith/utils/commit-async.d.ts +2 -0
- package/lib/boilersmith/utils/commit-async.js +15 -0
- package/lib/boilersmith/utils/read-tpl.js +2 -2
- package/lib/commands/audit/infra.d.ts +1 -1
- package/lib/commands/audit/infra.js +30 -8
- package/lib/commands/infra.d.ts +2 -2
- package/lib/commands/infra.js +18 -12
- package/lib/commands/init.d.ts +1 -1
- package/lib/commands/init.js +4 -2
- package/lib/commands/make/backend/api-controller.js +1 -2
- package/lib/commands/make/backend/api-serializer-attributes.js +1 -2
- package/lib/commands/make/backend/command.js +1 -2
- package/lib/commands/make/backend/event-listener.js +1 -2
- package/lib/commands/make/backend/handler.js +2 -5
- package/lib/commands/make/backend/integration-test.js +2 -4
- package/lib/commands/make/backend/migration.js +1 -2
- package/lib/commands/make/backend/model.js +1 -2
- package/lib/commands/make/backend/policy.js +1 -2
- package/lib/commands/make/backend/route.js +1 -2
- package/lib/commands/make/backend/service-provider.js +1 -2
- package/lib/commands/make/frontend/model.js +2 -5
- package/lib/commands/monorepo/create.d.ts +15 -0
- package/lib/commands/monorepo/create.js +20 -0
- package/lib/commands/monorepo/split.d.ts +15 -0
- package/lib/commands/monorepo/split.js +19 -0
- package/lib/commands/update/js-imports.js +1 -2
- package/lib/help.js +1 -1
- package/lib/providers/php-provider.js +2 -2
- package/lib/steps/gen-ext-scaffolder.d.ts +1 -1
- package/lib/steps/gen-ext-scaffolder.js +114 -64
- package/lib/steps/js/base.js +2 -4
- package/lib/steps/js/model.js +4 -4
- package/lib/steps/misc/composer.js +2 -2
- package/lib/steps/misc/git.d.ts +1 -1
- package/lib/steps/misc/git.js +2 -2
- package/lib/steps/misc/npm.d.ts +11 -0
- package/lib/steps/misc/npm.js +19 -0
- package/lib/steps/misc/yarn.js +2 -2
- package/lib/steps/monorepo/create.d.ts +17 -0
- package/lib/steps/monorepo/create.js +186 -0
- package/lib/steps/monorepo/split.d.ts +14 -0
- package/lib/steps/monorepo/split.js +95 -0
- package/lib/steps/stubs/backend/api-controller.d.ts +1 -1
- package/lib/steps/stubs/backend/api-controller.js +3 -0
- package/lib/steps/stubs/backend/api-serializer.d.ts +1 -1
- package/lib/steps/stubs/backend/api-serializer.js +3 -0
- package/lib/steps/stubs/backend/command.d.ts +0 -5
- package/lib/steps/stubs/backend/command.js +1 -0
- package/lib/steps/stubs/backend/event-listener.d.ts +1 -1
- package/lib/steps/stubs/backend/event-listener.js +2 -0
- package/lib/steps/stubs/backend/handler-command.d.ts +1 -1
- package/lib/steps/stubs/backend/handler-command.js +1 -0
- package/lib/steps/stubs/backend/handler.d.ts +1 -1
- package/lib/steps/stubs/backend/handler.js +4 -0
- package/lib/steps/stubs/backend/integration-test.d.ts +1 -1
- package/lib/steps/stubs/backend/integration-test.js +2 -0
- package/lib/steps/stubs/backend/job.d.ts +1 -1
- package/lib/steps/stubs/backend/job.js +1 -0
- package/lib/steps/stubs/backend/migration.js +6 -3
- package/lib/steps/stubs/backend/model.d.ts +1 -1
- package/lib/steps/stubs/backend/model.js +1 -0
- package/lib/steps/stubs/backend/policy.d.ts +1 -1
- package/lib/steps/stubs/backend/policy.js +2 -0
- package/lib/steps/stubs/backend/repository.d.ts +1 -1
- package/lib/steps/stubs/backend/repository.js +2 -0
- package/lib/steps/stubs/backend/service-provider.d.ts +1 -1
- package/lib/steps/stubs/backend/service-provider.js +1 -0
- package/lib/steps/stubs/backend/validator.d.ts +1 -1
- package/lib/steps/stubs/backend/validator.js +1 -0
- package/lib/steps/stubs/flarum-base.js +1 -1
- package/lib/steps/stubs/frontend/component.d.ts +0 -5
- package/lib/steps/stubs/frontend/component.js +1 -0
- package/lib/steps/stubs/frontend/modal.d.ts +0 -5
- package/lib/steps/stubs/frontend/modal.js +1 -0
- package/lib/steps/stubs/frontend/model.d.ts +0 -5
- package/lib/steps/stubs/frontend/model.js +1 -0
- package/lib/steps/stubs/js-base.js +8 -5
- package/lib/steps/stubs/php-base.js +10 -8
- package/lib/steps/update/js-imports.js +8 -2
- package/lib/utils/composer.d.ts +1 -0
- package/lib/utils/migration.js +3 -1
- package/lib/utils/monorepo.d.ts +24 -0
- package/lib/utils/monorepo.js +24 -0
- package/lib/utils/validation.d.ts +2 -0
- package/lib/utils/validation.js +6 -0
- package/oclif.manifest.json +1 -1
- package/package.json +7 -3
- package/php-subsystem/composer.json +9 -9
- package/php-subsystem/composer.lock +64 -71
- package/php-subsystem/vendor/composer/installed.json +54 -61
- package/php-subsystem/vendor/nikic/php-parser/README.md +55 -59
- package/php-subsystem/vendor/nikic/php-parser/composer.json +39 -39
- package/php-subsystem/vendor/nikic/php-parser/grammar/README.md +17 -20
package/lib/boilersmith/io.js
CHANGED
|
@@ -15,7 +15,7 @@ class PromptsIO {
|
|
|
15
15
|
this.noInteraction = noInteraction;
|
|
16
16
|
this.onCancel = onCancel;
|
|
17
17
|
}
|
|
18
|
-
async getParam(paramDef) {
|
|
18
|
+
async getParam(paramDef, noCache = false) {
|
|
19
19
|
var _a, _b, _c;
|
|
20
20
|
const paramName = paramDef.name;
|
|
21
21
|
if (this.cache.has(paramName)) {
|
|
@@ -42,7 +42,9 @@ class PromptsIO {
|
|
|
42
42
|
}));
|
|
43
43
|
resValue = res[paramName];
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
if (!noCache) {
|
|
46
|
+
this.cache.set(paramName, resValue);
|
|
47
|
+
}
|
|
46
48
|
this.prev = {
|
|
47
49
|
val: resValue,
|
|
48
50
|
prompt: paramDef,
|
|
@@ -3,7 +3,7 @@ export interface Paths {
|
|
|
3
3
|
package(...path: string[]): string;
|
|
4
4
|
requestedDir(...path: string[]): string | null;
|
|
5
5
|
monorepo(...path: string[]): string | null;
|
|
6
|
-
onMonorepoSub(packagePath: string): Paths;
|
|
6
|
+
onMonorepoSub(packagePath: string, monorepoPath?: string): Paths;
|
|
7
7
|
}
|
|
8
8
|
declare type InternalPaths = {
|
|
9
9
|
package: string;
|
|
@@ -17,6 +17,6 @@ export declare class NodePaths implements Paths {
|
|
|
17
17
|
package(...path: string[]): string;
|
|
18
18
|
requestedDir(...path: string[]): string | null;
|
|
19
19
|
monorepo(...path: string[]): string | null;
|
|
20
|
-
onMonorepoSub(packagePath: string): NodePaths;
|
|
20
|
+
onMonorepoSub(packagePath: string, monorepoPath?: string): NodePaths;
|
|
21
21
|
}
|
|
22
22
|
export {};
|
package/lib/boilersmith/paths.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NodePaths = void 0;
|
|
4
|
-
const
|
|
4
|
+
const path_1 = require("path");
|
|
5
5
|
class NodePaths {
|
|
6
6
|
constructor(paths) {
|
|
7
7
|
this.paths = paths;
|
|
8
8
|
}
|
|
9
9
|
cwd(...path) {
|
|
10
|
-
return (0,
|
|
10
|
+
return (0, path_1.resolve)(process.cwd(), ...path);
|
|
11
11
|
}
|
|
12
12
|
package(...path) {
|
|
13
|
-
return (0,
|
|
13
|
+
return (0, path_1.resolve)(this.paths.package, ...path);
|
|
14
14
|
}
|
|
15
15
|
requestedDir(...path) {
|
|
16
16
|
if (!this.paths.requestedDir)
|
|
17
17
|
return null;
|
|
18
|
-
return (0,
|
|
18
|
+
return (0, path_1.resolve)(this.paths.requestedDir, ...path);
|
|
19
19
|
}
|
|
20
20
|
monorepo(...path) {
|
|
21
21
|
if (!this.paths.monorepo)
|
|
22
22
|
return null;
|
|
23
|
-
return (0,
|
|
23
|
+
return (0, path_1.resolve)(this.paths.monorepo, ...path);
|
|
24
24
|
}
|
|
25
|
-
onMonorepoSub(packagePath) {
|
|
26
|
-
return new NodePaths(Object.assign(Object.assign({}, this.paths), { monorepo: this.paths.package, package: packagePath }));
|
|
25
|
+
onMonorepoSub(packagePath, monorepoPath) {
|
|
26
|
+
return new NodePaths(Object.assign(Object.assign({}, this.paths), { monorepo: monorepoPath !== null && monorepoPath !== void 0 ? monorepoPath : this.paths.package, package: packagePath }));
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
exports.NodePaths = NodePaths;
|
|
@@ -8,7 +8,7 @@ const module_1 = require("./module");
|
|
|
8
8
|
const template_param_1 = require("./template-param");
|
|
9
9
|
const cond_format_1 = require("boilersmith/utils/cond-format");
|
|
10
10
|
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
|
|
11
|
-
const
|
|
11
|
+
const fs_1 = require("fs");
|
|
12
12
|
function auditStepFactory(dry, scaffoldDir, modules, templateParams, excludeScaffoldingFunc, moduleStatusCache) {
|
|
13
13
|
let modulesEnabled;
|
|
14
14
|
return {
|
|
@@ -17,28 +17,28 @@ function auditStepFactory(dry, scaffoldDir, modules, templateParams, excludeScaf
|
|
|
17
17
|
async run(_fs, paths, io, _providers) {
|
|
18
18
|
const paramVals = await (0, template_param_1.currParamValues)(templateParams, _fs, paths, io);
|
|
19
19
|
modulesEnabled = await (0, module_1.currModulesEnabled)(modules, _fs, paths, moduleStatusCache);
|
|
20
|
-
const actionableModules = modules.filter(m => m.updatable && modulesEnabled[m.name] && (!m.togglable || !m.dependsOn.some(dep => !modulesEnabled[dep])));
|
|
21
|
-
io.info((0, cond_format_1.condFormat)(io.supportsAnsiColor, m => chalk_1.default.yellow(chalk_1.default.bold(chalk_1.default.underline(m))), `Auditing infrastructure for ${actionableModules.length} enabled modules:`), true);
|
|
20
|
+
const actionableModules = modules.filter((m) => m.updatable && modulesEnabled[m.name] && (!m.togglable || !m.dependsOn.some((dep) => !modulesEnabled[dep])));
|
|
21
|
+
io.info((0, cond_format_1.condFormat)(io.supportsAnsiColor, (m) => chalk_1.default.yellow(chalk_1.default.bold(chalk_1.default.underline(m))), `Auditing infrastructure for ${actionableModules.length} enabled modules:`), true);
|
|
22
22
|
for (const m of modules) {
|
|
23
23
|
if (actionableModules.includes(m)) {
|
|
24
|
-
io.info((0, cond_format_1.condFormat)(io.supportsAnsiColor, m => chalk_1.default.dim(chalk_1.default.green(m)), `✓ ${m.name}: ${m.shortDescription}`), true);
|
|
24
|
+
io.info((0, cond_format_1.condFormat)(io.supportsAnsiColor, (m) => chalk_1.default.dim(chalk_1.default.green(m)), `✓ ${m.name}: ${m.shortDescription}`), true);
|
|
25
25
|
}
|
|
26
26
|
else if (m.updatable) {
|
|
27
|
-
io.info((0, cond_format_1.condFormat)(io.supportsAnsiColor, m => chalk_1.default.dim(chalk_1.default.red(m)),
|
|
27
|
+
io.info((0, cond_format_1.condFormat)(io.supportsAnsiColor, (m) => chalk_1.default.dim(chalk_1.default.red(m)), `✕ ${m.name}: ${m.shortDescription} (disabled)`), true);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
for (const m of actionableModules) {
|
|
31
31
|
const fs = dry ? (0, mem_fs_1.create)() : _fs;
|
|
32
|
-
const excludeScaffolding = excludeScaffoldingFunc ? excludeScaffoldingFunc(fs, paths) : [];
|
|
32
|
+
const excludeScaffolding = excludeScaffoldingFunc ? excludeScaffoldingFunc(fs, paths) : { files: [], configKeys: {} };
|
|
33
33
|
(0, module_1.applyModule)(m, modulesEnabled, paramVals, scaffoldDir, fs, paths, excludeScaffolding, true);
|
|
34
34
|
if (dry) {
|
|
35
35
|
const filesWithChanges = fs
|
|
36
36
|
.all()
|
|
37
|
-
.filter(f => f.state && f.state !== 'deleted')
|
|
38
|
-
.filter(f => { var _a; return !(0,
|
|
37
|
+
.filter((f) => f.state && f.state !== 'deleted')
|
|
38
|
+
.filter((f) => { var _a; return !(0, fs_1.existsSync)(f.path) || (0, fs_1.readFileSync)(f.path, 'utf8').toString() !== ((_a = f.contents) === null || _a === void 0 ? void 0 : _a.toString()); });
|
|
39
39
|
if (filesWithChanges.length > 0) {
|
|
40
40
|
io.error(`Module ${m.name} has ${filesWithChanges.length} changed files: ${filesWithChanges
|
|
41
|
-
.map(f => f.path.replace(paths.package() + '/', ''))
|
|
41
|
+
.map((f) => f.path.replace(paths.package() + '/', ''))
|
|
42
42
|
.join(', ')}`, false);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -52,9 +52,9 @@ function auditStepFactory(dry, scaffoldDir, modules, templateParams, excludeScaf
|
|
|
52
52
|
}
|
|
53
53
|
return _fs;
|
|
54
54
|
},
|
|
55
|
-
exposes: modules.map(m => `modules.${m.name}`),
|
|
55
|
+
exposes: modules.map((m) => `modules.${m.name}`),
|
|
56
56
|
getExposed(_paths, _paramProvider) {
|
|
57
|
-
return (0, rename_keys_1.renameKeys)(modulesEnabled, k => `modules.${k}`);
|
|
57
|
+
return (0, rename_keys_1.renameKeys)(modulesEnabled, (k) => `modules.${k}`);
|
|
58
58
|
},
|
|
59
59
|
};
|
|
60
60
|
}
|
|
@@ -4,7 +4,7 @@ exports.infraStepFactory = void 0;
|
|
|
4
4
|
const module_1 = require("./module");
|
|
5
5
|
const template_param_1 = require("./template-param");
|
|
6
6
|
function infraStepFactory(scaffoldDir, moduleName, modules, templateParams, excludeScaffoldingFunc, moduleStatusCache) {
|
|
7
|
-
const module = modules.find(m => m.name === moduleName);
|
|
7
|
+
const module = modules.find((m) => m.name === moduleName);
|
|
8
8
|
if (!module) {
|
|
9
9
|
throw new Error(`Module ${moduleName} not found`);
|
|
10
10
|
}
|
|
@@ -17,7 +17,7 @@ function infraStepFactory(scaffoldDir, moduleName, modules, templateParams, excl
|
|
|
17
17
|
if (!module.updatable) {
|
|
18
18
|
io.error(`${module.name} is not updatable.`, true);
|
|
19
19
|
}
|
|
20
|
-
const excludeScaffolding = excludeScaffoldingFunc ? excludeScaffoldingFunc(fs, paths) : [];
|
|
20
|
+
const excludeScaffolding = excludeScaffoldingFunc ? excludeScaffoldingFunc(fs, paths) : { files: [], configKeys: {} };
|
|
21
21
|
const initializing = !modulesEnabled[module.name];
|
|
22
22
|
(0, module_1.applyModule)(module, Object.assign(Object.assign({}, modulesEnabled), { [module.name]: true }), paramVals, scaffoldDir, fs, paths, excludeScaffolding, initializing);
|
|
23
23
|
if (moduleStatusCache) {
|
|
@@ -12,22 +12,22 @@ function initStepFactory(scaffoldDir, modules, templateParams, excludeScaffoldin
|
|
|
12
12
|
async run(fs, paths, io, _providers) {
|
|
13
13
|
const paramVals = await (0, template_param_1.promptParamValues)(templateParams, paths, io);
|
|
14
14
|
modulesEnabled = await (0, module_1.promptModulesEnabled)(modules, io);
|
|
15
|
-
const excludeScaffolding = excludeScaffoldingFunc ? excludeScaffoldingFunc(fs, paths) : [];
|
|
15
|
+
const excludeScaffolding = excludeScaffoldingFunc ? excludeScaffoldingFunc(fs, paths) : { files: [], configKeys: {} };
|
|
16
16
|
for (const m of modules) {
|
|
17
|
-
if (modulesEnabled[m.name] && (!m.togglable || !m.dependsOn.some(dep => !modulesEnabled[dep]))) {
|
|
17
|
+
if (modulesEnabled[m.name] && (!m.togglable || !m.dependsOn.some((dep) => !modulesEnabled[dep]))) {
|
|
18
18
|
(0, module_1.applyModule)(m, modulesEnabled, paramVals, scaffoldDir, fs, paths, excludeScaffolding, true);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
if (moduleStatusCache) {
|
|
22
|
-
modules.forEach(m => {
|
|
22
|
+
modules.forEach((m) => {
|
|
23
23
|
(0, module_1.setModuleValue)(m, modulesEnabled[m.name], fs, paths, moduleStatusCache);
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
return fs;
|
|
27
27
|
},
|
|
28
|
-
exposes: modules.map(m => `modules.${m.name}`),
|
|
28
|
+
exposes: modules.map((m) => `modules.${m.name}`),
|
|
29
29
|
getExposed(_paths, _paramProvider) {
|
|
30
|
-
return (0, rename_keys_1.renameKeys)(modulesEnabled, k => `modules.${k}`);
|
|
30
|
+
return (0, rename_keys_1.renameKeys)(modulesEnabled, (k) => `modules.${k}`);
|
|
31
31
|
},
|
|
32
32
|
};
|
|
33
33
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Store } from 'mem-fs';
|
|
2
2
|
import { IO } from 'boilersmith/io';
|
|
3
3
|
import { Paths } from 'boilersmith/paths';
|
|
4
|
-
|
|
4
|
+
import { ExcludeScaffoldingFunc } from './scaffolder';
|
|
5
|
+
declare type FileOwnershipCommon<N extends string> = {
|
|
5
6
|
/**
|
|
6
7
|
* The path to the file
|
|
7
8
|
*/
|
|
@@ -13,16 +14,26 @@ interface FileOwnership {
|
|
|
13
14
|
/**
|
|
14
15
|
* Depends on other modules being enabled (or disabled).
|
|
15
16
|
*/
|
|
16
|
-
moduleDeps?: (
|
|
17
|
-
module:
|
|
17
|
+
moduleDeps?: (N | {
|
|
18
|
+
module: N;
|
|
18
19
|
enabled: boolean;
|
|
19
20
|
})[];
|
|
21
|
+
/**
|
|
22
|
+
* Only create the file if it doesn't exist; do not update existing files.
|
|
23
|
+
*/
|
|
24
|
+
doNotUpdate?: boolean;
|
|
25
|
+
};
|
|
26
|
+
declare type FileOwnership<N extends string> = (FileOwnershipCommon<N> & {
|
|
20
27
|
/**
|
|
21
28
|
* If in a monorepo, should the file be placed relative to the monorepo root, and if so, where?
|
|
22
29
|
* If provided, takes priority over destPath.
|
|
23
30
|
*/
|
|
24
|
-
monorepoPath
|
|
25
|
-
|
|
31
|
+
monorepoPath: string;
|
|
32
|
+
/**
|
|
33
|
+
* Only place this file if in a monorepo?
|
|
34
|
+
*/
|
|
35
|
+
requireMonorepo: boolean;
|
|
36
|
+
}) | FileOwnershipCommon<N>;
|
|
26
37
|
interface CommonModule<N extends string> {
|
|
27
38
|
name: N;
|
|
28
39
|
shortDescription: string;
|
|
@@ -34,7 +45,7 @@ interface CommonModule<N extends string> {
|
|
|
34
45
|
/**
|
|
35
46
|
* A list of scaffolding files managed by this module.
|
|
36
47
|
*/
|
|
37
|
-
filesToReplace: (string | FileOwnership)[];
|
|
48
|
+
filesToReplace: (string | FileOwnership<N>)[];
|
|
38
49
|
/**
|
|
39
50
|
* A map of names of JSON files to keys which should be deep-merged from the scaffolding.
|
|
40
51
|
*/
|
|
@@ -62,7 +73,7 @@ interface TogglableModule<N extends string> extends CommonModule<N> {
|
|
|
62
73
|
/**
|
|
63
74
|
* Can only be enabled if these other modules are enabled.
|
|
64
75
|
*/
|
|
65
|
-
dependsOn:
|
|
76
|
+
dependsOn: N[];
|
|
66
77
|
/**
|
|
67
78
|
* On an existing installation, if no information about whether this
|
|
68
79
|
* module is enabled or disabled is cached, infer whether it's enabled
|
|
@@ -78,5 +89,5 @@ export declare type ModuleStatusCache<N extends string> = {
|
|
|
78
89
|
export declare function promptModulesEnabled<N extends string>(modules: Module<N>[], io: IO): Promise<Record<N, boolean>>;
|
|
79
90
|
export declare function currModulesEnabled<N extends string>(modules: Module<N>[], fs: Store, paths: Paths, cache?: ModuleStatusCache<N>): Promise<Record<N, boolean>>;
|
|
80
91
|
export declare function setModuleValue<MN extends string>(module: Module<MN>, enabled: boolean, fs: Store, paths: Paths, cache: ModuleStatusCache<MN>): Promise<void>;
|
|
81
|
-
export declare function applyModule<MN extends string, TN extends string>(module: Module<MN>, modulesEnabled: Record<string, boolean>, paramVals: Record<TN, unknown>, scaffoldDir: string, fs: Store, paths: Paths,
|
|
92
|
+
export declare function applyModule<MN extends string, TN extends string>(module: Module<MN>, modulesEnabled: Record<string, boolean>, paramVals: Record<TN, unknown>, scaffoldDir: string, fs: Store, paths: Paths, excludeScaffolding?: ReturnType<ExcludeScaffoldingFunc>, isInitial?: boolean): Promise<Store>;
|
|
82
93
|
export {};
|
|
@@ -4,7 +4,7 @@ exports.applyModule = exports.setModuleValue = exports.currModulesEnabled = expo
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
|
|
6
6
|
const mem_fs_editor_1 = require("mem-fs-editor");
|
|
7
|
-
const
|
|
7
|
+
const path_1 = require("path");
|
|
8
8
|
const pick_deep_1 = (0, tslib_1.__importDefault)(require("pick-deep"));
|
|
9
9
|
const read_tpl_1 = require("boilersmith/utils/read-tpl");
|
|
10
10
|
const clone_and_fill_1 = require("boilersmith/utils/clone-and-fill");
|
|
@@ -19,7 +19,7 @@ async function promptModulesEnabled(modules, io) {
|
|
|
19
19
|
message: `Advanced Initialization ${(0, cond_format_1.condFormat)(io.supportsAnsiColor, chalk_1.default.dim, '(fine-tune which features are enabled)')}`,
|
|
20
20
|
});
|
|
21
21
|
for (const m of modules) {
|
|
22
|
-
const missingDeps = !m.togglable || m.dependsOn.some(dep => !modulesEnabled[dep]);
|
|
22
|
+
const missingDeps = !m.togglable || m.dependsOn.some((dep) => !modulesEnabled[dep]);
|
|
23
23
|
if (!m.togglable) {
|
|
24
24
|
modulesEnabled[m.name] = true;
|
|
25
25
|
}
|
|
@@ -48,7 +48,7 @@ async function currModulesEnabled(modules, fs, paths, cache) {
|
|
|
48
48
|
for (const m of modules) {
|
|
49
49
|
if (m.togglable) {
|
|
50
50
|
// eslint-disable-next-line no-await-in-loop
|
|
51
|
-
const isEnabled = (_a = await (cache === null || cache === void 0 ? void 0 : cache.get(m, fs, paths))) !== null && _a !== void 0 ? _a : await ((_b = m.inferEnabled) === null || _b === void 0 ? void 0 : _b.call(m, fs, paths));
|
|
51
|
+
const isEnabled = (_a = (await (cache === null || cache === void 0 ? void 0 : cache.get(m, fs, paths)))) !== null && _a !== void 0 ? _a : (await ((_b = m.inferEnabled) === null || _b === void 0 ? void 0 : _b.call(m, fs, paths)));
|
|
52
52
|
modulesEnabled[m.name] = isEnabled !== null && isEnabled !== void 0 ? isEnabled : m.defaultEnabled;
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
@@ -64,21 +64,23 @@ async function setModuleValue(module, enabled, fs, paths, cache) {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
exports.setModuleValue = setModuleValue;
|
|
67
|
-
// eslint-disable-next-line max-params
|
|
68
|
-
async function applyModule(module, modulesEnabled, paramVals, scaffoldDir, fs, paths,
|
|
69
|
-
|
|
67
|
+
// eslint-disable-next-line max-params,complexity
|
|
68
|
+
async function applyModule(module, modulesEnabled, paramVals, scaffoldDir, fs, paths,
|
|
69
|
+
// eslint-disable-next-line unicorn/no-object-as-default-parameter
|
|
70
|
+
excludeScaffolding = { files: [], configKeys: {} }, isInitial = false) {
|
|
71
|
+
var _a, _b;
|
|
70
72
|
const fsEditor = (0, mem_fs_editor_1.create)(fs);
|
|
71
73
|
// Validate that module can be enabled
|
|
72
74
|
if (!(modulesEnabled === null || modulesEnabled === void 0 ? void 0 : modulesEnabled[module.name])) {
|
|
73
75
|
throw new Error(`Could not apply module "${module.name}", because it is not enabled in the provided module statuses.`);
|
|
74
76
|
}
|
|
75
77
|
// Validate that dependencies are enabled
|
|
76
|
-
const missingDeps = module.togglable ? module.dependsOn.filter(dep => !modulesEnabled[dep]) : [];
|
|
78
|
+
const missingDeps = module.togglable ? module.dependsOn.filter((dep) => !modulesEnabled[dep]) : [];
|
|
77
79
|
if (missingDeps.length > 0) {
|
|
78
80
|
throw new Error(`Could not apply module "${module.name}", because the following dependency modules are missing: "${missingDeps.join(', ')}".`);
|
|
79
81
|
}
|
|
80
82
|
// Validate that all needed params are present
|
|
81
|
-
const missingParams = module.needsTemplateParams.filter(p => !(p in paramVals));
|
|
83
|
+
const missingParams = module.needsTemplateParams.filter((p) => !(p in paramVals));
|
|
82
84
|
if (missingParams.length > 0) {
|
|
83
85
|
throw new Error(`Could not apply module "${module.name}", because the following params are missing: "${missingParams.join(', ')}".`);
|
|
84
86
|
}
|
|
@@ -89,28 +91,63 @@ async function applyModule(module, modulesEnabled, paramVals, scaffoldDir, fs, p
|
|
|
89
91
|
params: paramVals,
|
|
90
92
|
modules: modulesEnabled,
|
|
91
93
|
};
|
|
92
|
-
const tplDataFlat = Object.assign(Object.assign({}, (0, rename_keys_1.renameKeys)(tplData.modules, k => `modules.${k}`)), (0, rename_keys_1.renameKeys)(tplData.params, k => `params.${k}`));
|
|
94
|
+
const tplDataFlat = Object.assign(Object.assign({}, (0, rename_keys_1.renameKeys)(tplData.modules, (k) => `modules.${k}`)), (0, rename_keys_1.renameKeys)(tplData.params, (k) => `params.${k}`));
|
|
95
|
+
// This is necessary because one layer of escaped backslashes is lost on template population.
|
|
96
|
+
tplData.params = Object.fromEntries(Object.entries(paramVals).map(([k, v]) => [k, typeof v === 'string' ? v.replace('\\', '\\\\') : v]));
|
|
93
97
|
for (const file of module.filesToReplace) {
|
|
94
98
|
const path = typeof file === 'string' ? file : file.path;
|
|
95
99
|
const moduleDeps = typeof file === 'string' ? [] : (_a = file.moduleDeps) !== null && _a !== void 0 ? _a : [];
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
const copyToIfMonorepo = typeof file !== 'string' && 'monorepoPath' in file && file.monorepoPath
|
|
101
|
+
? paths.monorepo((0, clone_and_fill_1.cloneAndFill)(file.monorepoPath, tplDataFlat))
|
|
102
|
+
: undefined;
|
|
103
|
+
const copyTo = copyToIfMonorepo !== null && copyToIfMonorepo !== void 0 ? copyToIfMonorepo : paths.package(typeof file !== 'string' && file.destPath ? (0, clone_and_fill_1.cloneAndFill)(file.destPath, tplDataFlat) : path);
|
|
104
|
+
if (typeof file !== 'string' && file.doNotUpdate && fsEditor.exists(copyTo)) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (typeof file !== 'string' && 'requireMonorepo' in file && file.requireMonorepo && paths.monorepo() === null) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (excludeScaffolding.files.includes(path) ||
|
|
111
|
+
moduleDeps.some((dep) => {
|
|
112
|
+
const depName = typeof dep === 'string' ? dep : dep.module;
|
|
113
|
+
const enabled = modulesEnabled[depName];
|
|
114
|
+
return typeof dep === 'string' || dep.enabled ? !enabled : enabled;
|
|
115
|
+
})) {
|
|
116
|
+
continue;
|
|
104
117
|
}
|
|
118
|
+
let source = (0, read_tpl_1.readTpl)((0, path_1.resolve)(scaffoldDir, path), tplData);
|
|
119
|
+
if (fsEditor.exists(copyTo)) {
|
|
120
|
+
source = applyCustomizations(source, fsEditor.read(copyTo));
|
|
121
|
+
}
|
|
122
|
+
fsEditor.write(copyTo, source);
|
|
105
123
|
}
|
|
106
124
|
const jsonPaths = (0, clone_and_fill_1.cloneAndFill)(module.jsonToAugment, tplDataFlat);
|
|
107
125
|
for (const jsonPath of Object.keys(jsonPaths)) {
|
|
108
|
-
const scaffoldContents = (0, read_tpl_1.readTpl)((0,
|
|
126
|
+
const scaffoldContents = (0, read_tpl_1.readTpl)((0, path_1.resolve)(scaffoldDir, jsonPath), tplData);
|
|
109
127
|
const scaffoldContentsJson = JSON.parse(scaffoldContents);
|
|
110
|
-
const
|
|
128
|
+
const excludeKeys = (0, clone_and_fill_1.cloneAndFill)((_b = excludeScaffolding.configKeys[jsonPath]) !== null && _b !== void 0 ? _b : [], tplDataFlat);
|
|
129
|
+
const fieldsToAugment = jsonPaths[jsonPath].filter((key) => !excludeKeys.includes(key));
|
|
111
130
|
const relevant = (0, pick_deep_1.default)(scaffoldContentsJson, fieldsToAugment);
|
|
112
131
|
fsEditor.extendJSON(paths.package(jsonPath), relevant, undefined, 4);
|
|
113
132
|
}
|
|
114
133
|
return fs;
|
|
115
134
|
}
|
|
116
135
|
exports.applyModule = applyModule;
|
|
136
|
+
function applyCustomizations(source, curr) {
|
|
137
|
+
const commentStructures = [
|
|
138
|
+
['//', '\n'],
|
|
139
|
+
['/*', ' */'],
|
|
140
|
+
['<!--', '-->'],
|
|
141
|
+
['#', '\n'],
|
|
142
|
+
];
|
|
143
|
+
commentStructures.forEach((x) => x);
|
|
144
|
+
return commentStructures.reduce((acc, [start, end]) => {
|
|
145
|
+
const CUSTOMIZATION_REGEX = new RegExp(`(${start}\\s*<CUSTOM-(?<id>.*)>\\s*${end})(?<contents>.*)(${start}\\s*</CUSTOM-\\k<id>>\\s*${end})`, 'gs');
|
|
146
|
+
const matches = curr.matchAll(CUSTOMIZATION_REGEX);
|
|
147
|
+
const customizations = Object.fromEntries([...matches]
|
|
148
|
+
.map((m) => m.groups)
|
|
149
|
+
.filter(Boolean)
|
|
150
|
+
.map((g) => [g === null || g === void 0 ? void 0 : g.id, g === null || g === void 0 ? void 0 : g.contents]));
|
|
151
|
+
return acc.replace(CUSTOMIZATION_REGEX, (_m, open, id, _c, close) => { var _a; return `${open}${(_a = customizations[id]) !== null && _a !== void 0 ? _a : ''}${close}`; });
|
|
152
|
+
}, source);
|
|
153
|
+
}
|
|
@@ -4,7 +4,10 @@ import { DefaultProviders, Step } from '../step-manager';
|
|
|
4
4
|
import { Module, ModuleStatusCache } from './module';
|
|
5
5
|
import { TemplateParam } from './template-param';
|
|
6
6
|
import { IO } from 'boilersmith/io';
|
|
7
|
-
export declare type ExcludeScaffoldingFunc = (fs: Store, paths: Paths) =>
|
|
7
|
+
export declare type ExcludeScaffoldingFunc = (fs: Store, paths: Paths) => {
|
|
8
|
+
files: string[];
|
|
9
|
+
configKeys: Record<string, string[]>;
|
|
10
|
+
};
|
|
8
11
|
export declare class Scaffolder<TN extends string = string, MN extends string = string> {
|
|
9
12
|
private templateParams;
|
|
10
13
|
private modules;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Scaffolder = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const globby_1 = (0, tslib_1.__importDefault)(require("globby"));
|
|
6
|
-
const
|
|
6
|
+
const path_1 = require("path");
|
|
7
7
|
const json_leaf_paths_1 = require("boilersmith/utils/json-leaf-paths");
|
|
8
8
|
const read_tpl_1 = require("boilersmith/utils/read-tpl");
|
|
9
9
|
const init_step_factory_1 = require("./init-step-factory");
|
|
@@ -27,8 +27,8 @@ class Scaffolder {
|
|
|
27
27
|
}
|
|
28
28
|
registerTemplateParam(templateParam) {
|
|
29
29
|
if ((0, template_param_1.isComputedParam)(templateParam)) {
|
|
30
|
-
const currParams = new Set(this.templateParams.map(p => (0, template_param_1.getParamName)(p)));
|
|
31
|
-
const missingDeps = templateParam.uses.filter(dep => !currParams.has(dep));
|
|
30
|
+
const currParams = new Set(this.templateParams.map((p) => (0, template_param_1.getParamName)(p)));
|
|
31
|
+
const missingDeps = templateParam.uses.filter((dep) => !currParams.has(dep));
|
|
32
32
|
if (missingDeps.length > 0) {
|
|
33
33
|
throw new Error(`Computed template param "${(0, template_param_1.getParamName)(templateParam)}" is missing dependency params: "${missingDeps.join(', ')}".`);
|
|
34
34
|
}
|
|
@@ -56,7 +56,7 @@ class Scaffolder {
|
|
|
56
56
|
}
|
|
57
57
|
moduleFiles(moduleName) {
|
|
58
58
|
var _a, _b;
|
|
59
|
-
return (_b = (_a = this.modules.find(m => m.name === moduleName)) === null || _a === void 0 ? void 0 : _a.filesToReplace.map(f => typeof f === 'string' ? f : f.path)) !== null && _b !== void 0 ? _b : [];
|
|
59
|
+
return (_b = (_a = this.modules.find((m) => m.name === moduleName)) === null || _a === void 0 ? void 0 : _a.filesToReplace.map((f) => (typeof f === 'string' ? f : f.path))) !== null && _b !== void 0 ? _b : [];
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
62
|
* Confirm that all files and configuration keys in the scaffolding dir
|
|
@@ -66,13 +66,13 @@ class Scaffolder {
|
|
|
66
66
|
async validate() {
|
|
67
67
|
const errors = [];
|
|
68
68
|
// Generate template data for future checks
|
|
69
|
-
const paramVals = Object.fromEntries(this.templateParams.map(param => [(0, template_param_1.getParamName)(param), 'TEST']));
|
|
70
|
-
const modulesEnabled = Object.fromEntries(this.modules.map(module => [module.name, true]));
|
|
69
|
+
const paramVals = Object.fromEntries(this.templateParams.map((param) => [(0, template_param_1.getParamName)(param), 'TEST']));
|
|
70
|
+
const modulesEnabled = Object.fromEntries(this.modules.map((module) => [module.name, true]));
|
|
71
71
|
const tplData = { params: paramVals, modules: modulesEnabled };
|
|
72
|
-
const tplDataFlat = Object.assign(Object.assign({}, (0, rename_keys_1.renameKeys)(tplData.modules, k => `modules.${k}`)), (0, rename_keys_1.renameKeys)(tplData.params, k => `params.${k}`));
|
|
73
|
-
const moduleNames = new Set(this.modules.map(m => m.name));
|
|
72
|
+
const tplDataFlat = Object.assign(Object.assign({}, (0, rename_keys_1.renameKeys)(tplData.modules, (k) => `modules.${k}`)), (0, rename_keys_1.renameKeys)(tplData.params, (k) => `params.${k}`));
|
|
73
|
+
const moduleNames = new Set(this.modules.map((m) => m.name));
|
|
74
74
|
for (const module of this.modules) {
|
|
75
|
-
const missingDeps = module.togglable ? module.dependsOn.filter(dep => !moduleNames.has(dep)) : [];
|
|
75
|
+
const missingDeps = module.togglable ? module.dependsOn.filter((dep) => !moduleNames.has(dep)) : [];
|
|
76
76
|
if (missingDeps.length > 0) {
|
|
77
77
|
errors.push(`Module "${module.name}" depends on modules that are not registered: "${missingDeps.join(', ')}".`);
|
|
78
78
|
}
|
|
@@ -81,23 +81,23 @@ class Scaffolder {
|
|
|
81
81
|
const configKeysToOwnerModules = new Map();
|
|
82
82
|
const templateParamsToUsingModules = new Map();
|
|
83
83
|
for (const module of this.modules) {
|
|
84
|
-
module.filesToReplace.forEach(file => {
|
|
84
|
+
module.filesToReplace.forEach((file) => {
|
|
85
85
|
var _a;
|
|
86
86
|
const path = typeof file === 'string' ? file : file.path;
|
|
87
87
|
const currModules = (_a = filesToOwnerModules.get(path)) !== null && _a !== void 0 ? _a : [];
|
|
88
88
|
filesToOwnerModules.set(path, [...currModules, module.name]);
|
|
89
89
|
});
|
|
90
|
-
module.needsTemplateParams.forEach(paramName => {
|
|
90
|
+
module.needsTemplateParams.forEach((paramName) => {
|
|
91
91
|
var _a;
|
|
92
92
|
const currModules = (_a = filesToOwnerModules.get(paramName)) !== null && _a !== void 0 ? _a : [];
|
|
93
93
|
templateParamsToUsingModules.set(paramName, [...currModules, module.name]);
|
|
94
94
|
});
|
|
95
|
-
Object.keys(module.jsonToAugment).forEach(jsonPath => {
|
|
95
|
+
Object.keys(module.jsonToAugment).forEach((jsonPath) => {
|
|
96
96
|
var _a;
|
|
97
97
|
const ownedKeys = (0, clone_and_fill_1.cloneAndFill)(module.jsonToAugment, tplDataFlat)[jsonPath];
|
|
98
98
|
const currJsonData = (_a = configKeysToOwnerModules.get(jsonPath)) !== null && _a !== void 0 ? _a : { fileOwners: [], keyOwners: new Map() };
|
|
99
99
|
currJsonData.fileOwners.push(module.name);
|
|
100
|
-
ownedKeys.forEach(key => {
|
|
100
|
+
ownedKeys.forEach((key) => {
|
|
101
101
|
var _a;
|
|
102
102
|
const currModules = (_a = currJsonData.keyOwners.get(key)) !== null && _a !== void 0 ? _a : [];
|
|
103
103
|
currJsonData.keyOwners.set(key, [...currModules, module.name]);
|
|
@@ -109,46 +109,46 @@ class Scaffolder {
|
|
|
109
109
|
const moduleOwnedFiles = [...filesToOwnerModules.keys()];
|
|
110
110
|
const moduleOwnedJsonConfs = new Set(configKeysToOwnerModules.keys());
|
|
111
111
|
moduleOwnedFiles
|
|
112
|
-
.filter(path => moduleOwnedJsonConfs.has(path))
|
|
113
|
-
.forEach(path => {
|
|
112
|
+
.filter((path) => moduleOwnedJsonConfs.has(path))
|
|
113
|
+
.forEach((path) => {
|
|
114
114
|
var _a, _b;
|
|
115
115
|
const fileModules = (_a = filesToOwnerModules.get(path)) === null || _a === void 0 ? void 0 : _a.join(', ');
|
|
116
116
|
const keyModules = (_b = configKeysToOwnerModules.get(path)) === null || _b === void 0 ? void 0 : _b.fileOwners.join(', ');
|
|
117
117
|
errors.push(`File "${path}" is owned by modules: "${fileModules}". However, it also has keys that are owned by modules: "${keyModules}".`);
|
|
118
118
|
});
|
|
119
119
|
// Ensure that all owned files exist in the filesystem.
|
|
120
|
-
const scaffoldingFilePaths = new Set((await (0, globby_1.default)((0,
|
|
120
|
+
const scaffoldingFilePaths = new Set((await (0, globby_1.default)((0, path_1.resolve)(this.scaffoldDir, '**/*'), { dot: true })).map((p) => p.replace(`${this.scaffoldDir}/`, '')).filter((p) => p !== ''));
|
|
121
121
|
moduleOwnedFiles
|
|
122
|
-
.filter(path => !scaffoldingFilePaths.has(path))
|
|
123
|
-
.forEach(path => {
|
|
122
|
+
.filter((path) => !scaffoldingFilePaths.has(path))
|
|
123
|
+
.forEach((path) => {
|
|
124
124
|
var _a;
|
|
125
125
|
const fileModules = (_a = filesToOwnerModules.get(path)) === null || _a === void 0 ? void 0 : _a.join(', ');
|
|
126
126
|
errors.push(`File "${path}" is owned by modules: "${fileModules}", but it doesn't exist in the scaffolding directory.`);
|
|
127
127
|
});
|
|
128
128
|
[...moduleOwnedJsonConfs]
|
|
129
|
-
.filter(path => !scaffoldingFilePaths.has(path))
|
|
130
|
-
.forEach(path => {
|
|
129
|
+
.filter((path) => !scaffoldingFilePaths.has(path))
|
|
130
|
+
.forEach((path) => {
|
|
131
131
|
var _a;
|
|
132
132
|
const keyModules = (_a = configKeysToOwnerModules.get(path)) === null || _a === void 0 ? void 0 : _a.fileOwners.join(', ');
|
|
133
133
|
errors.push(`File "${path}" has keys owned by modules: "${keyModules}", but it doesn't exist in the scaffolding directory.`);
|
|
134
134
|
});
|
|
135
135
|
// Ensure that all files in the filesystem are owned by at least one module.
|
|
136
136
|
[...scaffoldingFilePaths]
|
|
137
|
-
.filter(path => !filesToOwnerModules.has(path) && !configKeysToOwnerModules.has(path))
|
|
138
|
-
.forEach(path => {
|
|
137
|
+
.filter((path) => !filesToOwnerModules.has(path) && !configKeysToOwnerModules.has(path))
|
|
138
|
+
.forEach((path) => {
|
|
139
139
|
errors.push(`File "${path}" is not owned by any module.`);
|
|
140
140
|
});
|
|
141
141
|
// Ensure that every template param is used by at least one module.
|
|
142
142
|
this.templateParams
|
|
143
|
-
.filter(p => !templateParamsToUsingModules.has((0, template_param_1.getParamName)(p)))
|
|
144
|
-
.forEach(p => {
|
|
143
|
+
.filter((p) => !templateParamsToUsingModules.has((0, template_param_1.getParamName)(p)))
|
|
144
|
+
.forEach((p) => {
|
|
145
145
|
errors.push(`Template param "${(0, template_param_1.getParamName)(p)}" is defined, but not used by any modules.`);
|
|
146
146
|
});
|
|
147
147
|
// Ensure that every module's needed template params are provided.
|
|
148
|
-
const providedParams = new Set(this.templateParams.map(p => (0, template_param_1.getParamName)(p)));
|
|
148
|
+
const providedParams = new Set(this.templateParams.map((p) => (0, template_param_1.getParamName)(p)));
|
|
149
149
|
[...templateParamsToUsingModules.keys()]
|
|
150
|
-
.filter(paramName => !providedParams.has(paramName))
|
|
151
|
-
.forEach(paramName => {
|
|
150
|
+
.filter((paramName) => !providedParams.has(paramName))
|
|
151
|
+
.forEach((paramName) => {
|
|
152
152
|
var _a;
|
|
153
153
|
const paramModules = (_a = templateParamsToUsingModules.get(paramName)) === null || _a === void 0 ? void 0 : _a.join(', ');
|
|
154
154
|
errors.push(`Template param "${paramName}" is used by modules: "${paramModules}", but is not provided.`);
|
|
@@ -164,14 +164,14 @@ class Scaffolder {
|
|
|
164
164
|
if (errors.length > 0) {
|
|
165
165
|
throw new Error(errors.join('\n'));
|
|
166
166
|
}
|
|
167
|
-
const contents = (0, read_tpl_1.readTpl)((0,
|
|
167
|
+
const contents = (0, read_tpl_1.readTpl)((0, path_1.resolve)(this.scaffoldDir, path), tplData);
|
|
168
168
|
let json;
|
|
169
169
|
try {
|
|
170
170
|
json = JSON.parse(contents);
|
|
171
171
|
const keys = new Set((0, json_leaf_paths_1.jsonLeafPaths)(json));
|
|
172
172
|
[...keys]
|
|
173
|
-
.filter(k => !ownerData.keyOwners.has(k))
|
|
174
|
-
.forEach(k => {
|
|
173
|
+
.filter((k) => !ownerData.keyOwners.has(k))
|
|
174
|
+
.forEach((k) => {
|
|
175
175
|
errors.push(`Key "${k}" in file "${path}" is not owned by any module.`);
|
|
176
176
|
});
|
|
177
177
|
[...ownerData.keyOwners.entries()]
|
|
@@ -195,8 +195,8 @@ class Scaffolder {
|
|
|
195
195
|
throw new Error(errors.join('\n'));
|
|
196
196
|
}
|
|
197
197
|
// Ensure that all files can be resolved with ejs using provided template variables.
|
|
198
|
-
scaffoldingFilePaths.forEach(path => {
|
|
199
|
-
(0, read_tpl_1.readTpl)((0,
|
|
198
|
+
scaffoldingFilePaths.forEach((path) => {
|
|
199
|
+
(0, read_tpl_1.readTpl)((0, path_1.resolve)(this.scaffoldDir, path), tplData);
|
|
200
200
|
});
|
|
201
201
|
}
|
|
202
202
|
}
|
|
@@ -11,7 +11,7 @@ interface PromptTemplateParam<T, N extends string = string> {
|
|
|
11
11
|
}
|
|
12
12
|
interface ComputedTemplateParam<T, N extends string = string> {
|
|
13
13
|
name: N;
|
|
14
|
-
uses:
|
|
14
|
+
uses: N[];
|
|
15
15
|
compute: (paths: Paths, ...args: any[]) => Promise<T>;
|
|
16
16
|
}
|
|
17
17
|
export declare type TemplateParam<T = unknown, N extends string = string> = PromptTemplateParam<T, N> | ComputedTemplateParam<T, N>;
|
|
@@ -17,7 +17,7 @@ async function withComputedParamValues(params, paths, paramVals) {
|
|
|
17
17
|
const vals = Object.assign({}, paramVals);
|
|
18
18
|
const computedParams = params.filter(isComputedParam);
|
|
19
19
|
for (const p of computedParams) {
|
|
20
|
-
const depValues = p.uses.map(key => vals[key]);
|
|
20
|
+
const depValues = p.uses.map((key) => vals[key]);
|
|
21
21
|
// eslint-disable-next-line no-await-in-loop
|
|
22
22
|
vals[p.name] = await p.compute(paths, ...depValues);
|
|
23
23
|
}
|
|
@@ -39,7 +39,7 @@ async function currParamValues(params, fs, paths, io) {
|
|
|
39
39
|
const paramVals = {};
|
|
40
40
|
for (const p of promptParams) {
|
|
41
41
|
// eslint-disable-next-line no-await-in-loop
|
|
42
|
-
paramVals[p.prompt.name] = (_a = await p.getCurrVal(fs, paths)) !== null && _a !== void 0 ? _a : await io.getParam(p.prompt);
|
|
42
|
+
paramVals[p.prompt.name] = (_a = (await p.getCurrVal(fs, paths))) !== null && _a !== void 0 ? _a : (await io.getParam(p.prompt));
|
|
43
43
|
}
|
|
44
44
|
return withComputedParamValues(params, paths, paramVals);
|
|
45
45
|
}
|
|
@@ -72,7 +72,6 @@ export declare class StepManager<Providers extends DefaultProviders> {
|
|
|
72
72
|
run(paths: Paths, io: IO, providers: Providers, dry?: boolean): Promise<StepsResult>;
|
|
73
73
|
protected stepShouldRun(storedStep: StoredStep<Providers>, io: IO, packagePath?: string): Promise<boolean>;
|
|
74
74
|
protected runStep(storedStep: StoredStep<Providers>, paths: Paths, io: IO, providers: Providers, packagePath?: string, fs?: Store): Promise<Store>;
|
|
75
|
-
protected commit(fs: Store): Promise<boolean>;
|
|
76
75
|
}
|
|
77
76
|
export declare class AtomicStepManager<Providers = DefaultProviders> extends StepManager<Providers> {
|
|
78
77
|
protected steps: StoredStep<Providers>[];
|