UNPKG

1.28 kBJavaScriptView Raw
1#! /usr/bin/env node
2
3const shell = require('shelljs')
4const path = require('path')
5const {
6 getConfig,
7 /*generateConfigForPackageJson,*/ generateScriptsForPackageJson,
8 SPDT_DIR,
9} = require('../lib/config')
10
11function 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// function echoConfigForPackageJson() {
18// insertInto(generateConfigForPackageJson())
19// }
20
21function echoScriptsForPackageJson() {
22 insertInto(generateScriptsForPackageJson())
23}
24
25function 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
32function 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
39function init() {
40 const config = getConfig()
41 const projectDir = path.resolve(config.projectRoot)
42 const dest = mkDir(projectDir, SPDT_DIR)
43
44 // echoConfigForPackageJson()
45 echoScriptsForPackageJson()
46 const configsSource = path.resolve(__dirname, '../config-templates')
47 copyConfigFilesToProject(configsSource, dest)
48}
49
50init()