forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
70 lines (61 loc) · 1.6 KB
/
build.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const _ = require('lodash')
const path = require('path')
const fs = require('../lib/fs')
// grab the current version and a few other properties
// from the root package.json
const {
version,
description,
homepage,
license,
bugs,
repository,
keywords,
} = require('@packages/root')
// the rest of properties should come from the package.json in CLI folder
const packageJsonSrc = path.join('package.json')
const packageJsonDest = path.join('build', 'package.json')
function preparePackageForNpmRelease (json) {
// modify the existing package.json
// to prepare it for releasing to npm
delete json.devDependencies
delete json['private']
// no need to include "nyc" code coverage settings
delete json.nyc
_.extend(json, {
version,
description,
homepage,
license,
bugs,
repository,
keywords,
types: 'types', // typescript types
scripts: {
postinstall: 'node index.js --exec install',
size: 't=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";',
},
})
return json
}
function makeUserPackageFile () {
return fs.readJsonAsync(packageJsonSrc)
.then(preparePackageForNpmRelease)
.then((json) => {
return fs.outputJsonAsync(packageJsonDest, json, {
spaces: 2,
})
.return(json) // returning package json object makes it easy to test
})
}
module.exports = makeUserPackageFile
if (!module.parent) {
makeUserPackageFile()
.catch((err) => {
/* eslint-disable no-console */
console.error('Could not write user package file')
console.error(err)
/* eslint-enable no-console */
process.exit(-1)
})
}