@backstage/cli 0.30.0-next.1 → 0.30.0-next.3
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/CHANGELOG.md +54 -0
- package/config/jestSwcTransform.js +1 -1
- package/dist/commands/index.cjs.js +3 -0
- package/dist/commands/new/new.cjs.js +39 -80
- package/dist/commands/versions/bump.cjs.js +2 -0
- package/dist/lib/builder/plugins.cjs.js +20 -1
- package/dist/lib/new/createNewPackage.cjs.js +32 -0
- package/dist/lib/new/defaultTemplates.cjs.js +16 -0
- package/dist/lib/new/execution/PortableTemplater.cjs.js +91 -0
- package/dist/lib/new/execution/executePortableTemplate.cjs.js +54 -0
- package/dist/lib/new/execution/installNewPackage.cjs.js +127 -0
- package/dist/lib/new/execution/writeTemplateContents.cjs.js +111 -0
- package/dist/lib/new/preparation/collectPortableTemplateInput.cjs.js +157 -0
- package/dist/lib/new/preparation/loadPortableTemplate.cjs.js +82 -0
- package/dist/lib/new/preparation/loadPortableTemplateConfig.cjs.js +121 -0
- package/dist/lib/new/preparation/resolvePackageParams.cjs.js +40 -0
- package/dist/lib/new/preparation/selectTemplateInteractively.cjs.js +38 -0
- package/dist/lib/new/types.cjs.js +15 -4
- package/dist/lib/packager/createDistWorkspace.cjs.js +6 -8
- package/dist/lib/packager/productionPack.cjs.js +3 -0
- package/dist/lib/tasks.cjs.js +0 -111
- package/dist/lib/typeDistProject.cjs.js +2 -7
- package/dist/packages/backend-defaults/package.json.cjs.js +1 -1
- package/dist/packages/backend-plugin-api/package.json.cjs.js +1 -1
- package/dist/packages/backend-test-utils/package.json.cjs.js +1 -1
- package/dist/packages/cli/package.json.cjs.js +3 -3
- package/dist/packages/core-components/package.json.cjs.js +1 -1
- package/dist/packages/dev-utils/package.json.cjs.js +1 -1
- package/dist/plugins/auth-backend/package.json.cjs.js +1 -1
- package/dist/plugins/auth-backend-module-guest-provider/package.json.cjs.js +1 -1
- package/dist/plugins/catalog-node/package.json.cjs.js +1 -1
- package/dist/plugins/scaffolder-node/package.json.cjs.js +1 -1
- package/dist/plugins/scaffolder-node-test-utils/package.json.cjs.js +1 -1
- package/package.json +13 -13
- package/templates/{default-backend-plugin → backend-plugin}/README.md.hbs +4 -4
- package/templates/{default-backend-plugin → backend-plugin}/dev/index.ts.hbs +5 -5
- package/templates/{default-backend-plugin → backend-plugin}/package.json.hbs +1 -9
- package/templates/backend-plugin/portable-template.yaml +5 -0
- package/templates/{default-backend-plugin → backend-plugin}/src/plugin.test.ts.hbs +5 -5
- package/templates/{default-backend-plugin → backend-plugin}/src/plugin.ts.hbs +1 -1
- package/templates/{default-backend-module → backend-plugin-module}/README.md.hbs +1 -1
- package/templates/{default-backend-module → backend-plugin-module}/package.json.hbs +1 -9
- package/templates/backend-plugin-module/portable-template.yaml +5 -0
- package/templates/{default-plugin → frontend-plugin}/README.md.hbs +3 -3
- package/templates/{default-plugin → frontend-plugin}/dev/index.tsx.hbs +1 -1
- package/templates/{default-plugin → frontend-plugin}/package.json.hbs +1 -9
- package/templates/frontend-plugin/portable-template.yaml +6 -0
- package/templates/{default-plugin → frontend-plugin}/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs +1 -1
- package/templates/{default-plugin → frontend-plugin}/src/components/ExampleComponent/ExampleComponent.tsx.hbs +1 -1
- package/templates/{default-plugin → frontend-plugin}/src/plugin.test.ts.hbs +1 -1
- package/templates/{default-plugin → frontend-plugin}/src/plugin.ts.hbs +1 -1
- package/templates/{default-plugin → frontend-plugin}/src/routes.ts.hbs +1 -1
- package/templates/{node-library-package → node-library}/README.md.hbs +2 -2
- package/templates/{node-library-package → node-library}/package.json.hbs +1 -9
- package/templates/node-library/portable-template.yaml +3 -0
- package/templates/plugin-common-library/README.md.hbs +5 -0
- package/templates/{default-common-plugin-package → plugin-common-library}/package.json.hbs +2 -10
- package/templates/plugin-common-library/portable-template.yaml +3 -0
- package/templates/{default-common-plugin-package → plugin-common-library}/src/index.ts.hbs +1 -1
- package/templates/plugin-node-library/README.md.hbs +5 -0
- package/templates/{default-node-plugin-package → plugin-node-library}/package.json.hbs +2 -10
- package/templates/plugin-node-library/portable-template.yaml +3 -0
- package/templates/{default-node-plugin-package → plugin-node-library}/src/index.ts.hbs +1 -1
- package/templates/plugin-web-library/README.md.hbs +5 -0
- package/templates/{default-react-plugin-package → plugin-web-library}/package.json.hbs +2 -10
- package/templates/plugin-web-library/portable-template.yaml +3 -0
- package/templates/{default-react-plugin-package → plugin-web-library}/src/index.ts.hbs +1 -1
- package/templates/scaffolder-backend-module/README.md.hbs +5 -0
- package/templates/{scaffolder-module → scaffolder-backend-module}/package.json.hbs +2 -10
- package/templates/scaffolder-backend-module/portable-template.yaml +6 -0
- package/templates/{scaffolder-module → scaffolder-backend-module}/src/index.ts.hbs +1 -1
- package/templates/{web-library-package → web-library}/README.md.hbs +2 -2
- package/templates/{web-library-package → web-library}/package.json.hbs +1 -9
- package/templates/web-library/portable-template.yaml +3 -0
- package/dist/lib/new/FactoryRegistry.cjs.js +0 -96
- package/dist/lib/new/factories/backendModule.cjs.js +0 -82
- package/dist/lib/new/factories/backendPlugin.cjs.js +0 -78
- package/dist/lib/new/factories/common/prompts.cjs.js +0 -57
- package/dist/lib/new/factories/common/tasks.cjs.js +0 -66
- package/dist/lib/new/factories/common/util.cjs.js +0 -16
- package/dist/lib/new/factories/frontendPlugin.cjs.js +0 -107
- package/dist/lib/new/factories/index.cjs.js +0 -24
- package/dist/lib/new/factories/nodeLibraryPackage.cjs.js +0 -57
- package/dist/lib/new/factories/pluginCommon.cjs.js +0 -58
- package/dist/lib/new/factories/pluginNode.cjs.js +0 -58
- package/dist/lib/new/factories/pluginWeb.cjs.js +0 -58
- package/dist/lib/new/factories/scaffolderModule.cjs.js +0 -90
- package/dist/lib/new/factories/webLibraryPackage.cjs.js +0 -57
- package/templates/default-backend-module/tsconfig.json +0 -9
- package/templates/default-backend-plugin/tsconfig.json +0 -13
- package/templates/default-common-plugin-package/README.md.hbs +0 -5
- package/templates/default-common-plugin-package/tsconfig.json +0 -9
- package/templates/default-node-plugin-package/README.md.hbs +0 -5
- package/templates/default-node-plugin-package/tsconfig.json +0 -9
- package/templates/default-plugin/tsconfig.json +0 -12
- package/templates/default-react-plugin-package/README.md.hbs +0 -5
- package/templates/default-react-plugin-package/tsconfig.json +0 -11
- package/templates/node-library-package/tsconfig.json +0 -11
- package/templates/scaffolder-module/README.md.hbs +0 -5
- package/templates/scaffolder-module/tsconfig.json +0 -9
- package/templates/web-library-package/tsconfig.json +0 -11
- /package/templates/{default-backend-plugin → backend-plugin}/.eslintrc.js.hbs +0 -0
- /package/templates/{default-backend-plugin → backend-plugin}/src/index.ts.hbs +0 -0
- /package/templates/{default-backend-plugin → backend-plugin}/src/router.test.ts +0 -0
- /package/templates/{default-backend-plugin → backend-plugin}/src/router.ts +0 -0
- /package/templates/{default-backend-plugin → backend-plugin}/src/services/TodoListService/createTodoListService.ts +0 -0
- /package/templates/{default-backend-plugin → backend-plugin}/src/services/TodoListService/index.ts +0 -0
- /package/templates/{default-backend-plugin → backend-plugin}/src/services/TodoListService/types.ts +0 -0
- /package/templates/{default-backend-plugin → backend-plugin}/src/setupTests.ts +0 -0
- /package/templates/{default-backend-module → backend-plugin-module}/.eslintrc.js.hbs +0 -0
- /package/templates/{default-backend-module → backend-plugin-module}/src/index.ts.hbs +0 -0
- /package/templates/{default-backend-module → backend-plugin-module}/src/module.ts.hbs +0 -0
- /package/templates/{default-common-plugin-package → frontend-plugin}/.eslintrc.js.hbs +0 -0
- /package/templates/{default-plugin → frontend-plugin}/src/components/ExampleComponent/index.ts +0 -0
- /package/templates/{default-plugin → frontend-plugin}/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs +0 -0
- /package/templates/{default-plugin → frontend-plugin}/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs +0 -0
- /package/templates/{default-plugin → frontend-plugin}/src/components/ExampleFetchComponent/index.ts +0 -0
- /package/templates/{default-plugin → frontend-plugin}/src/index.ts.hbs +0 -0
- /package/templates/{default-plugin → frontend-plugin}/src/setupTests.ts +0 -0
- /package/templates/{default-node-plugin-package → node-library}/.eslintrc.js.hbs +0 -0
- /package/templates/{node-library-package → node-library}/src/index.ts.hbs +0 -0
- /package/templates/{default-common-plugin-package → node-library}/src/setupTests.ts +0 -0
- /package/templates/{default-plugin → plugin-common-library}/.eslintrc.js.hbs +0 -0
- /package/templates/{default-node-plugin-package → plugin-common-library}/src/setupTests.ts +0 -0
- /package/templates/{default-react-plugin-package → plugin-node-library}/.eslintrc.js.hbs +0 -0
- /package/templates/{node-library-package → plugin-node-library}/src/setupTests.ts +0 -0
- /package/templates/{node-library-package → plugin-web-library}/.eslintrc.js.hbs +0 -0
- /package/templates/{default-react-plugin-package → plugin-web-library}/src/components/ExampleComponent/ExampleComponent.test.tsx +0 -0
- /package/templates/{default-react-plugin-package → plugin-web-library}/src/components/ExampleComponent/ExampleComponent.tsx +0 -0
- /package/templates/{default-react-plugin-package → plugin-web-library}/src/components/ExampleComponent/index.ts +0 -0
- /package/templates/{default-react-plugin-package → plugin-web-library}/src/components/index.ts +0 -0
- /package/templates/{default-react-plugin-package → plugin-web-library}/src/hooks/index.ts +0 -0
- /package/templates/{default-react-plugin-package → plugin-web-library}/src/hooks/useExample/index.ts +0 -0
- /package/templates/{default-react-plugin-package → plugin-web-library}/src/hooks/useExample/useExample.ts +0 -0
- /package/templates/{default-react-plugin-package → plugin-web-library}/src/setupTests.ts +0 -0
- /package/templates/{scaffolder-module → scaffolder-backend-module}/.eslintrc.js.hbs +0 -0
- /package/templates/{scaffolder-module → scaffolder-backend-module}/src/actions/example.test.ts +0 -0
- /package/templates/{scaffolder-module → scaffolder-backend-module}/src/actions/example.ts +0 -0
- /package/templates/{scaffolder-module → scaffolder-backend-module}/src/module.ts +0 -0
- /package/templates/{web-library-package → web-library}/.eslintrc.js.hbs +0 -0
- /package/templates/{web-library-package → web-library}/src/index.ts.hbs +0 -0
- /package/templates/{web-library-package → web-library}/src/setupTests.ts +0 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs-extra');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var paths = require('../../paths.cjs.js');
|
|
6
|
+
var errors = require('@backstage/errors');
|
|
7
|
+
var cliNode = require('@backstage/cli-node');
|
|
8
|
+
var PortableTemplater = require('./PortableTemplater.cjs.js');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
13
|
+
|
|
14
|
+
async function writeTemplateContents(template, input) {
|
|
15
|
+
const targetDir = paths.paths.resolveTargetRoot(input.packagePath);
|
|
16
|
+
if (await fs__default.default.pathExists(targetDir)) {
|
|
17
|
+
throw new errors.InputError(`Package '${input.packagePath}' already exists`);
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const isMonoRepo = await cliNode.isMonoRepo();
|
|
21
|
+
const { role, ...roleValues } = input.roleParams;
|
|
22
|
+
const templater = await PortableTemplater.PortableTemplater.create({
|
|
23
|
+
values: {
|
|
24
|
+
...roleValues,
|
|
25
|
+
packageName: input.packageName
|
|
26
|
+
},
|
|
27
|
+
templatedValues: template.values
|
|
28
|
+
});
|
|
29
|
+
if (!isMonoRepo) {
|
|
30
|
+
await fs__default.default.writeJson(
|
|
31
|
+
path.resolve(targetDir, "tsconfig.json"),
|
|
32
|
+
{
|
|
33
|
+
extends: "@backstage/cli/config/tsconfig.json",
|
|
34
|
+
include: ["src", "dev", "migrations"],
|
|
35
|
+
exclude: ["node_modules"],
|
|
36
|
+
compilerOptions: {
|
|
37
|
+
outDir: "dist-types",
|
|
38
|
+
rootDir: "."
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
{ spaces: 2 }
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
for (const file of template.files) {
|
|
45
|
+
const destPath = path.resolve(targetDir, file.path);
|
|
46
|
+
await fs__default.default.ensureDir(path.dirname(destPath));
|
|
47
|
+
let content = file.syntax === "handlebars" ? templater.template(file.content) : file.content;
|
|
48
|
+
if (file.path === "package.json") {
|
|
49
|
+
try {
|
|
50
|
+
content = injectPackageJsonInput(input, content);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
throw new errors.ForwardedError(
|
|
53
|
+
"Failed to transform templated package.json",
|
|
54
|
+
error
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
await fs__default.default.writeFile(destPath, content).catch((error) => {
|
|
59
|
+
throw new errors.ForwardedError(`Failed to copy file to ${destPath}`, error);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return { targetDir };
|
|
63
|
+
} catch (error) {
|
|
64
|
+
await fs__default.default.rm(targetDir, { recursive: true, force: true, maxRetries: 10 });
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function injectPackageJsonInput(input, content) {
|
|
69
|
+
const pkgJson = JSON.parse(content);
|
|
70
|
+
const toAdd = new Array();
|
|
71
|
+
if (pkgJson.version) {
|
|
72
|
+
pkgJson.version = input.version;
|
|
73
|
+
} else {
|
|
74
|
+
toAdd.push(["version", input.version]);
|
|
75
|
+
}
|
|
76
|
+
if (pkgJson.license) {
|
|
77
|
+
pkgJson.license = input.license;
|
|
78
|
+
} else {
|
|
79
|
+
toAdd.push(["license", input.license]);
|
|
80
|
+
}
|
|
81
|
+
if (input.private) {
|
|
82
|
+
if (pkgJson.private === false) {
|
|
83
|
+
pkgJson.private = true;
|
|
84
|
+
} else if (!pkgJson.private) {
|
|
85
|
+
toAdd.push(["private", true]);
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
delete pkgJson.private;
|
|
89
|
+
}
|
|
90
|
+
if (input.publishRegistry) {
|
|
91
|
+
if (pkgJson.publishConfig) {
|
|
92
|
+
pkgJson.publishConfig = {
|
|
93
|
+
...pkgJson.publishConfig,
|
|
94
|
+
registry: input.publishRegistry
|
|
95
|
+
};
|
|
96
|
+
} else {
|
|
97
|
+
toAdd.push(["publishConfig", { registry: input.publishRegistry }]);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const entries = Object.entries(pkgJson);
|
|
101
|
+
const nameIndex = entries.findIndex(([name]) => name === "name");
|
|
102
|
+
if (nameIndex === -1) {
|
|
103
|
+
throw new Error("templated package.json does not contain a name field");
|
|
104
|
+
}
|
|
105
|
+
entries.splice(nameIndex + 1, 0, ...toAdd);
|
|
106
|
+
return JSON.stringify(Object.fromEntries(entries), null, 2);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
exports.injectPackageJsonInput = injectPackageJsonInput;
|
|
110
|
+
exports.writeTemplateContents = writeTemplateContents;
|
|
111
|
+
//# sourceMappingURL=writeTemplateContents.cjs.js.map
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var inquirer = require('inquirer');
|
|
4
|
+
var codeowners = require('../../codeowners/codeowners.cjs.js');
|
|
5
|
+
var paths = require('../../paths.cjs.js');
|
|
6
|
+
var resolvePackageParams = require('./resolvePackageParams.cjs.js');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var inquirer__default = /*#__PURE__*/_interopDefaultCompat(inquirer);
|
|
11
|
+
|
|
12
|
+
async function collectPortableTemplateInput(options) {
|
|
13
|
+
const { config, template, prefilledParams } = options;
|
|
14
|
+
const codeOwnersFilePath = await codeowners.getCodeownersFilePath(paths.paths.targetRoot);
|
|
15
|
+
const prompts = getPromptsForRole(template.role);
|
|
16
|
+
if (codeOwnersFilePath) {
|
|
17
|
+
prompts.push(ownerPrompt());
|
|
18
|
+
}
|
|
19
|
+
const deprecatedParams = {};
|
|
20
|
+
if (config.isUsingDefaultTemplates && prefilledParams.id) {
|
|
21
|
+
console.warn(
|
|
22
|
+
`DEPRECATION WARNING: The 'id' parameter is deprecated, use 'pluginId' instead`
|
|
23
|
+
);
|
|
24
|
+
deprecatedParams.pluginId = prefilledParams.id;
|
|
25
|
+
}
|
|
26
|
+
const parameters = {
|
|
27
|
+
...template.values,
|
|
28
|
+
...prefilledParams,
|
|
29
|
+
...deprecatedParams
|
|
30
|
+
};
|
|
31
|
+
const needsAnswer = [];
|
|
32
|
+
const prefilledAnswers = {};
|
|
33
|
+
for (const prompt of prompts) {
|
|
34
|
+
if (prompt.name && parameters[prompt.name] !== void 0) {
|
|
35
|
+
prefilledAnswers[prompt.name] = parameters[prompt.name];
|
|
36
|
+
} else {
|
|
37
|
+
needsAnswer.push(prompt);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const promptAnswers = await inquirer__default.default.prompt(
|
|
41
|
+
needsAnswer
|
|
42
|
+
);
|
|
43
|
+
const answers = {
|
|
44
|
+
...prefilledAnswers,
|
|
45
|
+
...promptAnswers
|
|
46
|
+
};
|
|
47
|
+
const roleParams = {
|
|
48
|
+
role: template.role,
|
|
49
|
+
name: answers.name,
|
|
50
|
+
pluginId: answers.pluginId,
|
|
51
|
+
moduleId: answers.moduleId
|
|
52
|
+
};
|
|
53
|
+
const packageParams = resolvePackageParams.resolvePackageParams({
|
|
54
|
+
roleParams,
|
|
55
|
+
packagePrefix: config.packageNamePrefix,
|
|
56
|
+
pluginInfix: config.packageNamePluginInfix
|
|
57
|
+
});
|
|
58
|
+
return {
|
|
59
|
+
roleParams,
|
|
60
|
+
owner: answers.owner,
|
|
61
|
+
license: config.license,
|
|
62
|
+
version: config.version,
|
|
63
|
+
private: config.private,
|
|
64
|
+
publishRegistry: config.publishRegistry,
|
|
65
|
+
packageName: packageParams.packageName,
|
|
66
|
+
packagePath: packageParams.packagePath
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function namePrompt() {
|
|
70
|
+
return {
|
|
71
|
+
type: "input",
|
|
72
|
+
name: "name",
|
|
73
|
+
message: "Enter the name of the package, without scope [required]",
|
|
74
|
+
validate: (value) => {
|
|
75
|
+
if (!value) {
|
|
76
|
+
return "Please enter the name of the package";
|
|
77
|
+
} else if (!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(value)) {
|
|
78
|
+
return "Package names must be lowercase and contain only letters, digits, and dashes.";
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function pluginIdPrompt() {
|
|
85
|
+
return {
|
|
86
|
+
type: "input",
|
|
87
|
+
name: "pluginId",
|
|
88
|
+
message: "Enter the ID of the plugin [required]",
|
|
89
|
+
validate: (value) => {
|
|
90
|
+
if (!value) {
|
|
91
|
+
return "Please enter the ID of the plugin";
|
|
92
|
+
} else if (!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(value)) {
|
|
93
|
+
return "Plugin IDs must be lowercase and contain only letters, digits, and dashes.";
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function moduleIdIdPrompt() {
|
|
100
|
+
return {
|
|
101
|
+
type: "input",
|
|
102
|
+
name: "moduleId",
|
|
103
|
+
message: "Enter the ID of the module [required]",
|
|
104
|
+
validate: (value) => {
|
|
105
|
+
if (!value) {
|
|
106
|
+
return "Please enter the ID of the module";
|
|
107
|
+
} else if (!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(value)) {
|
|
108
|
+
return "Module IDs must be lowercase and contain only letters, digits, and dashes.";
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function getPromptsForRole(role) {
|
|
115
|
+
switch (role) {
|
|
116
|
+
case "web-library":
|
|
117
|
+
case "node-library":
|
|
118
|
+
case "common-library":
|
|
119
|
+
return [namePrompt()];
|
|
120
|
+
case "plugin-web-library":
|
|
121
|
+
case "plugin-node-library":
|
|
122
|
+
case "plugin-common-library":
|
|
123
|
+
case "frontend-plugin":
|
|
124
|
+
case "backend-plugin":
|
|
125
|
+
return [pluginIdPrompt()];
|
|
126
|
+
case "frontend-plugin-module":
|
|
127
|
+
case "backend-plugin-module":
|
|
128
|
+
return [pluginIdPrompt(), moduleIdIdPrompt()];
|
|
129
|
+
default:
|
|
130
|
+
return [];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function ownerPrompt() {
|
|
134
|
+
return {
|
|
135
|
+
type: "input",
|
|
136
|
+
name: "owner",
|
|
137
|
+
message: "Enter an owner to add to CODEOWNERS [optional]",
|
|
138
|
+
validate: (value) => {
|
|
139
|
+
if (!value) {
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
const ownerIds = codeowners.parseOwnerIds(value);
|
|
143
|
+
if (!ownerIds) {
|
|
144
|
+
return "The owner must be a space separated list of team names (e.g. @org/team-name), usernames (e.g. @username), or the email addresses (e.g. user@example.com).";
|
|
145
|
+
}
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
exports.collectPortableTemplateInput = collectPortableTemplateInput;
|
|
152
|
+
exports.getPromptsForRole = getPromptsForRole;
|
|
153
|
+
exports.moduleIdIdPrompt = moduleIdIdPrompt;
|
|
154
|
+
exports.namePrompt = namePrompt;
|
|
155
|
+
exports.ownerPrompt = ownerPrompt;
|
|
156
|
+
exports.pluginIdPrompt = pluginIdPrompt;
|
|
157
|
+
//# sourceMappingURL=collectPortableTemplateInput.cjs.js.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var z = require('zod');
|
|
4
|
+
var fs = require('fs-extra');
|
|
5
|
+
var recursiveReaddir = require('recursive-readdir');
|
|
6
|
+
var path = require('path');
|
|
7
|
+
var node_path = require('node:path');
|
|
8
|
+
var yaml = require('yaml');
|
|
9
|
+
var paths = require('../../paths.cjs.js');
|
|
10
|
+
var types = require('../types.cjs.js');
|
|
11
|
+
var errors = require('@backstage/errors');
|
|
12
|
+
var zodValidationError = require('zod-validation-error');
|
|
13
|
+
|
|
14
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
15
|
+
|
|
16
|
+
var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
17
|
+
var recursiveReaddir__default = /*#__PURE__*/_interopDefaultCompat(recursiveReaddir);
|
|
18
|
+
|
|
19
|
+
const templateDefinitionSchema = z.z.object({
|
|
20
|
+
name: z.z.string(),
|
|
21
|
+
role: z.z.enum(types.TEMPLATE_ROLES),
|
|
22
|
+
description: z.z.string().optional(),
|
|
23
|
+
values: z.z.record(z.z.string()).optional()
|
|
24
|
+
}).strict();
|
|
25
|
+
async function loadPortableTemplate(pointer) {
|
|
26
|
+
if (pointer.target.match(/https?:\/\//)) {
|
|
27
|
+
throw new Error("Remote templates are not supported yet");
|
|
28
|
+
}
|
|
29
|
+
const templateContent = await fs__default.default.readFile(paths.paths.resolveTargetRoot(pointer.target), "utf-8").catch((error) => {
|
|
30
|
+
throw new errors.ForwardedError(
|
|
31
|
+
`Failed to load template definition from '${pointer.target}'`,
|
|
32
|
+
error
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
const rawTemplate = yaml.parse(templateContent);
|
|
36
|
+
const parsed = templateDefinitionSchema.safeParse(rawTemplate);
|
|
37
|
+
if (!parsed.success) {
|
|
38
|
+
throw new errors.ForwardedError(
|
|
39
|
+
`Invalid template definition at '${pointer.target}'`,
|
|
40
|
+
zodValidationError.fromZodError(parsed.error)
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
const { role, values = {} } = parsed.data;
|
|
44
|
+
const templatePath = path.resolve(node_path.dirname(pointer.target));
|
|
45
|
+
const filePaths = await recursiveReaddir__default.default(templatePath).catch((error) => {
|
|
46
|
+
throw new errors.ForwardedError(
|
|
47
|
+
`Failed to load template contents from '${templatePath}'`,
|
|
48
|
+
error
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
const loadedFiles = new Array();
|
|
52
|
+
for (const filePath of filePaths) {
|
|
53
|
+
const path$1 = path.relative(templatePath, filePath);
|
|
54
|
+
if (filePath === pointer.target) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const content = await fs__default.default.readFile(filePath, "utf-8").catch((error) => {
|
|
58
|
+
throw new errors.ForwardedError(
|
|
59
|
+
`Failed to load file contents from '${path$1}'`,
|
|
60
|
+
error
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
if (path$1.endsWith(".hbs")) {
|
|
64
|
+
loadedFiles.push({
|
|
65
|
+
path: path$1.slice(0, -4),
|
|
66
|
+
content,
|
|
67
|
+
syntax: "handlebars"
|
|
68
|
+
});
|
|
69
|
+
} else {
|
|
70
|
+
loadedFiles.push({ path: path$1, content });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
name: pointer.name,
|
|
75
|
+
role,
|
|
76
|
+
files: loadedFiles,
|
|
77
|
+
values
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
exports.loadPortableTemplate = loadPortableTemplate;
|
|
82
|
+
//# sourceMappingURL=loadPortableTemplate.cjs.js.map
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs-extra');
|
|
4
|
+
var node_path = require('node:path');
|
|
5
|
+
var paths = require('../../paths.cjs.js');
|
|
6
|
+
var defaultTemplates = require('../defaultTemplates.cjs.js');
|
|
7
|
+
var types = require('../types.cjs.js');
|
|
8
|
+
var yaml = require('yaml');
|
|
9
|
+
var z = require('zod');
|
|
10
|
+
var zodValidationError = require('zod-validation-error');
|
|
11
|
+
var errors = require('@backstage/errors');
|
|
12
|
+
|
|
13
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
14
|
+
|
|
15
|
+
var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
16
|
+
|
|
17
|
+
const defaults = {
|
|
18
|
+
license: "Apache-2.0",
|
|
19
|
+
version: "0.1.0",
|
|
20
|
+
private: true,
|
|
21
|
+
publishRegistry: void 0,
|
|
22
|
+
packageNamePrefix: "@internal/",
|
|
23
|
+
packageNamePluginInfix: "plugin-"
|
|
24
|
+
};
|
|
25
|
+
const newConfigSchema = z.z.object({
|
|
26
|
+
templates: z.z.array(z.z.string()).optional(),
|
|
27
|
+
globals: z.z.object({
|
|
28
|
+
license: z.z.string().optional(),
|
|
29
|
+
version: z.z.string().optional(),
|
|
30
|
+
private: z.z.boolean().optional(),
|
|
31
|
+
publishRegistry: z.z.string().optional(),
|
|
32
|
+
namePrefix: z.z.string().optional(),
|
|
33
|
+
namePluginInfix: z.z.string().optional()
|
|
34
|
+
}).optional()
|
|
35
|
+
}).strict();
|
|
36
|
+
const pkgJsonWithNewConfigSchema = z.z.object({
|
|
37
|
+
backstage: z.z.object({
|
|
38
|
+
cli: z.z.object({
|
|
39
|
+
new: newConfigSchema.optional()
|
|
40
|
+
}).optional()
|
|
41
|
+
}).optional()
|
|
42
|
+
});
|
|
43
|
+
async function loadPortableTemplateConfig(options = {}) {
|
|
44
|
+
const { overrides = {} } = options;
|
|
45
|
+
const pkgPath = options.packagePath ?? paths.paths.resolveTargetRoot("package.json");
|
|
46
|
+
const pkgJson = await fs__default.default.readJson(pkgPath);
|
|
47
|
+
const parsed = pkgJsonWithNewConfigSchema.safeParse(pkgJson);
|
|
48
|
+
if (!parsed.success) {
|
|
49
|
+
throw new errors.ForwardedError(
|
|
50
|
+
`Failed to load templating configuration from '${pkgPath}'`,
|
|
51
|
+
zodValidationError.fromZodError(parsed.error)
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
const config = parsed.data.backstage?.cli?.new;
|
|
55
|
+
const basePath = node_path.dirname(pkgPath);
|
|
56
|
+
const templatePointerEntries = await Promise.all(
|
|
57
|
+
(config?.templates ?? defaultTemplates.defaultTemplates).map(async (rawPointer) => {
|
|
58
|
+
try {
|
|
59
|
+
const templatePath = resolveLocalTemplatePath(rawPointer, basePath);
|
|
60
|
+
const pointer = await peekLocalTemplateDefinition(templatePath);
|
|
61
|
+
return { pointer, rawPointer };
|
|
62
|
+
} catch (error) {
|
|
63
|
+
throw new errors.ForwardedError(
|
|
64
|
+
`Failed to load template definition '${rawPointer}'`,
|
|
65
|
+
error
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
const templateNameConflicts = /* @__PURE__ */ new Map();
|
|
71
|
+
for (const { pointer, rawPointer } of templatePointerEntries) {
|
|
72
|
+
const conflict = templateNameConflicts.get(pointer.name);
|
|
73
|
+
if (conflict) {
|
|
74
|
+
throw new Error(
|
|
75
|
+
`Invalid template configuration, received conflicting template name '${pointer.name}' from '${conflict}' and '${rawPointer}'`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
templateNameConflicts.set(pointer.name, rawPointer);
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
isUsingDefaultTemplates: !config?.templates,
|
|
82
|
+
templatePointers: templatePointerEntries.map(({ pointer }) => pointer),
|
|
83
|
+
license: overrides.license ?? config?.globals?.license ?? defaults.license,
|
|
84
|
+
version: overrides.version ?? config?.globals?.version ?? defaults.version,
|
|
85
|
+
private: overrides.private ?? config?.globals?.private ?? defaults.private,
|
|
86
|
+
publishRegistry: overrides.publishRegistry ?? config?.globals?.publishRegistry ?? defaults.publishRegistry,
|
|
87
|
+
packageNamePrefix: overrides.packageNamePrefix ?? config?.globals?.namePrefix ?? defaults.packageNamePrefix,
|
|
88
|
+
packageNamePluginInfix: overrides.packageNamePluginInfix ?? config?.globals?.namePluginInfix ?? defaults.packageNamePluginInfix
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function resolveLocalTemplatePath(pointer, basePath) {
|
|
92
|
+
if (node_path.isAbsolute(pointer)) {
|
|
93
|
+
throw new Error(`Template target may not be an absolute path`);
|
|
94
|
+
}
|
|
95
|
+
if (pointer.startsWith(".")) {
|
|
96
|
+
return node_path.resolve(basePath, pointer, types.TEMPLATE_FILE_NAME);
|
|
97
|
+
}
|
|
98
|
+
return require.resolve(`${pointer}/${types.TEMPLATE_FILE_NAME}`, {
|
|
99
|
+
paths: [basePath]
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
const partialTemplateDefinitionSchema = z.z.object({
|
|
103
|
+
name: z.z.string(),
|
|
104
|
+
description: z.z.string().optional()
|
|
105
|
+
});
|
|
106
|
+
async function peekLocalTemplateDefinition(target) {
|
|
107
|
+
const content = await fs__default.default.readFile(target, "utf8");
|
|
108
|
+
const rawTemplate = yaml.parse(content);
|
|
109
|
+
const parsed = partialTemplateDefinitionSchema.safeParse(rawTemplate);
|
|
110
|
+
if (!parsed.success) {
|
|
111
|
+
throw zodValidationError.fromZodError(parsed.error);
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
name: parsed.data.name,
|
|
115
|
+
description: parsed.data.description,
|
|
116
|
+
target
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
exports.loadPortableTemplateConfig = loadPortableTemplateConfig;
|
|
121
|
+
//# sourceMappingURL=loadPortableTemplateConfig.cjs.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('path');
|
|
4
|
+
|
|
5
|
+
function resolvePackageParams(options) {
|
|
6
|
+
const baseName = getBaseNameForRole(options.roleParams);
|
|
7
|
+
const isPlugin = options.roleParams.role.includes("plugin");
|
|
8
|
+
const pluginInfix = isPlugin ? options.pluginInfix : "";
|
|
9
|
+
return {
|
|
10
|
+
packageName: `${options.packagePrefix}${pluginInfix}${baseName}`,
|
|
11
|
+
packagePath: path.join(isPlugin ? "plugins" : "packages", baseName)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function getBaseNameForRole(roleParams) {
|
|
15
|
+
switch (roleParams.role) {
|
|
16
|
+
case "web-library":
|
|
17
|
+
case "node-library":
|
|
18
|
+
case "common-library":
|
|
19
|
+
return roleParams.name;
|
|
20
|
+
case "plugin-web-library":
|
|
21
|
+
return `${roleParams.pluginId}-react`;
|
|
22
|
+
case "plugin-node-library":
|
|
23
|
+
return `${roleParams.pluginId}-node`;
|
|
24
|
+
case "plugin-common-library":
|
|
25
|
+
return `${roleParams.pluginId}-common`;
|
|
26
|
+
case "frontend-plugin":
|
|
27
|
+
return `${roleParams.pluginId}`;
|
|
28
|
+
case "frontend-plugin-module":
|
|
29
|
+
return `${roleParams.pluginId}-module-${roleParams.moduleId}`;
|
|
30
|
+
case "backend-plugin":
|
|
31
|
+
return `${roleParams.pluginId}-backend`;
|
|
32
|
+
case "backend-plugin-module":
|
|
33
|
+
return `${roleParams.pluginId}-backend-module-${roleParams.moduleId}`;
|
|
34
|
+
default:
|
|
35
|
+
throw new Error(`Unknown role ${roleParams.role}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.resolvePackageParams = resolvePackageParams;
|
|
40
|
+
//# sourceMappingURL=resolvePackageParams.cjs.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var inquirer = require('inquirer');
|
|
4
|
+
|
|
5
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
6
|
+
|
|
7
|
+
var inquirer__default = /*#__PURE__*/_interopDefaultCompat(inquirer);
|
|
8
|
+
|
|
9
|
+
async function selectTemplateInteractively(config, preselectedTemplateName) {
|
|
10
|
+
let selectedName = preselectedTemplateName;
|
|
11
|
+
if (config.isUsingDefaultTemplates && selectedName === "plugin") {
|
|
12
|
+
console.warn(
|
|
13
|
+
`DEPRECATION WARNING: The 'plugin' template is deprecated, use 'frontend-plugin' instead`
|
|
14
|
+
);
|
|
15
|
+
selectedName = "frontend-plugin";
|
|
16
|
+
}
|
|
17
|
+
if (!selectedName) {
|
|
18
|
+
const answers = await inquirer__default.default.prompt([
|
|
19
|
+
{
|
|
20
|
+
type: "list",
|
|
21
|
+
name: "name",
|
|
22
|
+
message: "What do you want to create?",
|
|
23
|
+
choices: config.templatePointers.map(
|
|
24
|
+
(t) => t.description ? { name: `${t.name} - ${t.description}`, value: t.name } : t.name
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
]);
|
|
28
|
+
selectedName = answers.name;
|
|
29
|
+
}
|
|
30
|
+
const template = config.templatePointers.find((t) => t.name === selectedName);
|
|
31
|
+
if (!template) {
|
|
32
|
+
throw new Error(`Template '${selectedName}' not found`);
|
|
33
|
+
}
|
|
34
|
+
return template;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.selectTemplateInteractively = selectTemplateInteractively;
|
|
38
|
+
//# sourceMappingURL=selectTemplateInteractively.cjs.js.map
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const TEMPLATE_FILE_NAME = "portable-template.yaml";
|
|
4
|
+
const TEMPLATE_ROLES = [
|
|
5
|
+
"web-library",
|
|
6
|
+
"node-library",
|
|
7
|
+
"common-library",
|
|
8
|
+
"plugin-web-library",
|
|
9
|
+
"plugin-node-library",
|
|
10
|
+
"plugin-common-library",
|
|
11
|
+
"frontend-plugin",
|
|
12
|
+
"frontend-plugin-module",
|
|
13
|
+
"backend-plugin",
|
|
14
|
+
"backend-plugin-module"
|
|
15
|
+
];
|
|
6
16
|
|
|
7
|
-
exports.
|
|
17
|
+
exports.TEMPLATE_FILE_NAME = TEMPLATE_FILE_NAME;
|
|
18
|
+
exports.TEMPLATE_ROLES = TEMPLATE_ROLES;
|
|
8
19
|
//# sourceMappingURL=types.cjs.js.map
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
var chalk = require('chalk');
|
|
4
4
|
var fs = require('fs-extra');
|
|
5
5
|
var path = require('path');
|
|
6
|
-
var pLimit = require('p-limit');
|
|
7
6
|
var os = require('os');
|
|
8
7
|
var tar = require('tar');
|
|
9
8
|
var partition = require('lodash/partition');
|
|
@@ -21,7 +20,6 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
21
20
|
|
|
22
21
|
var chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
|
|
23
22
|
var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
24
|
-
var pLimit__default = /*#__PURE__*/_interopDefaultCompat(pLimit);
|
|
25
23
|
var tar__default = /*#__PURE__*/_interopDefaultCompat(tar);
|
|
26
24
|
var partition__default = /*#__PURE__*/_interopDefaultCompat(partition);
|
|
27
25
|
|
|
@@ -207,12 +205,12 @@ async function moveToDistWorkspace(workspaceDir, localPackages, alwaysPack, enab
|
|
|
207
205
|
for (const target of unsafePackages) {
|
|
208
206
|
await pack(target, `temp-package.tgz`);
|
|
209
207
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
);
|
|
208
|
+
await parallel.runParallelWorkers({
|
|
209
|
+
items: safePackages.map((target, index) => ({ target, index })),
|
|
210
|
+
worker: async ({ target, index }) => {
|
|
211
|
+
await pack(target, `temp-package-${index}.tgz`);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
216
214
|
}
|
|
217
215
|
|
|
218
216
|
exports.createDistWorkspace = createDistWorkspace;
|
|
@@ -120,6 +120,9 @@ async function rewriteEntryPoints(pkg, packageDir, featureDetectionProject) {
|
|
|
120
120
|
);
|
|
121
121
|
if (defaultFeatureType) {
|
|
122
122
|
exp = { backstage: defaultFeatureType, ...exp };
|
|
123
|
+
pkg.backstage = pkg.backstage ?? {};
|
|
124
|
+
pkg.backstage.features = pkg.backstage.features ?? {};
|
|
125
|
+
pkg.backstage.features[entryPoint.mount] = defaultFeatureType;
|
|
123
126
|
}
|
|
124
127
|
}
|
|
125
128
|
if (entryPoint.mount === ".") {
|