-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunLocal.js
More file actions
44 lines (36 loc) · 1.16 KB
/
runLocal.js
File metadata and controls
44 lines (36 loc) · 1.16 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
'use strict'
const fs = require('fs-extra')
const { spawn } = require('child_process')
const clipboardy = require('clipboardy')
const ora = require('ora')
const spinner = ora('Starting server locally ⏳')
/**
* return the path of the directory
* @param {String} dirName the name of the project and dirname
*/
function runLocal (dirPath, port) {
spinner.start()
if (!dirPath) {
throw new Error('The path cant be empty')
}
runDeployLocal(dirPath, port)
}
function runDeployLocal (dirPath, port) {
spawn('npm', [ 'start' ], {
cwd: dirPath
})
spinner.succeed()
const localUrl = `http://localhost:${port}/`
clipboardy.writeSync(localUrl)
console.log('> url copied on clipboard: ', localUrl)
// process.on('exit', exitHandler.bind(null, { dirPath }));
process.on('SIGINT', exitHandler.bind(null, { dirPath }))
process.on('SIGUSR1', exitHandler.bind(null, { dirPath }))
process.on('SIGUSR2', exitHandler.bind(null, { dirPath }))
process.on('uncaughtException', exitHandler.bind(null, { dirPath }))
}
function exitHandler (options) {
fs.removeSync(options.dirPath)
console.log('> Thanks for using easygraphql 😀')
}
module.exports = runLocal