-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreate.ts
More file actions
76 lines (61 loc) · 1.86 KB
/
Copy pathcreate.ts
File metadata and controls
76 lines (61 loc) · 1.86 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import ncp from 'ncp'
import * as path from 'path'
import { promisify } from 'util'
import { getArg } from './utils/args'
const copy = promisify(ncp)
type CreateArgs = {
dir: string
lang: string
testRunner: string
}
async function create (args: string[]): Promise<void> {
let options: CreateArgs
// dir - default .
const dir = !args.length || args[0].match(/^-/) ? '.' : args[0]
// lang - default js
const lang: string = getArg(args, { name: 'lang', alias: 'l' }) || 'js'
// testRunner - default mocha
const testRunner: string =
getArg(args, { name: 'testRunner', alias: 't' }) || 'mocha'
// validate lang
if (!['js'].includes(lang)) {
throw new Error(`Language ${lang} not supported yet in create`)
}
// validate test runner
if (!['mocha'].includes(testRunner)) {
throw new Error(`Test Runner ${testRunner} not supported yet in create`)
}
console.info(`Creating CodeRoad project for ${lang} ${testRunner}`)
options = {
dir,
lang,
testRunner
}
const localPath = path.join(process.cwd(), options.dir)
// TODO: git init ?
// copy tutorial file
const pathToSrc = path.join(__dirname, '..', 'src')
const templateDirectory = path.resolve(pathToSrc, 'templates')
const markdownPath = path.join(templateDirectory, 'TUTORIAL.md')
const targetMarkdownPath = path.join(localPath, 'TUTORIAL.md')
try {
await copy(markdownPath, targetMarkdownPath, {
clobber: false
})
} catch (e) {
console.error('Error on creating markdown file')
console.error(e.message)
}
// TODO: copy master yaml
const pathToYaml = path.join(templateDirectory, `${lang}-${testRunner}`)
try {
await copy(pathToYaml, localPath, {
clobber: false
})
} catch (e) {
console.error('Error on creating yaml file')
console.error(e.message)
}
// TODO: copy code files with commits
}
export default create