-
Notifications
You must be signed in to change notification settings - Fork 0
/
.neutrinorc.js
108 lines (93 loc) · 3.05 KB
/
.neutrinorc.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
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
const path = require('path')
const fs = require('fs')
const child_process = require('child_process')
const Future = require('fluture')
const R = require('ramda')
const assetsDirectory = 'https://github.com/b-gran/fast-keys/raw/master/assets'
const readme = 'README.md'
const license ='LICENSE'
const typeDefs = 'index.d.ts'
function rootDir (name) {
return path.join(__dirname, name)
}
const getOutputForNeutrino = R.curry(
(neutrino, name) => path.resolve(path.join(neutrino.options.output, name))
)
module.exports = {
use: [
'@neutrinojs/standardjs',
[
'@neutrinojs/library',
{
name: 'fast-keys'
}
],
'@neutrinojs/jest',
// Publish to npm
neutrino => {
neutrino.register('publish', () => {
const isNextRelease = neutrino.options.args.next
const packageJson = neutrino.options.packageJson
const mainFile = path.resolve(path.join(neutrino.options.output, packageJson.main))
const outputDir = getOutputForNeutrino(neutrino)
return Future.node(done => fs.access(mainFile, done))
.mapRej(() => {
console.log()
console.error('No main file in output directory. Please run npm build')
})
// Create package.json for publishing
.chain(() => {
const trimPackageJson = R.omit([ 'devDependencies', 'scripts' ], packageJson)
return Future.encase3(JSON.stringify, trimPackageJson, null, ' ')
})
.chain(packageJsonString => {
const publishablePackageJsonPath = path.resolve(path.join(neutrino.options.output, 'package.json'))
return Future
.node(done => fs.writeFile(publishablePackageJsonPath, packageJsonString, done))
})
// Copy type defs
.chain(() => copyWith(
rootDir(typeDefs),
outputDir(typeDefs)
))
// Copy LICENSE
.chain(() => copyWith(
rootDir(license),
outputDir(license)
))
// Copy README to build & substitute assets
.chain(() => copyWith(
rootDir(readme),
outputDir(readme),
content => content.toString().replace(
/\(assets\/([\w\-_.]+)\)/,
`(${assetsDirectory}/$1)`
)
))
// Run publish
.chain(() => {
console.log()
console.log(`Publishing version ${packageJson.version} to npm ${isNextRelease ? '(@next release) ' : ''}...`)
const command = isNextRelease
? `npm publish --tag next`
: `npm publish`
return Future.node(done =>
child_process.exec(
command,
{ cwd: neutrino.options.output },
done
)
)
})
})
}
]
}
function copyWith (from, to, transform = R.identity) {
return Future.node(done => fs.readFile(from, done))
.chain(contents => Future.node(done => fs.writeFile(
to,
transform(contents),
done
)))
}