Repository navigation
Expand file tree
/
Copy pathcli.js
More file actions
61 lines (53 loc) · 1.62 KB
/
Copy pathcli.js
File metadata and controls
61 lines (53 loc) · 1.62 KB
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
#!/usr/bin/env node
const { resolve, join } = require('path');
const { unlinkSync, existsSync, mkdirSync, readdirSync } = require('fs');
const log = require('./helpers/log');
const execSyncLocally = require('./helpers/execSyncLocally');
const setupTypescript = require('./helpers/setupTypescript');
const Commands = {
help: 'help',
init: 'init',
convert: 'convert',
};
const defaultCommand = Commands.init;
const execCommand = process.argv[2] || defaultCommand;
const additionalArgs = process.argv.slice(3);
if (execCommand === Commands.help) {
console.log('Available commands:', '\n');
console.log(
'`init`',
':',
'Create new Routify starter template with Typescript support.'
);
console.log(
'`convert`',
':',
'Add Typescript support for the existing Routify starter template.'
);
} else {
const targetDir = additionalArgs[0]
? resolve(process.cwd(), additionalArgs[0])
: process.cwd();
if (execCommand === Commands.init) {
if (existsSync(targetDir)) {
if (readdirSync(targetDir).length) {
console.error(
'Target directory is not empty. Please use `setup-routify-ts convert #{targetDir}` instead.'
);
process.exit();
}
} else mkdirSync(targetDir);
log(
"Preparing base Routify starter template. May take a few minutes. Please wait a moment."
);
execSyncLocally(
targetDir,
`npx @sveltech/routify init${
additionalArgs.length > 1 ? additionalArgs.slice(1).join(' ') : ''
}`
);
// Delete package-lock.json
unlinkSync(join(targetDir, 'package-lock.json'));
}
setupTypescript(targetDir);
}