-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·53 lines (44 loc) · 1.43 KB
/
index.js
File metadata and controls
executable file
·53 lines (44 loc) · 1.43 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
#!/usr/bin/env node
const path = require('path')
const { spawn } = require('child_process')
const os = require('os')
const fs = require('fs-extra')
const chalk = require('chalk')
const { getProgramArgs } = require('./argsParser.js')
const { checkAppNameCanBeUsed } = require('./utils.js')
const { createFiles } = require('./createFiles.js')
const { generatePackagesListToInstall } = require('./generatePackagesListToInstall.js')
const isWindows = os.platform() === 'win32'
createApp(...getProgramArgs())
function createApp(projectName, programArgs) {
const projectRoot = path.resolve(projectName)
const appName = path.basename(projectRoot)
const packagesToInstall = generatePackagesListToInstall(programArgs)
checkAppNameCanBeUsed(appName)
console.log(`Creating a new LightScript app in ${chalk.green(projectRoot)}.\n`)
fs.ensureDirSync(projectRoot)
process.chdir(projectRoot)
createFiles(process.cwd(), programArgs, appName)
installNpmPackages(packagesToInstall)
}
function installNpmPackages(packagesToInstall){
console.log('Installing packages.\n')
const child = spawn(
'npm',
[
'install',
...packagesToInstall ,
'-D'
],
{
stdio: 'inherit',
// had some issues on windows, 'shell:true' seems to fix it
shell: isWindows ? true : false
}
)
child.on('close', code => {
if(code !== 0) {
console.error('There was an error installing the packages.')
}
})
}