-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-package.js
45 lines (39 loc) · 1.05 KB
/
make-package.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
const { resolve } = require("path")
const { ncp } = require("ncp")
const package = require("./package.json")
const fs = require("fs")
middleware(makePackageJson, copyReadme, copyCli)()
function makePackageJson(next) {
const dest = resolve(__dirname, "./dist/package/package.json")
const content = Object.assign({}, package, {
main: "umd/index.js",
module: "es/index.js",
typings: "lib/index.d.ts"
})
fs.writeFileSync(dest, JSON.stringify(content, null, 2), "utf8")
next()
}
function copyReadme(next) {
const src = resolve(__dirname, "./README.md")
const dest = resolve(__dirname, "./dist/package/README.md")
ncp(src, dest, err => {
if (err) throw err
next()
})
}
function copyCli(next) {
const src = resolve(__dirname, "./cli")
const dest = resolve(__dirname, "./dist/package/cli")
ncp(src, dest, err => {
if (err) throw err
next()
})
}
function done() {
console.log("Done!")
}
function middleware(...fns) {
return (...args) => {
return fns.reduceRight((next, fn) => () => fn(next, ...args), () => {})()
}
}