jizy-packer 2.1.21 → 2.1.23
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/cli/init.js +14 -12
- package/package.json +1 -1
package/cli/init.js
CHANGED
|
@@ -3,30 +3,31 @@ import path from "path";
|
|
|
3
3
|
import readline from "readline";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
function copyAndReplace(srcDir, destDir, replacements) {
|
|
7
7
|
const entries = fs.readdirSync(srcDir, { withFileTypes: true });
|
|
8
|
-
console.
|
|
9
|
-
|
|
8
|
+
console.dir(entries.map(e => e.name));
|
|
9
|
+
|
|
10
|
+
entries.forEach(entry => {
|
|
11
|
+
console.log(entry.name);
|
|
10
12
|
const srcPath = path.join(srcDir, entry.name);
|
|
11
13
|
const destName = entry.name.replace(/\.skel$/, "");
|
|
12
14
|
const destPath = path.join(destDir, destName);
|
|
13
15
|
|
|
14
16
|
if (entry.isDirectory()) {
|
|
15
17
|
if (!fs.existsSync(destPath)) fs.mkdirSync(destPath);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
copyAndReplace(srcPath, destPath, replacements);
|
|
19
|
+
return;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
if (fs.existsSync(destPath)) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
continue; // Skip existing files & folders
|
|
23
|
+
if (entry.name !== 'package.json') {
|
|
24
|
+
return; // Skip existing files & folders
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
// read json file and check if the name of the package is set
|
|
27
28
|
const pkg = JSON.parse(fs.readFileSync(srcPath, "utf8"));
|
|
28
29
|
if (pkg.name) {
|
|
29
|
-
|
|
30
|
+
return; // skip existing package.json with name set
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
|
|
@@ -35,7 +36,7 @@ async function copyAndReplace(srcDir, destDir, replacements) {
|
|
|
35
36
|
content = content.replace(new RegExp(`%${key}%`, "g"), value);
|
|
36
37
|
});
|
|
37
38
|
fs.writeFileSync(destPath, content, "utf8");
|
|
38
|
-
}
|
|
39
|
+
});
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
function askQuestion(query) {
|
|
@@ -64,5 +65,6 @@ const __dirname = path.dirname(__filename);
|
|
|
64
65
|
const srcDir = path.join(__dirname, "..", "_package");
|
|
65
66
|
const destDir = process.cwd();
|
|
66
67
|
|
|
67
|
-
console.log(srcDir
|
|
68
|
-
|
|
68
|
+
console.log(srcDir);
|
|
69
|
+
console.log(destDir);
|
|
70
|
+
copyAndReplace(srcDir, destDir, answers);
|