1 | #! /usr/bin/env node
|
2 |
|
3 | const shell = require('shelljs')
|
4 | const path = require('path')
|
5 | const {
|
6 | getConfig,
|
7 | generateScriptsForPackageJson,
|
8 | SPDT_DIR,
|
9 | } = require('../lib/config')
|
10 |
|
11 | function insertInto(content) {
|
12 | shell.echo(`Insert it into your package.json\n-----\n`)
|
13 | shell.echo(content)
|
14 | shell.echo(`\n-----\n`)
|
15 | }
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | function echoScriptsForPackageJson() {
|
22 | insertInto(generateScriptsForPackageJson())
|
23 | }
|
24 |
|
25 | function copyConfigFilesToProject(source, dest) {
|
26 | const command = `cp -r ${source}/ ${dest}`
|
27 | shell.exec(command)
|
28 | shell.echo(`Copied jest-puppeteer config files to ${dest}`)
|
29 | return true
|
30 | }
|
31 |
|
32 | function mkDir(parentDir, dirName) {
|
33 | const command = `cd ${parentDir} && mkdir -p ${dirName}`
|
34 | shell.exec(command)
|
35 | shell.echo(`Created dir ${parentDir}/${dirName}`)
|
36 | return `${parentDir}/${dirName}`
|
37 | }
|
38 |
|
39 | function init() {
|
40 | const config = getConfig()
|
41 | const projectDir = path.resolve(config.projectRoot)
|
42 | const dest = mkDir(projectDir, SPDT_DIR)
|
43 |
|
44 |
|
45 | echoScriptsForPackageJson()
|
46 | const configsSource = path.resolve(__dirname, '../config-templates')
|
47 | copyConfigFilesToProject(configsSource, dest)
|
48 | }
|
49 |
|
50 | init()
|