core-maugli 1.0.3 → 1.0.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/bin/init.js +33 -25
- package/package.json +1 -1
package/bin/init.js
CHANGED
@@ -8,31 +8,39 @@ import { execSync } from 'child_process';
|
|
8
8
|
const __filename = fileURLToPath(import.meta.url);
|
9
9
|
const __dirname = path.dirname(__filename);
|
10
10
|
const templateRoot = path.join(__dirname, '..');
|
11
|
-
const targetDir = process.argv[2] ? path.resolve(process.argv[2]) : process.cwd();
|
12
11
|
|
13
|
-
function
|
14
|
-
const
|
15
|
-
const dest = path.join(targetDir, item);
|
16
|
-
cpSync(src, dest, { recursive: true });
|
17
|
-
console.log(`Copied ${item}`);
|
18
|
-
}
|
12
|
+
export default function init(targetName) {
|
13
|
+
const targetDir = targetName ? path.resolve(targetName) : process.cwd();
|
19
14
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
function copyItem(item) {
|
16
|
+
const src = path.join(templateRoot, item);
|
17
|
+
const dest = path.join(targetDir, item);
|
18
|
+
cpSync(src, dest, { recursive: true });
|
19
|
+
console.log(`Copied ${item}`);
|
24
20
|
}
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
21
|
+
|
22
|
+
// Copy package files first so npm install works correctly
|
23
|
+
['package.json', 'package-lock.json'].forEach(file => {
|
24
|
+
if (existsSync(path.join(templateRoot, file))) {
|
25
|
+
copyItem(file);
|
26
|
+
}
|
27
|
+
});
|
28
|
+
|
29
|
+
const items = [
|
30
|
+
'astro.config.mjs',
|
31
|
+
'tsconfig.json',
|
32
|
+
'public',
|
33
|
+
'src',
|
34
|
+
'scripts',
|
35
|
+
'typograf-batch.js',
|
36
|
+
'resize-all.cjs'
|
37
|
+
];
|
38
|
+
items.forEach(copyItem);
|
39
|
+
|
40
|
+
execSync('npm install', { cwd: targetDir, stdio: 'inherit' });
|
41
|
+
}
|
42
|
+
|
43
|
+
// Если скрипт запускается напрямую
|
44
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
45
|
+
init(process.argv[2]);
|
46
|
+
}
|