forked from isomorphic-git/isomorphic-git
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage-scripts.js
More file actions
128 lines (120 loc) · 4.77 KB
/
package-scripts.js
File metadata and controls
128 lines (120 loc) · 4.77 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// package-scripts.js is a convention used by the 'nps' utility
// It's like package.json scripts, but more flexible.
const { concurrent, series, runInNewWindow } = require('nps-utils')
// Polyfill TRAVIS_PULL_REQUEST_SHA environment variable
require('./__tests__/__helpers__/set-TRAVIS_PULL_REQUEST_SHA.js')
const retry = n => cmd =>
Array(n)
.fill(`(${cmd})`)
.join(` || `)
const retry3 = retry(3)
const quote = cmd =>
cmd.replace(new RegExp("'", 'g'), "\\'").replace(new RegExp('"', 'g'), '\\"')
const optional = cmd =>
`(${cmd}) || echo "Optional command '${quote(cmd)}' failed".`
const timeout = n => cmd => `timeout -t ${n}m -- ${cmd}`
const timeout5 = timeout(5)
const or = (a, b) => `(${a}) || (${b})`
const srcPaths = '*.js src/*.js src/**/*.js __tests__/*.js __tests__/**/*.js'
module.exports = {
scripts: {
lint: {
default: series.nps('lint.js', 'lint.typescript'),
js: `standard ${srcPaths}`,
fix: `standard --fix ${srcPaths}`,
typescript: 'tsc src/index.d.ts --lib es6',
typescriptTests: 'tsc -p tsconfig.json'
},
watch: {
default: concurrent.nps('watch.rollup', 'watch.jest'),
rollup: runInNewWindow('rollup -cw'),
jest: runInNewWindow('cross-env DEBUG=* jest --watch'),
karma: runInNewWindow('karma start')
},
contributors: {
add: 'all-contributors add',
generate:
'all-contributors generate && node ./__tests__/__helpers__/fix-all-contributors.js',
check: 'all-contributors check'
},
build: {
default: series.nps(
'build.rollup',
'build.webpack',
'build.indexjson',
'build.treeshake',
'build.size'
),
webpack: 'webpack',
rollup: 'rollup -c',
indexjson: `node __tests__/__helpers__/make_http_index.js`,
treeshake: 'agadoo',
docs: 'node ./__tests__/__helpers__/generate-docs.js',
size: process.env.CI
? optional(
`cross-env TRAVIS=true ` +
`GITHUB_TOKEN=${process.env.BUNDLESIZE_GITHUB_TOKEN} ` +
`TRAVIS_REPO_SLUG=${process.env.TRAVIS_REPO_SLUG ||
process.env.BUILD_REPOSITORY_NAME} ` +
// TODO: Figure out what the Azure equivalent of TRAVIS_PULL_REQUEST_SHA is.
`TRAVIS_PULL_REQUEST_SHA=${
process.env.TRAVIS_PULL_REQUEST_SHA
} ` +
`bundlesize`
)
: optional(`cross-env-shell GITHUB_TOKEN='' bundlesize`)
},
// ATTENTION:
// LIST OF SAFE PORTS FOR SAUCE LABS (Edge and Safari) https://wiki.saucelabs.com/display/DOCS/Sauce+Connect+Proxy+FAQS#SauceConnectProxyFAQS-CanIAccessApplicationsonlocalhost?
// 'proxy' needs to run in the background during tests. I'm too lazy to auto start/stop it from within the browser tests.
proxy: {
default: `cors-proxy start -p 9999`,
start: `cors-proxy start -p 9999 -d`,
stop: `cors-proxy stop`
},
gitserver: {
default: `cross-env GIT_HTTP_MOCK_SERVER_PORT=8888 GIT_HTTP_MOCK_SERVER_ROOT=__tests__/__fixtures__ git-http-mock-server`,
start: `cross-env GIT_HTTP_MOCK_SERVER_PORT=8888 GIT_HTTP_MOCK_SERVER_ROOT=__tests__/__fixtures__ git-http-mock-server start`,
stop: `cross-env GIT_HTTP_MOCK_SERVER_PORT=8888 GIT_HTTP_MOCK_SERVER_ROOT=__tests__/__fixtures__ git-http-mock-server stop`
},
test: {
// We run jest in Travis so we get accurate code coverage that's mapped to the original source.
// But by default, we skip 'jest' because I decided to make it an optionalDependency after it was
// pointed out to me that it depends on native modules that don't have prebuilt binaries available,
// and no one should be required to install Python and a C++ compiler to contribute to this code.
default: process.env.CI
? series.nps(
'lint',
'build',
'test.setup',
'test.one',
'test.karma',
'test.teardown'
)
: series.nps(
'lint',
'build',
'test.setup',
'test.one',
'test.karma',
'test.teardown'
),
setup: series.nps('proxy.start', 'gitserver.start'),
teardown: series.nps('proxy.stop', 'gitserver.stop'),
one: retry3(or('nps test.jest', 'nps test.jasmine')),
jasmine: process.env.CI
? `cross-env NODE_PATH=./dist/for-node ${timeout5('jasmine')}`
: `cross-env NODE_PATH=./dist/for-node jasmine`,
jest: process.env.CI
? `${timeout5('jest --ci --coverage')}`
: `jest --ci --coverage`,
karma: process.env.CI
? retry3('karma start --single-run')
: 'karma start --single-run'
},
prepublish: {
default: series.nps('prepublish.version', 'build'),
version: `node __tests__/__helpers__/fix-version-number.js`
}
}
}