forked from kordwarshuis/spec-up-t-starter-pack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate-spec-up-t-starterpack.js
71 lines (53 loc) · 2.37 KB
/
create-spec-up-t-starterpack.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env node
const { execSync } = require('child_process');
const fs = require('fs-extra');
const path = require('path');
const { setupCompleteMessage, errorDirExistsMessage } = require('./messages.js');
// Main setup function
async function setupSpecPack(dirName) {
const packageSpecUpT = path.join(__dirname, 'package.spec-up-t.json');
const targetDir = path.join(process.cwd(), dirName);
try {
/* ****************
Install Git
**************** */
if (fs.existsSync(targetDir)) {
console.error(`${errorDirExistsMessage[0]}${dirName}${errorDirExistsMessage[1]}`);
process.exit(1);
}
// Create targetDir if it doesn't exist
if (!fs.existsSync(targetDir)) {
await fs.mkdir(targetDir);
console.log(`Created directory: ${dirName}`);
}
// Copy package.spec-up-t.json to targetDir
await fs.copy(packageSpecUpT, path.join(targetDir, 'package.json'));
// Run git init
console.log(`Initialize git repository`);
execSync(`git init`, { cwd: targetDir, stdio: 'inherit' });
console.log(`Git repository initialized`);
// Install dependencies with npm
console.log(`Using npm to install dependencies.`);
// Suppress npm audit and fund messages in the project-specific .npmrc
const npmrcPath = path.join(targetDir, '.npmrc');
await fs.writeFile(npmrcPath, 'audit=false\nfund=false\n', 'utf8');
// Run npm install
// execSync(`npm install`, { cwd: targetDir, stdio: 'inherit' });
execSync(`npm install --silent`, { cwd: targetDir, stdio: 'inherit' });
console.log(`${setupCompleteMessage[0]}`);
/* ****************
Call spec-up-t install.js
**************** */
const packageName = 'spec-up-t';
const basePath = path.join(targetDir);
const nodeModulesPath = path.join(basePath, 'node_modules');
const packagePath = path.join(nodeModulesPath, packageName);
require(path.join(packagePath, 'src', 'install-from-boilerplate', 'install.js'));
} catch (err) {
console.error('Error during setup:', err);
process.exit(1);
}
}
// Start setup process with provided directory name
const dirName = process.argv[2] || 'spec-up-t-boilerplate';
setupSpecPack(dirName);