Skip to content

Commit

Permalink
chore: force create-rspack use publish version
Browse files Browse the repository at this point in the history
  • Loading branch information
hardfist committed Jan 8, 2024
1 parent be59383 commit 92c6e57
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion packages/create-rspack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const fs = require("fs");
const path = require("path");
const prompts = require("prompts");
const { formatTargetDir } = require("./utils");
const { version } = require("./package.json");

yargs(hideBin(process.argv))
.command("$0", "init rspack project", async argv => {
Expand Down Expand Up @@ -73,6 +74,9 @@ function copyFolder(src, dst) {

fs.mkdirSync(dst, { recursive: true });
for (const file of fs.readdirSync(src)) {
if (file === "node_modules") {
continue;
}
const srcFile = path.resolve(src, file);
const dstFile = renameFiles[file]
? path.resolve(dst, renameFiles[file])
Expand All @@ -81,7 +85,27 @@ function copyFolder(src, dst) {
if (stat.isDirectory()) {
copyFolder(srcFile, dstFile);
} else {
fs.copyFileSync(srcFile, dstFile);
// use create-rspack version as @rspack/xxx version in template
if (file === "package.json") {
const pkg = require(srcFile);
if (pkg.dependencies) {
for (const key of Object.keys(pkg.dependencies)) {
if (key.startsWith("@rspack/")) {
pkg.dependencies[key] = version;
}
}
}
if (pkg.devDependencies) {
for (const key of Object.keys(pkg.devDependencies)) {
if (key.startsWith("@rspack/")) {
pkg.devDependencies[key] = version;
}
}
}
fs.writeFileSync(dstFile, JSON.stringify(pkg, null, 2), "utf-8");
} else {
fs.copyFileSync(srcFile, dstFile);
}
}
}
}
Expand Down

0 comments on commit 92c6e57

Please sign in to comment.