create-rspress 0.0.10 → 0.0.12

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/dist/index.js CHANGED
@@ -2733,7 +2733,7 @@ var require_dist = __commonJS({
2733
2733
  });
2734
2734
  };
2735
2735
  }
2736
- var prompts2 = require_prompts();
2736
+ var prompts3 = require_prompts();
2737
2737
  var passOn = ["suggest", "format", "onState", "validate", "onRender", "type"];
2738
2738
  var noop = () => {
2739
2739
  };
@@ -2786,7 +2786,7 @@ var require_dist = __commonJS({
2786
2786
  var _question2 = question;
2787
2787
  name = _question2.name;
2788
2788
  type = _question2.type;
2789
- if (prompts2[type] === void 0) {
2789
+ if (prompts3[type] === void 0) {
2790
2790
  throw new Error(`prompt type (${type}) is not defined`);
2791
2791
  }
2792
2792
  if (override2[question.name] !== void 0) {
@@ -2797,7 +2797,7 @@ var require_dist = __commonJS({
2797
2797
  }
2798
2798
  }
2799
2799
  try {
2800
- answer = prompt._injected ? getInjectedAnswer(prompt._injected, question.initial) : yield prompts2[type](question);
2800
+ answer = prompt._injected ? getInjectedAnswer(prompt._injected, question.initial) : yield prompts3[type](question);
2801
2801
  answers[name] = answer = yield getFormattedAnswer(question, answer, true);
2802
2802
  quit = yield onSubmit(question, answer, answers);
2803
2803
  } catch (err) {
@@ -2830,7 +2830,7 @@ var require_dist = __commonJS({
2830
2830
  }
2831
2831
  module2.exports = Object.assign(prompt, {
2832
2832
  prompt,
2833
- prompts: prompts2,
2833
+ prompts: prompts3,
2834
2834
  inject,
2835
2835
  override
2836
2836
  });
@@ -4997,7 +4997,7 @@ var require_prompts2 = __commonJS({
4997
4997
  var require_lib = __commonJS({
4998
4998
  "../../node_modules/.pnpm/prompts@2.4.1/node_modules/prompts/lib/index.js"(exports, module2) {
4999
4999
  "use strict";
5000
- var prompts2 = require_prompts2();
5000
+ var prompts3 = require_prompts2();
5001
5001
  var passOn = ["suggest", "format", "onState", "validate", "onRender", "type"];
5002
5002
  var noop = () => {
5003
5003
  };
@@ -5031,7 +5031,7 @@ var require_lib = __commonJS({
5031
5031
  throw new Error("prompt message is required");
5032
5032
  }
5033
5033
  ({ name, type } = question);
5034
- if (prompts2[type] === void 0) {
5034
+ if (prompts3[type] === void 0) {
5035
5035
  throw new Error(`prompt type (${type}) is not defined`);
5036
5036
  }
5037
5037
  if (override2[question.name] !== void 0) {
@@ -5042,7 +5042,7 @@ var require_lib = __commonJS({
5042
5042
  }
5043
5043
  }
5044
5044
  try {
5045
- answer = prompt._injected ? getInjectedAnswer(prompt._injected, question.initial) : await prompts2[type](question);
5045
+ answer = prompt._injected ? getInjectedAnswer(prompt._injected, question.initial) : await prompts3[type](question);
5046
5046
  answers[name] = answer = await getFormattedAnswer(question, answer, true);
5047
5047
  quit = await onSubmit(question, answer, answers);
5048
5048
  } catch (err) {
@@ -5066,7 +5066,7 @@ var require_lib = __commonJS({
5066
5066
  function override(answers) {
5067
5067
  prompt._override = Object.assign({}, answers);
5068
5068
  }
5069
- module2.exports = Object.assign(prompt, { prompt, prompts: prompts2, inject, override });
5069
+ module2.exports = Object.assign(prompt, { prompt, prompts: prompts3, inject, override });
5070
5070
  }
5071
5071
  });
5072
5072
 
@@ -8065,12 +8065,13 @@ var CAC = class extends import_events.EventEmitter {
8065
8065
  var cac = (name = "") => new CAC(name);
8066
8066
 
8067
8067
  // src/index.ts
8068
- var import_prompts = __toESM(require_prompts3());
8068
+ var import_prompts2 = __toESM(require_prompts3());
8069
8069
  var import_fs_extra2 = __toESM(require_lib2());
8070
8070
 
8071
8071
  // src/utils.ts
8072
8072
  var import_path = __toESM(require("path"));
8073
8073
  var import_fs_extra = __toESM(require_lib2());
8074
+ var import_prompts = __toESM(require_prompts3());
8074
8075
  async function copyFolder(src, dest) {
8075
8076
  const renameFiles = {
8076
8077
  _gitignore: ".gitignore"
@@ -8087,6 +8088,23 @@ async function copyFolder(src, dest) {
8087
8088
  }
8088
8089
  }
8089
8090
  }
8091
+ function replaceVar(str, data, decorator = "") {
8092
+ return str.replace(/<%=\s*(.*?)\s*%>/g, (_, key) => {
8093
+ const value = data[key.trim()];
8094
+ return `${decorator}${value}${decorator}`;
8095
+ });
8096
+ }
8097
+ async function renderFile(fileSrc, templateDir, targetRoot, data) {
8098
+ const templateFilePath = import_path.default.resolve(templateDir, fileSrc);
8099
+ const targetPath = import_path.default.resolve(targetRoot, fileSrc);
8100
+ const file = await import_fs_extra.default.readFile(templateFilePath, "utf-8");
8101
+ const decorator = templateFilePath.endsWith(".ts") ? "'" : "";
8102
+ const output = replaceVar(file, data, decorator);
8103
+ if (!import_fs_extra.default.existsSync(targetRoot)) {
8104
+ await import_fs_extra.default.mkdir(targetRoot, { recursive: true });
8105
+ }
8106
+ await import_fs_extra.default.writeFile(targetPath, output);
8107
+ }
8090
8108
  function getPkgManager() {
8091
8109
  const ua = process.env.npm_config_user_agent;
8092
8110
  if (!ua) {
@@ -8099,13 +8117,40 @@ function getPkgManager() {
8099
8117
  function formatTargetDir(targetDir) {
8100
8118
  return targetDir.trim().replace(/\/+$/g, "");
8101
8119
  }
8120
+ function initSitePrompts(options) {
8121
+ const initOptionEvent = (option) => {
8122
+ option.onState = (state) => {
8123
+ const value = state.value || option.initial;
8124
+ option.value = option.formatFn?.(value) || value;
8125
+ };
8126
+ return option;
8127
+ };
8128
+ options.forEach(initOptionEvent);
8129
+ return (0, import_prompts.default)(options);
8130
+ }
8102
8131
 
8103
8132
  // src/index.ts
8104
8133
  var cli = cac("create-rspress").help();
8105
8134
  cli.command("", "Create a new rspress site").action(async () => {
8135
+ const siteOptions = [
8136
+ {
8137
+ name: "siteTitle",
8138
+ type: "text",
8139
+ message: "Site Title",
8140
+ initial: "Rspress",
8141
+ value: ""
8142
+ },
8143
+ {
8144
+ name: "siteDesc",
8145
+ type: "text",
8146
+ message: "Site Description",
8147
+ initial: "Rspack-based Static Site Generator",
8148
+ value: ""
8149
+ }
8150
+ ];
8106
8151
  const defaultProjectName = "rspress-site";
8107
8152
  let targetDir = defaultProjectName;
8108
- const promptProjectDir = async () => await (0, import_prompts.default)([
8153
+ const promptProjectDir = async () => await (0, import_prompts2.default)([
8109
8154
  {
8110
8155
  type: "text",
8111
8156
  name: "projectDir",
@@ -8125,9 +8170,18 @@ cli.command("", "Create a new rspress site").action(async () => {
8125
8170
  await promptProjectDir();
8126
8171
  root = import_path2.default.resolve(process.cwd(), targetDir);
8127
8172
  }
8173
+ await initSitePrompts(siteOptions);
8128
8174
  await import_fs_extra2.default.mkdir(root, { recursive: true });
8129
8175
  const srcFolder = import_path2.default.resolve(__dirname, "../template");
8130
8176
  await copyFolder(srcFolder, targetDir);
8177
+ const filesToInterpret = ["docs/index.md", "rspress.config.ts"];
8178
+ const siteData = siteOptions.reduce((prev, cur) => {
8179
+ prev[cur.name] = cur.value;
8180
+ return prev;
8181
+ }, {});
8182
+ for (const file of filesToInterpret) {
8183
+ await renderFile(file, targetDir, targetDir, siteData);
8184
+ }
8131
8185
  const pkgManager = getPkgManager();
8132
8186
  console.log("\nDone. Now run:\n");
8133
8187
  console.log(`cd ${targetDir}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-rspress",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "types": "./dist/index.d.ts",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -0,0 +1,16 @@
1
+ [
2
+ {
3
+ "text": "Guide",
4
+ "link": "/guide/",
5
+ "activeMatch": "/guide/"
6
+ },
7
+ {
8
+ "text": "Hello World",
9
+ "link": "/hello/",
10
+ "activeMatch": "/hello/"
11
+ },
12
+ {
13
+ "text": "API",
14
+ "link": "https://rspress.dev/api/index.html"
15
+ }
16
+ ]
File without changes
@@ -0,0 +1,201 @@
1
+ # Markdown & MDX
2
+
3
+ Rspress supports not only Markdown but also [MDX](https://mdxjs.com/), a powerful way to develop content.
4
+
5
+ ## Markdown
6
+
7
+ MDX is a superset of Markdown, which means you can write Markdown files as usual. For example:
8
+
9
+ ```md
10
+ # Hello World
11
+ ```
12
+
13
+ ## Use Component
14
+
15
+ When you want to use React components in Markdown files, you should name your files with `.mdx` extension. For example:
16
+
17
+ ```mdx
18
+ // docs/index.mdx
19
+ import { CustomComponent } from './custom';
20
+
21
+ # Hello World
22
+
23
+ <CustomComponent />
24
+ ```
25
+
26
+ ## Front Matter
27
+
28
+ You can add Front Matter at the beginning of your Markdown file, which is a YAML-formatted object that defines some metadata. For example:
29
+
30
+ ```yaml
31
+ ---
32
+ title: Hello World
33
+ ---
34
+ ```
35
+
36
+ > Note: By default, Rspress uses h1 headings as html headings.
37
+
38
+ You can also access properties defined in Front Matter in the body, for example:
39
+
40
+ ```markdown
41
+ ---
42
+ title: Hello World
43
+ ---
44
+
45
+ # {frontmatter.title}
46
+ ```
47
+
48
+ The previously defined properties will be passed to the component as `frontmatter` properties. So the final output will be:
49
+
50
+ ```html
51
+ <h1>Hello World</h1>
52
+ ```
53
+
54
+ ## Custom Container
55
+
56
+ You can use the `:::` syntax to create custom containers and support custom titles. For example:
57
+
58
+ **Input:**
59
+
60
+ ```markdown
61
+ :::tip
62
+ This is a `block` of type `tip`
63
+ :::
64
+
65
+ :::info
66
+ This is a `block` of type `info`
67
+ :::
68
+
69
+ :::warning
70
+ This is a `block` of type `warning`
71
+ :::
72
+
73
+ :::danger
74
+ This is a `block` of type `danger`
75
+ :::
76
+
77
+ ::: details
78
+ This is a `block` of type `details`
79
+ :::
80
+
81
+ :::tip Custom Title
82
+ This is a `block` of `Custom Title`
83
+ :::
84
+
85
+ :::tip{title="Custom Title"}
86
+ This is a `block` of `Custom Title`
87
+ :::
88
+ ```
89
+
90
+ **Output:**
91
+
92
+ :::tip
93
+ This is a `block` of type `tip`
94
+ :::
95
+
96
+ :::info
97
+ This is a `block` of type `info`
98
+ :::
99
+
100
+ :::warning
101
+ This is a `block` of type `warning`
102
+ :::
103
+
104
+ :::danger
105
+ This is a `block` of type `danger`
106
+ :::
107
+
108
+ ::: details
109
+ This is a `block` of type `details`
110
+ :::
111
+
112
+ :::tip Custom Title
113
+ This is a `block` of `Custom Title`
114
+ :::
115
+
116
+ :::tip{title="Custom Title"}
117
+ This is a `block` of `Custom Title`
118
+ :::
119
+
120
+ ## Code Block
121
+
122
+ ### Basic Usage
123
+
124
+ You can use the \`\`\` syntax to create code blocks and support custom titles. For example:
125
+
126
+ **Input:**
127
+
128
+ ````md
129
+ ```js
130
+ console.log('Hello World');
131
+ ```
132
+
133
+ ```js title="hello.js"
134
+ console.log('Hello World');
135
+ ```
136
+ ````
137
+
138
+ **Output:**
139
+
140
+ ```js
141
+ console.log('Hello World');
142
+ ```
143
+
144
+ ```js title="hello.js"
145
+ console.log('Hello World');
146
+ ```
147
+
148
+ ### Show Line Numbers
149
+
150
+ If you want to display line numbers, you can enable the `showLineNumbers` option in the config file:
151
+
152
+ ```ts title="rspress.config.ts"
153
+ export default {
154
+ // ...
155
+ markdown: {
156
+ showLineNumbers: true,
157
+ },
158
+ };
159
+ ```
160
+
161
+ ### Line Highlighting
162
+
163
+ You can also apply line highlighting and code block title at the same time, for example:
164
+
165
+ **Input:**
166
+
167
+ ````md
168
+ ```js title="hello.js" {1,3-5}
169
+ console.log('Hello World');
170
+
171
+ const a = 1;
172
+
173
+ console.log(a);
174
+
175
+ const b = 2;
176
+
177
+ console.log(b);
178
+ ```
179
+ ````
180
+
181
+ **Ouput:**
182
+
183
+ ```js title="hello.js" {1,3-5}
184
+ console.log('Hello World');
185
+
186
+ const a = 1;
187
+
188
+ console.log(a);
189
+
190
+ const b = 2;
191
+
192
+ console.log(b);
193
+ ```
194
+
195
+ ## Rustify MDX compiler
196
+
197
+ You can enable Rustify MDX compiler by following config:
198
+
199
+ import MdxRs from '../../fragments/mdx-rs';
200
+
201
+ <MdxRs />
@@ -0,0 +1,4 @@
1
+ # Hello World!
2
+
3
+ ## Start
4
+ Write something to build your own docs! 🎁
@@ -0,0 +1,37 @@
1
+ ---
2
+ pageType: home
3
+
4
+ hero:
5
+ name: <%= siteTitle %>
6
+ text: <%= siteDesc %>
7
+ tagline: <%= siteTitle %> tagline
8
+ actions:
9
+ - theme: brand
10
+ text: Quick Start
11
+ link: /guide/
12
+ - theme: alt
13
+ text: Github
14
+ link: https://github.com/web-infra-dev/rspress
15
+ image:
16
+ src: https://lf3-static.bytednsdoc.com/obj/eden-cn/uhbfnupenuhf/rspress/rspress-logo.png
17
+ alt: <%= siteTitle %> Logo
18
+ features:
19
+ - title: Blazing fast build speed
20
+ details: The core compilation module is based on the Rust front-end toolchain, providing a more ultimate development experience.
21
+ icon: 🏃🏻‍♀️
22
+ - title: Support for MDX content writing
23
+ details: MDX is a powerful way to write content, allowing you to use React components in Markdown.
24
+ icon: 📦
25
+ - title: Built-in full-text search
26
+ details: Automatically generates a full-text search index for you during construction, providing out-of-the-box full-text search capabilities.
27
+ icon: 🎨
28
+ - title: Simpler I18n solution
29
+ details: With the built-in I18n solution, you can easily provide multi-language support for documents or components.
30
+ icon: 🌍
31
+ - title: Static site generation
32
+ details: In production, it automatically builds into static HTML files, which can be easily deployed anywhere.
33
+ icon: 🌈
34
+ - title: Providing multiple custom capabilities
35
+ details: Through its extension mechanism, you can easily extend theme UI and build process.
36
+ icon: 🔥
37
+ ---
@@ -2,5 +2,17 @@ import * as path from 'path';
2
2
  import { defineConfig } from 'rspress/config';
3
3
 
4
4
  export default defineConfig({
5
- root: path.join(__dirname, 'doc'),
5
+ root: path.join(__dirname, 'docs'),
6
+ title: <%= siteTitle %>,
7
+ description: <%= siteDesc %>,
8
+ icon: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/uhbfnupenuhf/rspress/rspress-logo.png',
9
+ logo: {
10
+ light: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/rjhwzy/ljhwZthlaukjlkulzlp/rspress/rspress-navbar-logo-0904.png',
11
+ dark: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/rjhwzy/ljhwZthlaukjlkulzlp/rspress/rspress-navbar-logo-dark-0904.png',
12
+ },
13
+ themeConfig: {
14
+ socialLinks: [
15
+ { icon: 'github', mode: 'link', content: 'https://github.com/web-infra-dev/rspress' },
16
+ ],
17
+ },
6
18
  });
@@ -1 +0,0 @@
1
- # Guide
@@ -1 +0,0 @@
1
- # Hello World