-
Notifications
You must be signed in to change notification settings - Fork 2
/
prepublish.js
64 lines (54 loc) · 1.9 KB
/
prepublish.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
'use strict'
const chalk = require('chalk')
const path = require('path')
const copyFile = require('./lib/copy-file')
const outputDirname = path.resolve(__dirname, './root-repo')
const copyProps = { outputDirname }
// Don't fail silently
process.on('unhandledRejection', err => {
throw err
})
async function prepublish() {
// Track how many files were actually copied
let successes = 0
const copyAndCount = async (path, props) => {
const wasSuccess = await copyFile(path, props)
if (wasSuccess) successes++
}
const copyPackageJsonAndCount = async (pkg, outputDirname) => {
await copyAndCount(`../../${pkg}/package.json`, {
outputDirname: path.resolve(outputDirname, pkg),
})
}
// Copy config from host root repo where possible to avoid duplication
const copyPromises = [
copyAndCount('../../../.eslintignore', copyProps),
copyAndCount('../../../.prettierignore', copyProps),
copyAndCount('../../../.prettierrc', copyProps),
copyAndCount('../../../babel.config.js', copyProps),
copyAndCount('../../../jsx-packages.js', copyProps),
copyAndCount('../../../packages/.eslintrc', {
outputDirname: path.resolve(copyProps.outputDirname, 'packages'),
}),
copyAndCount('../../../.gitignore', {
// Temporarily drop the `.` to dodge NPM's .gitignore >> .npmignore
// rename bugfeature explained here https://github.com/npm/npm/issues/7252
outputFilename: 'gitignore',
...copyProps,
}),
copyAndCount('../../../package.json', copyProps),
copyPackageJsonAndCount('sdk', outputDirname),
copyPackageJsonAndCount('data', outputDirname),
copyPackageJsonAndCount('shell', outputDirname),
copyPackageJsonAndCount('samples', outputDirname),
]
await Promise.all(copyPromises)
console.log(
chalk.green(
`Copied ${successes} file${
successes === 1 ? '' : 's'
} to ${outputDirname}`
)
)
}
prepublish()