-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfigure.js
More file actions
54 lines (44 loc) · 876 Bytes
/
configure.js
File metadata and controls
54 lines (44 loc) · 876 Bytes
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
'use strict'
/**
* Dependencies
*/
const cwd = process.cwd()
const path = require('path')
const fs = require('fs')
/**
* Env
*/
const scriptDir = __dirname
/**
* Args
*/
const args = process.argv.slice(2)
const [ packageName ] = args
/**
* Config
*/
const config = require(path.join(scriptDir, 'config.json'))
// parse package.json
let packageData
try {
let json = fs.readFileSync(path.join(cwd, 'package.json'), 'utf8')
packageData = JSON.parse(json)
} catch (error) {
console.error(error)
process.exit(1)
}
// configured stuff
Object.assign(packageData, config)
// package name
if (packageName) {
packageData.name = packageName
}
// stringify
let stringified = JSON.stringify(packageData, null, 2)
// write to file
try {
fs.writeFileSync(path.join(cwd, 'package.json'), stringified)
} catch (error) {
console.error(error)
process.exit(1)
}