create-rspack 1.0.0-rc.2 → 1.0.1
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/bin.js +2 -0
- package/dist/index.js +86 -0
- package/package.json +25 -12
- package/template-common/README.md +23 -0
- package/{template-react → template-react-js}/src/App.css +1 -1
- package/template-react-ts/src/App.css +1 -1
- package/index.js +0 -166
- package/template-react/_gitignore +0 -13
- package/template-vanilla/_gitignore +0 -13
- package/template-vanilla-ts/_gitignore +0 -13
- package/template-vue/_gitignore +0 -13
- package/template-vue-ts/_gitignore +0 -13
- package/utils/index.js +0 -4
- /package/{template-react-ts/_gitignore → template-common/gitignore} +0 -0
- /package/{template-react → template-react-js}/index.html +0 -0
- /package/{template-react → template-react-js}/package.json +0 -0
- /package/{template-react → template-react-js}/rspack.config.mjs +0 -0
- /package/{template-react → template-react-js}/src/App.jsx +0 -0
- /package/{template-react → template-react-js}/src/assets/react.svg +0 -0
- /package/{template-react → template-react-js}/src/index.css +0 -0
- /package/{template-react → template-react-js}/src/main.jsx +0 -0
- /package/{template-vanilla → template-vanilla-js}/index.html +0 -0
- /package/{template-vanilla → template-vanilla-js}/package.json +0 -0
- /package/{template-vanilla → template-vanilla-js}/rspack.config.mjs +0 -0
- /package/{template-vanilla → template-vanilla-js}/src/index.css +0 -0
- /package/{template-vanilla → template-vanilla-js}/src/index.js +0 -0
- /package/{template-vue → template-vue-js}/index.html +0 -0
- /package/{template-vue → template-vue-js}/package.json +0 -0
- /package/{template-vue → template-vue-js}/rspack.config.mjs +0 -0
- /package/{template-vue → template-vue-js}/src/App.vue +0 -0
- /package/{template-vue → template-vue-js}/src/assets/rspack.svg +0 -0
- /package/{template-vue → template-vue-js}/src/assets/vue.svg +0 -0
- /package/{template-vue → template-vue-js}/src/components/HelloWorld.vue +0 -0
- /package/{template-vue → template-vue-js}/src/main.js +0 -0
- /package/{template-vue → template-vue-js}/src/style.css +0 -0
package/bin.js
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {fileURLToPath as __webpack_fileURLToPath__} from "url";
|
|
2
|
+
import {dirname as __webpack_dirname__} from "path";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_create_rstack__ from "create-rstack";
|
|
5
|
+
|
|
6
|
+
;// CONCATENATED MODULE: external "node:path"
|
|
7
|
+
|
|
8
|
+
var external_node_path_namespaceObject = __WEBPACK_EXTERNAL_MODULE_node_path__;
|
|
9
|
+
|
|
10
|
+
;// CONCATENATED MODULE: external "create-rstack"
|
|
11
|
+
|
|
12
|
+
var external_create_rstack_namespaceObject = __WEBPACK_EXTERNAL_MODULE_create_rstack__;
|
|
13
|
+
|
|
14
|
+
;// CONCATENATED MODULE: ./src/index.ts
|
|
15
|
+
var src_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
|
|
16
|
+
//#!/usr/bin/env node
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
async function getTemplateName({ template }) {
|
|
20
|
+
if (typeof template === "string") {
|
|
21
|
+
const pair = template.split("-");
|
|
22
|
+
const language = pair[1] ?? "js";
|
|
23
|
+
const framework = pair[0];
|
|
24
|
+
return `${framework}-${language}`;
|
|
25
|
+
}
|
|
26
|
+
const framework = (0,external_create_rstack_namespaceObject.checkCancel)(await (0,external_create_rstack_namespaceObject.select)({
|
|
27
|
+
message: "Select framework",
|
|
28
|
+
options: [
|
|
29
|
+
{
|
|
30
|
+
value: "vanilla",
|
|
31
|
+
label: "Vanilla"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
value: "react",
|
|
35
|
+
label: "React"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
value: "vue",
|
|
39
|
+
label: "Vue"
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}));
|
|
43
|
+
const language = (0,external_create_rstack_namespaceObject.checkCancel)(await (0,external_create_rstack_namespaceObject.select)({
|
|
44
|
+
message: "Select language",
|
|
45
|
+
options: [
|
|
46
|
+
{
|
|
47
|
+
value: "ts",
|
|
48
|
+
label: "TypeScript"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
value: "js",
|
|
52
|
+
label: "JavaScript"
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
}));
|
|
56
|
+
return `${framework}-${language}`;
|
|
57
|
+
}
|
|
58
|
+
function mapESLintTemplate(templateName) {
|
|
59
|
+
switch(templateName){
|
|
60
|
+
case "react-js":
|
|
61
|
+
case "react-ts":
|
|
62
|
+
case "vue-js":
|
|
63
|
+
case "vue-ts":
|
|
64
|
+
return templateName;
|
|
65
|
+
}
|
|
66
|
+
const language = templateName.split("-")[1];
|
|
67
|
+
return `vanilla-${language}`;
|
|
68
|
+
}
|
|
69
|
+
(0,external_create_rstack_namespaceObject.create)({
|
|
70
|
+
root: external_node_path_namespaceObject["default"].resolve(src_dirname, ".."),
|
|
71
|
+
name: "rspack",
|
|
72
|
+
templates: [
|
|
73
|
+
"vanilla-js",
|
|
74
|
+
"vanilla-ts",
|
|
75
|
+
"react-js",
|
|
76
|
+
"react-ts",
|
|
77
|
+
"vue-js",
|
|
78
|
+
"vue-ts"
|
|
79
|
+
],
|
|
80
|
+
skipFiles: [
|
|
81
|
+
".npmignore"
|
|
82
|
+
],
|
|
83
|
+
getTemplateName,
|
|
84
|
+
mapESLintTemplate
|
|
85
|
+
});
|
|
86
|
+
|
package/package.json
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-rspack",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"license": "MIT",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"bin": {
|
|
7
|
-
"create-rspack": "index.js"
|
|
8
|
-
},
|
|
9
|
-
"publishConfig": {
|
|
10
|
-
"access": "public",
|
|
11
|
-
"provenance": true
|
|
12
|
-
},
|
|
3
|
+
"version": "1.0.1",
|
|
13
4
|
"homepage": "https://rspack.dev",
|
|
14
5
|
"bugs": "https://github.com/web-infra-dev/rspack/issues",
|
|
15
6
|
"repository": {
|
|
@@ -17,8 +8,30 @@
|
|
|
17
8
|
"url": "https://github.com/web-infra-dev/rspack",
|
|
18
9
|
"directory": "packages/create-rspack"
|
|
19
10
|
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "bin.js",
|
|
14
|
+
"bin": {
|
|
15
|
+
"create-rspack": "bin.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"template-*",
|
|
19
|
+
"dist",
|
|
20
|
+
"bin.js"
|
|
21
|
+
],
|
|
20
22
|
"dependencies": {
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
+
"create-rstack": "1.0.1"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@rslib/core": "0.0.3",
|
|
27
|
+
"typescript": "5.0.2"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public",
|
|
31
|
+
"provenance": true
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "rslib build",
|
|
35
|
+
"dev": "rslib build -w"
|
|
23
36
|
}
|
|
24
37
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Rspack Project
|
|
2
|
+
|
|
3
|
+
## Setup
|
|
4
|
+
|
|
5
|
+
Install the dependencies:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Get Started
|
|
12
|
+
|
|
13
|
+
Start the dev server:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm run dev
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Build the app for production:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm run build
|
|
23
|
+
```
|
package/index.js
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const yargs = require("yargs/yargs");
|
|
3
|
-
const { hideBin } = require("yargs/helpers");
|
|
4
|
-
const fs = require("node:fs");
|
|
5
|
-
const path = require("node:path");
|
|
6
|
-
const prompts = require("prompts");
|
|
7
|
-
const { formatTargetDir } = require("./utils");
|
|
8
|
-
const { version } = require("./package.json");
|
|
9
|
-
|
|
10
|
-
yargs(hideBin(process.argv))
|
|
11
|
-
.command("$0", "init rspack project", async argv => {
|
|
12
|
-
const { help } = argv.argv;
|
|
13
|
-
if (help) return;
|
|
14
|
-
|
|
15
|
-
const onCancel = () => {
|
|
16
|
-
console.log("Operation cancelled.");
|
|
17
|
-
process.exit(0);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const defaultProjectName = "rspack-project";
|
|
21
|
-
let template = "react";
|
|
22
|
-
let targetDir = defaultProjectName;
|
|
23
|
-
|
|
24
|
-
const promptProjectDir = async () =>
|
|
25
|
-
await prompts(
|
|
26
|
-
[
|
|
27
|
-
{
|
|
28
|
-
type: "text",
|
|
29
|
-
name: "projectDir",
|
|
30
|
-
initial: defaultProjectName,
|
|
31
|
-
message: "Project folder",
|
|
32
|
-
onState: state => {
|
|
33
|
-
targetDir = formatTargetDir(state.value) || defaultProjectName;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
],
|
|
37
|
-
{ onCancel }
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
await promptProjectDir();
|
|
41
|
-
let projectDir = getProjectDir(targetDir);
|
|
42
|
-
let root = path.resolve(process.cwd(), projectDir);
|
|
43
|
-
while (fs.existsSync(root)) {
|
|
44
|
-
console.log(
|
|
45
|
-
`${targetDir} is not empty, please choose another project name`
|
|
46
|
-
);
|
|
47
|
-
await promptProjectDir();
|
|
48
|
-
projectDir = getProjectDir(targetDir);
|
|
49
|
-
root = path.resolve(process.cwd(), projectDir);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// choose template
|
|
53
|
-
await prompts(
|
|
54
|
-
[
|
|
55
|
-
{
|
|
56
|
-
type: "select",
|
|
57
|
-
name: "template",
|
|
58
|
-
message: "Project template",
|
|
59
|
-
choices: [
|
|
60
|
-
{ title: "vanilla", value: "vanilla" },
|
|
61
|
-
{ title: "vanilla-ts", value: "vanilla-ts" },
|
|
62
|
-
{ title: "react", value: "react" },
|
|
63
|
-
{ title: "react-ts", value: "react-ts" },
|
|
64
|
-
{ title: "vue", value: "vue" },
|
|
65
|
-
{ title: "vue-ts", value: "vue-ts" }
|
|
66
|
-
],
|
|
67
|
-
onState: state => {
|
|
68
|
-
template = state.value;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
],
|
|
72
|
-
{ onCancel }
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
fs.mkdirSync(root, { recursive: true });
|
|
76
|
-
const srcFolder = path.resolve(__dirname, `template-${template}`);
|
|
77
|
-
copyFolder(srcFolder, root, targetDir);
|
|
78
|
-
const pkgManager = getPkgManager();
|
|
79
|
-
console.log("\nDone. Now run:\n");
|
|
80
|
-
console.log(`cd ${projectDir}\n`);
|
|
81
|
-
console.log(`${pkgManager} install\n`);
|
|
82
|
-
console.log(`${pkgManager} run dev\n`);
|
|
83
|
-
})
|
|
84
|
-
.help()
|
|
85
|
-
.parse();
|
|
86
|
-
|
|
87
|
-
function copyFolder(src, dst, targetDir) {
|
|
88
|
-
const renameFiles = {
|
|
89
|
-
_gitignore: ".gitignore"
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
// replace workspace packages with version in package.json
|
|
93
|
-
const workspacePackages = [
|
|
94
|
-
"@rspack/cli",
|
|
95
|
-
"@rspack/core",
|
|
96
|
-
"@rspack/dev-server"
|
|
97
|
-
];
|
|
98
|
-
|
|
99
|
-
fs.mkdirSync(dst, { recursive: true });
|
|
100
|
-
for (const file of fs.readdirSync(src)) {
|
|
101
|
-
if (file === "node_modules") {
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
const srcFile = path.resolve(src, file);
|
|
105
|
-
const dstFile = renameFiles[file]
|
|
106
|
-
? path.resolve(dst, renameFiles[file])
|
|
107
|
-
: path.resolve(dst, file);
|
|
108
|
-
const stat = fs.statSync(srcFile);
|
|
109
|
-
if (stat.isDirectory()) {
|
|
110
|
-
copyFolder(srcFile, dstFile, targetDir);
|
|
111
|
-
} else {
|
|
112
|
-
// use create-rspack version as @rspack/xxx version in template
|
|
113
|
-
if (file === "package.json") {
|
|
114
|
-
const pkg = require(srcFile);
|
|
115
|
-
if (pkg.dependencies) {
|
|
116
|
-
for (const key of Object.keys(pkg.dependencies)) {
|
|
117
|
-
if (workspacePackages.includes(key)) {
|
|
118
|
-
pkg.dependencies[key] = version;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (pkg.devDependencies) {
|
|
123
|
-
for (const key of Object.keys(pkg.devDependencies)) {
|
|
124
|
-
if (workspacePackages.includes(key)) {
|
|
125
|
-
pkg.devDependencies[key] = version;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
if (pkg.name) {
|
|
130
|
-
pkg.name = getPkgName(targetDir);
|
|
131
|
-
}
|
|
132
|
-
fs.writeFileSync(dstFile, JSON.stringify(pkg, null, 2), "utf-8");
|
|
133
|
-
} else {
|
|
134
|
-
fs.copyFileSync(srcFile, dstFile);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function getPkgName(targetDir) {
|
|
141
|
-
const scopeMatch = matchScopedPackageName(targetDir);
|
|
142
|
-
if (scopeMatch) {
|
|
143
|
-
return targetDir; // Scoped package name
|
|
144
|
-
}
|
|
145
|
-
return path.basename(targetDir); // Use the base name of the target directory
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function getProjectDir(targetDir) {
|
|
149
|
-
const scopeMatch = matchScopedPackageName(targetDir);
|
|
150
|
-
if (scopeMatch) {
|
|
151
|
-
return scopeMatch[1]; // Subdirectory project name for scoped packages
|
|
152
|
-
}
|
|
153
|
-
return targetDir;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function matchScopedPackageName(targetDir) {
|
|
157
|
-
return targetDir.match(/^@[^/]+\/(.+)/);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function getPkgManager() {
|
|
161
|
-
const ua = process.env.npm_config_user_agent;
|
|
162
|
-
if (!ua) return "npm";
|
|
163
|
-
const [pkgInfo] = ua.split(" ");
|
|
164
|
-
const [name] = pkgInfo.split("/");
|
|
165
|
-
return name || "npm";
|
|
166
|
-
}
|
package/template-vue/_gitignore
DELETED
package/utils/index.js
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|