@alauda/doom 0.5.2 → 0.5.4

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/index.js CHANGED
@@ -27,6 +27,7 @@ program
27
27
  })
28
28
  .option('-c, --config [config]', 'Specify the path to the config file')
29
29
  .option('-v <version>', 'Specify the version of the documentation')
30
+ .option('-p, --prefix <prefix>', 'Specify the prefix of the documentation base')
30
31
  .command('dev', { isDefault: true })
31
32
  .description('Start the development server')
32
33
  .argument('[root]', 'Root directory of the documentation')
@@ -36,9 +37,9 @@ program
36
37
  setNodeEnv('development');
37
38
  let devServer;
38
39
  let cliWatcher;
39
- const { config: configFile, v: version, ...server } = this.optsWithGlobals();
40
+ const { config: configFile, v: version, prefix, ...server } = this.optsWithGlobals();
40
41
  const startDevServer = async () => {
41
- const { config, filepath } = await loadConfig(root, configFile, version);
42
+ const { config, filepath } = await loadConfig(root, configFile, prefix, version);
42
43
  const docDirectory = config.root;
43
44
  try {
44
45
  devServer = await dev({
@@ -101,8 +102,8 @@ program
101
102
  .argument('[root]', 'Root directory of the documentation')
102
103
  .action(async function (root) {
103
104
  setNodeEnv('production');
104
- const { config: configFile, v: version } = this.optsWithGlobals();
105
- const { config } = await loadConfig(root, configFile, version);
105
+ const { config: configFile, prefix, v: version, } = this.optsWithGlobals();
106
+ const { config } = await loadConfig(root, configFile, prefix, version);
106
107
  const docDirectory = config.root;
107
108
  await build({
108
109
  config,
@@ -119,8 +120,8 @@ program
119
120
  .option('--host [host]', 'Host name')
120
121
  .action(async function (root) {
121
122
  setNodeEnv('production');
122
- const { config: configFile, v: version, ...server } = this.optsWithGlobals();
123
- const { config } = await loadConfig(root, configFile, version);
123
+ const { config: configFile, prefix, v: version, ...server } = this.optsWithGlobals();
124
+ const { config } = await loadConfig(root, configFile, prefix, version);
124
125
  await serve({
125
126
  config,
126
127
  ...server,
@@ -1,5 +1,5 @@
1
1
  import { type DoomConfig } from '../utils/index.js';
2
- export declare function loadConfig(root?: string, configFile?: string, version?: string): Promise<{
2
+ export declare function loadConfig(root?: string, configFile?: string, prefix?: string, version?: string): Promise<{
3
3
  config: DoomConfig;
4
4
  filepath?: string;
5
5
  }>;
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { nodeTypes } from '@mdx-js/mdx';
4
- import { addLeadingSlash, addTrailingSlash, removeLeadingSlash, removeTrailingSlash, } from '@rspress/core';
4
+ import { addLeadingSlash, addTrailingSlash, normalizeSlash, removeLeadingSlash, removeTrailingSlash, } from '@rspress/core';
5
5
  import { pluginPreview } from '@rspress/plugin-preview';
6
6
  import { logger } from '@rspress/shared/logger';
7
7
  import { transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight, transformerRemoveNotationEscape, } from '@shikijs/transformers';
@@ -100,7 +100,7 @@ const getCommonConfig = async (config, version) => {
100
100
  const findConfig = (basePath) => {
101
101
  return DEFAULT_EXTENSIONS.map((ext) => basePath + ext).find(fs.existsSync);
102
102
  };
103
- export async function loadConfig(root, configFile, version) {
103
+ export async function loadConfig(root, configFile, prefix, version) {
104
104
  let configFilePath;
105
105
  if (configFile) {
106
106
  configFilePath = path.resolve(configFile);
@@ -156,6 +156,9 @@ export async function loadConfig(root, configFile, version) {
156
156
  base = removeTrailingSlash(base) + `/${normalizedVersion}`;
157
157
  }
158
158
  mergedConfig.base = base = addTrailingSlash(base);
159
+ if (prefix) {
160
+ mergedConfig.base = normalizeSlash(prefix) + base;
161
+ }
159
162
  mergedConfig.root = resolveDocRoot(CWD, root, mergedConfig.root);
160
163
  let ensureDefaultLogo = false;
161
164
  if (!mergedConfig.logo) {
@@ -190,7 +193,7 @@ export async function loadConfig(root, configFile, version) {
190
193
  mergedConfig.outDir = `dist${normalizedVersion === 'unversioned' ? `/unversioned${base}` : base}`;
191
194
  }
192
195
  if (mergedConfig.builderConfig?.server?.open === true) {
193
- mergedConfig.builderConfig.server.open = base;
196
+ mergedConfig.builderConfig.server.open = mergedConfig.base;
194
197
  }
195
198
  return {
196
199
  config: mergedConfig,
package/lib/cli/new.js CHANGED
@@ -57,6 +57,7 @@ const resolveScaffoldings = async (name, force) => {
57
57
  }
58
58
  const git = simpleGit(repoFolder);
59
59
  if (!created) {
60
+ logger.info(`Cloning scaffolding template \`${cyan(name)}\` repository...`);
60
61
  await git.clone(/^((\w+):)?\/\//.test(repo)
61
62
  ? repo
62
63
  : `https://gitlab-ce.alauda.cn/${repo}`, repoFolder, ['--depth', '1']);
@@ -77,9 +78,11 @@ const resolveScaffoldings = async (name, force) => {
77
78
  const options = ['--depth', '1', '--force'];
78
79
  for (const branch of branches) {
79
80
  if (branch === currentBranch) {
80
- await git.pull([...options, '--no-rebase']);
81
+ logger.info(`Pulling latest changes from branch \`${cyan(branch)}\`...`);
82
+ await git.pull([...options, '--rebase']);
81
83
  }
82
84
  else {
85
+ logger.info(`Switching to branch \`${cyan(branch)}\`...`);
83
86
  await git.fetch('origin', `${branch}:${branch}`, options);
84
87
  await git.checkout((currentBranch = branch));
85
88
  }
@@ -117,6 +120,7 @@ program
117
120
  }
118
121
  const { base, scaffoldings } = (await resolveScaffoldings(name, force)) || {};
119
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`);
120
124
  return;
121
125
  }
122
126
  if (!type) {
@@ -139,6 +143,7 @@ program
139
143
  for (const param of scaffolding.parameters || []) {
140
144
  parameters[param.name] = await prompts[param.type](param.options);
141
145
  }
146
+ logger.start('Generating scaffolding...');
142
147
  for (const layout of scaffolding.layout || []) {
143
148
  const source = path.resolve(base, render(layout.source, { parameters }));
144
149
  const target = path.resolve(render(layout.target, { parameters }));
@@ -158,9 +163,17 @@ program
158
163
  break;
159
164
  }
160
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))));
161
173
  for (const matcher of layout.matchers || []) {
162
174
  const matched = await glob(matcher.match.map((m) => render(m, { parameters })), { cwd: source });
163
175
  for (const file of matched) {
176
+ files.delete(file);
164
177
  await handleTemplateFile({
165
178
  source: path.resolve(source, file),
166
179
  target: path.resolve(target, file.endsWith('.ejs') ? file.slice(0, -4) : file),
@@ -170,10 +183,17 @@ program
170
183
  });
171
184
  }
172
185
  }
186
+ for (const file of files) {
187
+ await handleTemplateFile({
188
+ source: path.resolve(source, file),
189
+ target: path.resolve(target, file),
190
+ });
191
+ }
173
192
  break;
174
193
  }
175
194
  }
176
195
  }
196
+ logger.success('Scaffolding generated successfully!');
177
197
  })
178
198
  .parseAsync(process.argv)
179
199
  .catch((err) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
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.17.0 <20 || >=20.1.0"
12
+ "node": ">=18.20.0 <20 || >=20.1.0"
13
13
  },
14
14
  "bin": "lib/cli/index.js",
15
15
  "exports": {