@alauda/doom 0.5.1 → 0.5.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/lib/cli/new.js +22 -3
- package/package.json +2 -2
package/lib/cli/new.js
CHANGED
|
@@ -12,8 +12,7 @@ import { resolveStaticConfig } from '../utils/helpers.js';
|
|
|
12
12
|
export const DEFAULT_PATH = 'templates/scaffolding.yaml';
|
|
13
13
|
const scaffoldingTemplates = {
|
|
14
14
|
'product-doc': {
|
|
15
|
-
repo: 'alauda/product-doc-guide',
|
|
16
|
-
branches: ['master', 'feat/templates'],
|
|
15
|
+
repo: 'alauda-public/product-doc-guide',
|
|
17
16
|
},
|
|
18
17
|
};
|
|
19
18
|
const scaffoldingsFolder = path.resolve(os.homedir(), '.doom/scaffoldings');
|
|
@@ -58,6 +57,7 @@ const resolveScaffoldings = async (name, force) => {
|
|
|
58
57
|
}
|
|
59
58
|
const git = simpleGit(repoFolder);
|
|
60
59
|
if (!created) {
|
|
60
|
+
logger.info(`Cloning scaffolding template \`${cyan(name)}\` repository...`);
|
|
61
61
|
await git.clone(/^((\w+):)?\/\//.test(repo)
|
|
62
62
|
? repo
|
|
63
63
|
: `https://gitlab-ce.alauda.cn/${repo}`, repoFolder, ['--depth', '1']);
|
|
@@ -78,9 +78,11 @@ const resolveScaffoldings = async (name, force) => {
|
|
|
78
78
|
const options = ['--depth', '1', '--force'];
|
|
79
79
|
for (const branch of branches) {
|
|
80
80
|
if (branch === currentBranch) {
|
|
81
|
-
|
|
81
|
+
logger.info(`Pulling latest changes from branch \`${cyan(branch)}\`...`);
|
|
82
|
+
await git.pull([...options, '--rebase']);
|
|
82
83
|
}
|
|
83
84
|
else {
|
|
85
|
+
logger.info(`Switching to branch \`${cyan(branch)}\`...`);
|
|
84
86
|
await git.fetch('origin', `${branch}:${branch}`, options);
|
|
85
87
|
await git.checkout((currentBranch = branch));
|
|
86
88
|
}
|
|
@@ -118,6 +120,7 @@ program
|
|
|
118
120
|
}
|
|
119
121
|
const { base, scaffoldings } = (await resolveScaffoldings(name, force)) || {};
|
|
120
122
|
if (!scaffoldings) {
|
|
123
|
+
logger.error(`Unable to resolve any scaffoldings, if you are sure the template \`${magenta(name)}\` exists, try to use the \`--force\` option, or event remove the local cache at ${magenta(path.resolve(scaffoldingsFolder, name))} and try again`);
|
|
121
124
|
return;
|
|
122
125
|
}
|
|
123
126
|
if (!type) {
|
|
@@ -140,6 +143,7 @@ program
|
|
|
140
143
|
for (const param of scaffolding.parameters || []) {
|
|
141
144
|
parameters[param.name] = await prompts[param.type](param.options);
|
|
142
145
|
}
|
|
146
|
+
logger.start('Generating scaffolding...');
|
|
143
147
|
for (const layout of scaffolding.layout || []) {
|
|
144
148
|
const source = path.resolve(base, render(layout.source, { parameters }));
|
|
145
149
|
const target = path.resolve(render(layout.target, { parameters }));
|
|
@@ -159,9 +163,17 @@ program
|
|
|
159
163
|
break;
|
|
160
164
|
}
|
|
161
165
|
case 'folder': {
|
|
166
|
+
const dirents = await fs.readdir(source, {
|
|
167
|
+
recursive: true,
|
|
168
|
+
withFileTypes: true,
|
|
169
|
+
});
|
|
170
|
+
const files = new Set(dirents
|
|
171
|
+
.filter((d) => d.isFile())
|
|
172
|
+
.map((d) => path.relative(source, path.resolve(d.parentPath, d.name))));
|
|
162
173
|
for (const matcher of layout.matchers || []) {
|
|
163
174
|
const matched = await glob(matcher.match.map((m) => render(m, { parameters })), { cwd: source });
|
|
164
175
|
for (const file of matched) {
|
|
176
|
+
files.delete(file);
|
|
165
177
|
await handleTemplateFile({
|
|
166
178
|
source: path.resolve(source, file),
|
|
167
179
|
target: path.resolve(target, file.endsWith('.ejs') ? file.slice(0, -4) : file),
|
|
@@ -171,10 +183,17 @@ program
|
|
|
171
183
|
});
|
|
172
184
|
}
|
|
173
185
|
}
|
|
186
|
+
for (const file of files) {
|
|
187
|
+
await handleTemplateFile({
|
|
188
|
+
source: path.resolve(source, file),
|
|
189
|
+
target: path.resolve(target, file),
|
|
190
|
+
});
|
|
191
|
+
}
|
|
174
192
|
break;
|
|
175
193
|
}
|
|
176
194
|
}
|
|
177
195
|
}
|
|
196
|
+
logger.success('Scaffolding generated successfully!');
|
|
178
197
|
})
|
|
179
198
|
.parseAsync(process.argv)
|
|
180
199
|
.catch((err) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
6
|
"repository": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"packageManager": "yarn@4.5.0",
|
|
11
11
|
"engines": {
|
|
12
|
-
"node": ">=18.
|
|
12
|
+
"node": ">=18.20.0 <20 || >=20.1.0"
|
|
13
13
|
},
|
|
14
14
|
"bin": "lib/cli/index.js",
|
|
15
15
|
"exports": {
|