-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate-spec-up-t-starterpack.js
43 lines (34 loc) · 1.79 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
#!/usr/bin/env node
const { execSync } = require('child_process');
const fs = require('fs-extra');
const path = require('path');
// Function to copy /spec directory, specs.json, and README.md to the target directory
async function setupSpecUpTStarterPack(dirName) {
// The directory that will be the source for the starter pack
const sourceDir = path.join(__dirname, 'spec-up-t-starterpack');
const targetDir = path.join(process.cwd(), dirName);
const readmeFile = path.join(targetDir, 'README.md');
try {
// Check if source files and directories exist
if (await fs.existsSync(targetDir)) {
console.error(`The name you chose, “${dirName}”, already exists. Exiting...`);
process.exit(1);
}
// Copy 'spec-up-starterpack' directory
await fs.copy(sourceDir, targetDir);
// Rename path.join(sourceDir, 'gitignore') to path.join(targetDir, '.gitignore')
if (await fs.existsSync(path.join(targetDir, 'gitignore'))) {
await fs.rename(path.join(targetDir, 'gitignore'), path.join(targetDir, '.gitignore'));
}
// Replace'spec-up-t-starterpack' with the name of the target directory in README.md
let data = await fs.readFile(readmeFile, 'utf8');
const result = data.replace(/spec-up-t-starterpack/g, dirName);
await fs.writeFile(readmeFile, result, 'utf8');
console.log(`Spec-Up-T starterpack setup complete.\n\nNow cd into the directory that you just created and run "npm install" to install dependencies:\n\ncd ${dirName}\n\nnpm install`);
} catch (err) {
console.error(err);
}
}
// Get the target directory from command line arguments or use current directory
const dirName = process.argv[2] || 'spec-up-t-starterpack';
setupSpecUpTStarterPack(dirName);