@dawitworku/projectcli 0.2.1 → 3.0.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/CHANGELOG.md +29 -0
- package/README.md +106 -0
- package/ROADMAP.md +23 -0
- package/docs/demo.cast +445 -0
- package/docs/demo.svg +254637 -0
- package/package.json +13 -3
- package/scripts/release-notes.js +34 -0
- package/src/add.js +164 -1
- package/src/config.js +66 -0
- package/src/core/doctor/index.js +504 -0
- package/src/devcontainer.js +82 -0
- package/src/index.js +408 -37
- package/src/license.js +80 -0
- package/src/plugin.js +140 -0
- package/src/plugins/contributions.js +101 -0
- package/src/plugins/manager.js +38 -0
- package/src/preflight.js +26 -0
- package/src/preset.js +59 -0
- package/src/presets/index.js +124 -0
- package/src/registry/index.js +91 -0
- package/src/registry.js +3 -909
- package/src/registry_legacy.js +911 -0
- package/src/settings.js +32 -3
- package/src/upgrade.js +228 -0
package/src/license.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const licenses = {
|
|
2
|
+
MIT: (year, author) => `MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) ${year} ${author}
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
23
|
+
`,
|
|
24
|
+
Apache2: (year, author) => ` Apache License
|
|
25
|
+
Version 2.0, January 2004
|
|
26
|
+
http://www.apache.org/licenses/
|
|
27
|
+
|
|
28
|
+
Copyright ${year} ${author}
|
|
29
|
+
|
|
30
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
31
|
+
you may not use this file except in compliance with the License.
|
|
32
|
+
You may obtain a copy of the License at
|
|
33
|
+
|
|
34
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
35
|
+
|
|
36
|
+
Unless required by applicable law or agreed to in writing, software
|
|
37
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
38
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
39
|
+
See the License for the specific language governing permissions and
|
|
40
|
+
limitations under the License.
|
|
41
|
+
`,
|
|
42
|
+
ISC: (year, author) => `ISC License
|
|
43
|
+
|
|
44
|
+
Copyright (c) ${year}, ${author}
|
|
45
|
+
|
|
46
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
47
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
48
|
+
copyright notice and this permission notice appear in all copies.
|
|
49
|
+
|
|
50
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
51
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
52
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
53
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
54
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
55
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
56
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
57
|
+
`,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
function getLicense(type, author) {
|
|
61
|
+
const year = new Date().getFullYear();
|
|
62
|
+
const template = licenses[type] || licenses.MIT;
|
|
63
|
+
return template(year, author || "The Authors");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function generateLicense(projectRoot, type, author) {
|
|
67
|
+
return [
|
|
68
|
+
{
|
|
69
|
+
type: "writeFile",
|
|
70
|
+
path: "LICENSE",
|
|
71
|
+
content: getLicense(type, author),
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = {
|
|
77
|
+
getLicense,
|
|
78
|
+
generateLicense,
|
|
79
|
+
licenseTypes: ["MIT", "Apache2", "ISC"],
|
|
80
|
+
};
|
package/src/plugin.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
const chalk = require("chalk");
|
|
2
|
+
|
|
3
|
+
const { loadConfig, saveConfig, CONFIG_PATH } = require("./config");
|
|
4
|
+
const { getEnabledPlugins, tryLoadPlugin } = require("./plugins/manager");
|
|
5
|
+
|
|
6
|
+
function parsePluginArgs(argv) {
|
|
7
|
+
const out = { yes: false, dryRun: false };
|
|
8
|
+
const args = Array.isArray(argv) ? argv : [];
|
|
9
|
+
for (const a of args) {
|
|
10
|
+
if (a === "--yes" || a === "-y") out.yes = true;
|
|
11
|
+
else if (a === "--dry-run") out.dryRun = true;
|
|
12
|
+
}
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function firstPositional(argv) {
|
|
17
|
+
const args = Array.isArray(argv) ? argv : [];
|
|
18
|
+
for (const a of args) {
|
|
19
|
+
if (typeof a !== "string") continue;
|
|
20
|
+
if (a.startsWith("-")) continue;
|
|
21
|
+
return a;
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function secondPositional(argv) {
|
|
27
|
+
const args = Array.isArray(argv) ? argv : [];
|
|
28
|
+
let seenFirst = false;
|
|
29
|
+
for (const a of args) {
|
|
30
|
+
if (typeof a !== "string") continue;
|
|
31
|
+
if (a.startsWith("-")) continue;
|
|
32
|
+
if (!seenFirst) {
|
|
33
|
+
seenFirst = true;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
return a;
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function printPluginList(effectiveConfig) {
|
|
42
|
+
const enabled = getEnabledPlugins(effectiveConfig);
|
|
43
|
+
|
|
44
|
+
console.log(chalk.bold("\nPlugins:"));
|
|
45
|
+
if (enabled.length === 0) {
|
|
46
|
+
console.log(chalk.dim("(none enabled)"));
|
|
47
|
+
console.log(chalk.dim(`Config: ${CONFIG_PATH}`));
|
|
48
|
+
console.log("");
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
for (const id of enabled) {
|
|
53
|
+
const loaded = tryLoadPlugin(id);
|
|
54
|
+
if (loaded.ok) {
|
|
55
|
+
console.log(`${chalk.green("✓")} ${id}`);
|
|
56
|
+
} else {
|
|
57
|
+
console.log(`${chalk.red("✗")} ${id}`);
|
|
58
|
+
console.log(chalk.dim(` → ${loaded.error}`));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
console.log(chalk.dim(`\nConfig: ${CONFIG_PATH}`));
|
|
62
|
+
console.log("");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function runPlugin({ prompt, argv, effectiveConfig }) {
|
|
66
|
+
const flags = parsePluginArgs(argv);
|
|
67
|
+
const args = Array.isArray(argv) ? argv : [];
|
|
68
|
+
|
|
69
|
+
const sub = firstPositional(args);
|
|
70
|
+
|
|
71
|
+
if (!sub || sub === "list") {
|
|
72
|
+
printPluginList(effectiveConfig);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (sub === "install") {
|
|
77
|
+
const pluginId = secondPositional(args);
|
|
78
|
+
if (!pluginId) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
"Missing plugin id. Example: projectcli plugin install my-company"
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const cfg = loadConfig();
|
|
85
|
+
const current = Array.isArray(cfg.plugins) ? cfg.plugins : [];
|
|
86
|
+
const enabled = new Set(
|
|
87
|
+
current.map((p) => String(p || "").trim()).filter(Boolean)
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
if (enabled.has(pluginId)) {
|
|
91
|
+
console.log(chalk.dim(`\nAlready enabled: ${pluginId}`));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const loaded = tryLoadPlugin(pluginId);
|
|
96
|
+
if (!loaded.ok) {
|
|
97
|
+
console.log(
|
|
98
|
+
chalk.yellow("\nNote: this command does not install packages.")
|
|
99
|
+
);
|
|
100
|
+
console.log(
|
|
101
|
+
chalk.yellow(
|
|
102
|
+
`It only enables a plugin that is already resolvable by Node: ${pluginId}`
|
|
103
|
+
)
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (flags.dryRun) {
|
|
108
|
+
console.log(chalk.bold("\nPlanned actions:"));
|
|
109
|
+
console.log(chalk.gray("- ") + chalk.yellow(`enable plugin ${pluginId}`));
|
|
110
|
+
console.log("\nDry run: nothing executed.");
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (!flags.yes) {
|
|
115
|
+
const { ok } = await prompt([
|
|
116
|
+
{
|
|
117
|
+
type: "confirm",
|
|
118
|
+
name: "ok",
|
|
119
|
+
message: `Enable plugin ${pluginId} in ${CONFIG_PATH}?`,
|
|
120
|
+
default: true,
|
|
121
|
+
},
|
|
122
|
+
]);
|
|
123
|
+
if (!ok) return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
enabled.add(pluginId);
|
|
127
|
+
saveConfig({ plugins: Array.from(enabled) });
|
|
128
|
+
console.log(chalk.green(`\n✓ Enabled plugin: ${pluginId}`));
|
|
129
|
+
console.log(chalk.dim(`Config: ${CONFIG_PATH}`));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
throw new Error(
|
|
134
|
+
`Unknown plugin subcommand: ${sub}. Try: projectcli plugin list | projectcli plugin install <id>`
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
module.exports = {
|
|
139
|
+
runPlugin,
|
|
140
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
const { getEnabledPlugins, tryLoadPlugin } = require("./manager");
|
|
2
|
+
|
|
3
|
+
function loadEnabledPlugins(effectiveConfig) {
|
|
4
|
+
const enabled = getEnabledPlugins(effectiveConfig);
|
|
5
|
+
const plugins = [];
|
|
6
|
+
const errors = [];
|
|
7
|
+
|
|
8
|
+
for (const id of enabled) {
|
|
9
|
+
const res = tryLoadPlugin(id);
|
|
10
|
+
if (res.ok) {
|
|
11
|
+
plugins.push({ id, module: res.module });
|
|
12
|
+
} else {
|
|
13
|
+
errors.push({ id, error: res.error || "Failed to load plugin" });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return { plugins, errors };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getPluginPresets(effectiveConfig) {
|
|
21
|
+
const { plugins } = loadEnabledPlugins(effectiveConfig);
|
|
22
|
+
const out = [];
|
|
23
|
+
|
|
24
|
+
for (const p of plugins) {
|
|
25
|
+
const mod = p.module || {};
|
|
26
|
+
const presets = mod.presets;
|
|
27
|
+
if (!presets) continue;
|
|
28
|
+
|
|
29
|
+
if (Array.isArray(presets)) {
|
|
30
|
+
for (const preset of presets) {
|
|
31
|
+
if (preset && typeof preset.id === "string") {
|
|
32
|
+
out.push({ ...preset, pluginId: p.id });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (typeof presets === "object") {
|
|
39
|
+
for (const key of Object.keys(presets)) {
|
|
40
|
+
const preset = presets[key];
|
|
41
|
+
if (!preset) continue;
|
|
42
|
+
const id = typeof preset.id === "string" ? preset.id : key;
|
|
43
|
+
if (!id) continue;
|
|
44
|
+
out.push({ ...preset, id, pluginId: p.id });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getPluginRegistryAdditions(effectiveConfig) {
|
|
53
|
+
const { plugins } = loadEnabledPlugins(effectiveConfig);
|
|
54
|
+
const out = [];
|
|
55
|
+
|
|
56
|
+
for (const p of plugins) {
|
|
57
|
+
const mod = p.module || {};
|
|
58
|
+
const reg = mod.registry;
|
|
59
|
+
if (!reg) continue;
|
|
60
|
+
|
|
61
|
+
// Supported shapes:
|
|
62
|
+
// 1) registry: { "Language": { "Framework": generator, ... }, ... }
|
|
63
|
+
// 2) registry: { languages: { ... } }
|
|
64
|
+
const languages =
|
|
65
|
+
reg.languages && typeof reg.languages === "object" ? reg.languages : reg;
|
|
66
|
+
if (!languages || typeof languages !== "object") continue;
|
|
67
|
+
|
|
68
|
+
out.push({ pluginId: p.id, languages });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getPluginDoctorChecks(effectiveConfig) {
|
|
75
|
+
const { plugins } = loadEnabledPlugins(effectiveConfig);
|
|
76
|
+
const out = [];
|
|
77
|
+
|
|
78
|
+
for (const p of plugins) {
|
|
79
|
+
const mod = p.module || {};
|
|
80
|
+
|
|
81
|
+
const checks = Array.isArray(mod.doctorChecks)
|
|
82
|
+
? mod.doctorChecks
|
|
83
|
+
: Array.isArray(mod.doctor?.checks)
|
|
84
|
+
? mod.doctor.checks
|
|
85
|
+
: [];
|
|
86
|
+
|
|
87
|
+
for (const check of checks) {
|
|
88
|
+
if (!check || typeof check.id !== "string") continue;
|
|
89
|
+
out.push({ ...check, pluginId: p.id });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
module.exports = {
|
|
97
|
+
loadEnabledPlugins,
|
|
98
|
+
getPluginPresets,
|
|
99
|
+
getPluginRegistryAdditions,
|
|
100
|
+
getPluginDoctorChecks,
|
|
101
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
function uniqStrings(items) {
|
|
2
|
+
const out = [];
|
|
3
|
+
const seen = new Set();
|
|
4
|
+
for (const v of items || []) {
|
|
5
|
+
if (typeof v !== "string") continue;
|
|
6
|
+
const s = v.trim();
|
|
7
|
+
if (!s) continue;
|
|
8
|
+
if (seen.has(s)) continue;
|
|
9
|
+
seen.add(s);
|
|
10
|
+
out.push(s);
|
|
11
|
+
}
|
|
12
|
+
return out;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getEnabledPlugins(effectiveConfig) {
|
|
16
|
+
const fromConfig = Array.isArray(effectiveConfig?.plugins)
|
|
17
|
+
? effectiveConfig.plugins
|
|
18
|
+
: [];
|
|
19
|
+
return uniqStrings(fromConfig);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function tryLoadPlugin(pluginId) {
|
|
23
|
+
try {
|
|
24
|
+
// Plugins are expected to be resolvable via Node resolution.
|
|
25
|
+
// This command only enables/disables plugins in config; it does not install packages.
|
|
26
|
+
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
27
|
+
const mod = require(pluginId);
|
|
28
|
+
return { ok: true, module: mod, error: null };
|
|
29
|
+
} catch (err) {
|
|
30
|
+
const message = err && err.message ? err.message : String(err);
|
|
31
|
+
return { ok: false, module: null, error: message };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = {
|
|
36
|
+
getEnabledPlugins,
|
|
37
|
+
tryLoadPlugin,
|
|
38
|
+
};
|
package/src/preflight.js
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
const { spawn } = require("node:child_process");
|
|
2
2
|
|
|
3
|
+
function getInstallHint(binary) {
|
|
4
|
+
const bin = String(binary || "").toLowerCase();
|
|
5
|
+
if (bin === "git") return "Install Git: https://git-scm.com/downloads";
|
|
6
|
+
if (bin === "node" || bin === "npm")
|
|
7
|
+
return "Install Node.js (includes npm): https://nodejs.org/en/download";
|
|
8
|
+
if (bin === "pnpm") return "Install pnpm: https://pnpm.io/installation";
|
|
9
|
+
if (bin === "yarn")
|
|
10
|
+
return "Install Yarn: https://yarnpkg.com/getting-started/install";
|
|
11
|
+
if (bin === "bun") return "Install Bun: https://bun.sh/docs/installation";
|
|
12
|
+
if (bin === "cargo" || bin === "rustc")
|
|
13
|
+
return "Install Rust: https://rustup.rs";
|
|
14
|
+
if (bin === "go") return "Install Go: https://go.dev/dl/";
|
|
15
|
+
if (bin === "python" || bin === "python3")
|
|
16
|
+
return "Install Python: https://www.python.org/downloads/";
|
|
17
|
+
if (bin === "poetry")
|
|
18
|
+
return "Install Poetry: https://python-poetry.org/docs/#installation";
|
|
19
|
+
if (bin === "php") return "Install PHP: https://www.php.net/downloads";
|
|
20
|
+
if (bin === "dotnet")
|
|
21
|
+
return "Install .NET SDK: https://dotnet.microsoft.com/download";
|
|
22
|
+
if (bin === "java" || bin === "javac")
|
|
23
|
+
return "Install a JDK: https://adoptium.net/";
|
|
24
|
+
if (bin === "dart") return "Install Dart SDK: https://dart.dev/get-dart";
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
3
28
|
function checkBinary(binary, args = ["--version"]) {
|
|
4
29
|
return new Promise((resolve) => {
|
|
5
30
|
const child = spawn(binary, args, {
|
|
@@ -22,4 +47,5 @@ function checkBinaries(binaries) {
|
|
|
22
47
|
module.exports = {
|
|
23
48
|
checkBinary,
|
|
24
49
|
checkBinaries,
|
|
50
|
+
getInstallHint,
|
|
25
51
|
};
|
package/src/preset.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const chalk = require("chalk");
|
|
2
|
+
|
|
3
|
+
const { loadConfig, saveConfig, CONFIG_PATH } = require("./config");
|
|
4
|
+
const { listPresets, getPreset } = require("./presets");
|
|
5
|
+
|
|
6
|
+
function printPresetList(effectiveConfig) {
|
|
7
|
+
console.log(chalk.bold("\nPresets:"));
|
|
8
|
+
for (const id of listPresets(effectiveConfig)) {
|
|
9
|
+
const p = getPreset(id, effectiveConfig);
|
|
10
|
+
console.log(`- ${p.id}: ${chalk.dim(p.label)}`);
|
|
11
|
+
}
|
|
12
|
+
console.log("");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async function runPreset({ prompt, argv, effectiveConfig }) {
|
|
16
|
+
const args = Array.isArray(argv) ? argv : [];
|
|
17
|
+
const sub = args[0];
|
|
18
|
+
|
|
19
|
+
if (!sub || sub === "list") {
|
|
20
|
+
printPresetList(effectiveConfig);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (sub === "use") {
|
|
25
|
+
const presetArg = args[1];
|
|
26
|
+
const preset = getPreset(presetArg, effectiveConfig);
|
|
27
|
+
|
|
28
|
+
const config = loadConfig();
|
|
29
|
+
|
|
30
|
+
if (!presetArg) {
|
|
31
|
+
const { picked } = await prompt([
|
|
32
|
+
{
|
|
33
|
+
type: "list",
|
|
34
|
+
name: "picked",
|
|
35
|
+
message: "Choose a preset:",
|
|
36
|
+
choices: listPresets(effectiveConfig),
|
|
37
|
+
default: config.preset || preset.id,
|
|
38
|
+
},
|
|
39
|
+
]);
|
|
40
|
+
saveConfig({ preset: picked });
|
|
41
|
+
console.log(chalk.green(`\n✓ Preset set to: ${picked}`));
|
|
42
|
+
console.log(chalk.dim(`Config: ${CONFIG_PATH}`));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
saveConfig({ preset: preset.id });
|
|
47
|
+
console.log(chalk.green(`\n✓ Preset set to: ${preset.id}`));
|
|
48
|
+
console.log(chalk.dim(`Config: ${CONFIG_PATH}`));
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
throw new Error(
|
|
53
|
+
`Unknown preset subcommand: ${sub}. Try: projectcli preset list | projectcli preset use <name>`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
module.exports = {
|
|
58
|
+
runPreset,
|
|
59
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
const PRESETS = {
|
|
2
|
+
minimal: {
|
|
3
|
+
id: "minimal",
|
|
4
|
+
label: "Minimal",
|
|
5
|
+
defaults: {
|
|
6
|
+
packageManager: null,
|
|
7
|
+
js: {
|
|
8
|
+
formatter: false,
|
|
9
|
+
linter: false,
|
|
10
|
+
tests: false,
|
|
11
|
+
},
|
|
12
|
+
extras: {
|
|
13
|
+
ci: false,
|
|
14
|
+
docker: false,
|
|
15
|
+
devcontainer: false,
|
|
16
|
+
license: true,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
startup: {
|
|
22
|
+
id: "startup",
|
|
23
|
+
label: "Startup",
|
|
24
|
+
defaults: {
|
|
25
|
+
packageManager: "pnpm",
|
|
26
|
+
js: {
|
|
27
|
+
formatter: true,
|
|
28
|
+
linter: true,
|
|
29
|
+
tests: true,
|
|
30
|
+
},
|
|
31
|
+
extras: {
|
|
32
|
+
ci: true,
|
|
33
|
+
docker: true,
|
|
34
|
+
devcontainer: false,
|
|
35
|
+
license: true,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
strict: {
|
|
41
|
+
id: "strict",
|
|
42
|
+
label: "Strict",
|
|
43
|
+
defaults: {
|
|
44
|
+
packageManager: "pnpm",
|
|
45
|
+
js: {
|
|
46
|
+
formatter: true,
|
|
47
|
+
linter: true,
|
|
48
|
+
tests: true,
|
|
49
|
+
},
|
|
50
|
+
extras: {
|
|
51
|
+
ci: true,
|
|
52
|
+
docker: true,
|
|
53
|
+
devcontainer: true,
|
|
54
|
+
license: true,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
enterprise: {
|
|
60
|
+
id: "enterprise",
|
|
61
|
+
label: "Enterprise",
|
|
62
|
+
defaults: {
|
|
63
|
+
packageManager: "pnpm",
|
|
64
|
+
js: {
|
|
65
|
+
formatter: true,
|
|
66
|
+
linter: true,
|
|
67
|
+
tests: true,
|
|
68
|
+
},
|
|
69
|
+
extras: {
|
|
70
|
+
ci: true,
|
|
71
|
+
docker: true,
|
|
72
|
+
devcontainer: true,
|
|
73
|
+
license: true,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const { getPluginPresets } = require("../plugins/contributions");
|
|
80
|
+
|
|
81
|
+
function getAllPresets(effectiveConfig) {
|
|
82
|
+
const out = { ...PRESETS };
|
|
83
|
+
|
|
84
|
+
const pluginPresets = getPluginPresets(effectiveConfig);
|
|
85
|
+
for (const p of pluginPresets) {
|
|
86
|
+
if (!p || typeof p.id !== "string") continue;
|
|
87
|
+
const id = p.id.trim().toLowerCase();
|
|
88
|
+
if (!id) continue;
|
|
89
|
+
// Plugin presets can extend the catalog; do not override built-ins.
|
|
90
|
+
if (out[id]) continue;
|
|
91
|
+
|
|
92
|
+
out[id] = {
|
|
93
|
+
id,
|
|
94
|
+
label: typeof p.label === "string" ? p.label : id,
|
|
95
|
+
defaults: p.defaults && typeof p.defaults === "object" ? p.defaults : {},
|
|
96
|
+
pluginId: p.pluginId,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function listPresets(effectiveConfig) {
|
|
104
|
+
return Object.keys(getAllPresets(effectiveConfig));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function getPreset(presetId, effectiveConfig) {
|
|
108
|
+
const all = getAllPresets(effectiveConfig);
|
|
109
|
+
if (typeof presetId !== "string") return all.startup || PRESETS.startup;
|
|
110
|
+
const key = presetId.trim().toLowerCase();
|
|
111
|
+
return all[key] || all.startup || PRESETS.startup;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function describePreset(presetId, effectiveConfig) {
|
|
115
|
+
const p = getPreset(presetId, effectiveConfig);
|
|
116
|
+
return { id: p.id, label: p.label, defaults: p.defaults };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
module.exports = {
|
|
120
|
+
PRESETS,
|
|
121
|
+
listPresets,
|
|
122
|
+
getPreset,
|
|
123
|
+
describePreset,
|
|
124
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// V3 registry wrapper.
|
|
2
|
+
// Combines the legacy built-in registry with plugin-provided generators.
|
|
3
|
+
|
|
4
|
+
const legacy = require("../registry_legacy");
|
|
5
|
+
const { getPluginRegistryAdditions } = require("../plugins/contributions");
|
|
6
|
+
|
|
7
|
+
function normalizeLanguageName(name) {
|
|
8
|
+
return String(name || "").trim();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function normalizeFrameworkName(name) {
|
|
12
|
+
return String(name || "").trim();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getPluginRegistryMap(effectiveConfig) {
|
|
16
|
+
const additions = getPluginRegistryAdditions(effectiveConfig);
|
|
17
|
+
const out = {};
|
|
18
|
+
|
|
19
|
+
for (const add of additions) {
|
|
20
|
+
const languages = add.languages;
|
|
21
|
+
if (!languages || typeof languages !== "object") continue;
|
|
22
|
+
|
|
23
|
+
for (const langKey of Object.keys(languages)) {
|
|
24
|
+
const langName = normalizeLanguageName(langKey);
|
|
25
|
+
if (!langName) continue;
|
|
26
|
+
|
|
27
|
+
const frameworks = languages[langKey];
|
|
28
|
+
if (!frameworks || typeof frameworks !== "object") continue;
|
|
29
|
+
|
|
30
|
+
if (!out[langName]) out[langName] = {};
|
|
31
|
+
|
|
32
|
+
for (const fwKey of Object.keys(frameworks)) {
|
|
33
|
+
const fwName = normalizeFrameworkName(fwKey);
|
|
34
|
+
if (!fwName) continue;
|
|
35
|
+
const gen = frameworks[fwKey];
|
|
36
|
+
if (!gen) continue;
|
|
37
|
+
|
|
38
|
+
// Do not override existing plugin framework entries.
|
|
39
|
+
if (!out[langName][fwName]) {
|
|
40
|
+
out[langName][fwName] = gen;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getLanguages(effectiveConfig) {
|
|
50
|
+
const base = legacy.getLanguages();
|
|
51
|
+
const pluginMap = getPluginRegistryMap(effectiveConfig);
|
|
52
|
+
|
|
53
|
+
const extra = Object.keys(pluginMap);
|
|
54
|
+
const merged = [...base];
|
|
55
|
+
for (const lang of extra) {
|
|
56
|
+
if (!merged.includes(lang)) merged.push(lang);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return merged;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function getFrameworks(language, effectiveConfig) {
|
|
63
|
+
const lang = normalizeLanguageName(language);
|
|
64
|
+
const base = legacy.getFrameworks(lang);
|
|
65
|
+
const pluginMap = getPluginRegistryMap(effectiveConfig);
|
|
66
|
+
const pluginFrameworks = pluginMap[lang] ? Object.keys(pluginMap[lang]) : [];
|
|
67
|
+
|
|
68
|
+
const merged = [...base];
|
|
69
|
+
for (const fw of pluginFrameworks) {
|
|
70
|
+
if (!merged.includes(fw)) merged.push(fw);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return merged;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function getGenerator(language, framework, effectiveConfig) {
|
|
77
|
+
const lang = normalizeLanguageName(language);
|
|
78
|
+
const fw = normalizeFrameworkName(framework);
|
|
79
|
+
|
|
80
|
+
const base = legacy.getGenerator(lang, fw);
|
|
81
|
+
if (base) return base;
|
|
82
|
+
|
|
83
|
+
const pluginMap = getPluginRegistryMap(effectiveConfig);
|
|
84
|
+
return pluginMap[lang]?.[fw] || null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = {
|
|
88
|
+
getLanguages,
|
|
89
|
+
getFrameworks,
|
|
90
|
+
getGenerator,
|
|
91
|
+
};
|