-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.ts
78 lines (69 loc) · 1.78 KB
/
gulpfile.ts
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
import { src, series, dest } from "gulp";
import { execFile } from "child_process";
var del = require("del");
const chmod = require("gulp-chmod");
var replace = require("gulp-replace");
var header = require("gulp-header");
function release() {
return execFile("./node_modules/.bin/standard-version");
}
function cleanDistDirectory() {
return del("./dist/**/*");
}
function build() {
return execFile("./node_modules/.bin/webpack");
}
function copyPackageFileToDistPath() {
return src("./package.json").pipe(dest("./dist"));
}
function copyReadmeFileToDistPath() {
return src("./README.md").pipe(dest("./dist"));
}
function updatePackageFile() {
return src("./dist/package.json")
.pipe(replace(`"main": "index.js",`, `"main": "main.bundle.js",`))
.pipe(dest("./dist/"));
}
function makeFileExecutable() {
return src("./dist/main.bundle.js")
.pipe(chmod(0o755))
.pipe(dest("./dist/"));
}
function addRunCommandInBuildFile() {
return src("./dist/main.bundle.js")
.pipe(header("#!/usr/bin/env node\n"))
.pipe(dest("./dist/"));
}
function buildNpmPackage() {
return new Promise((resolve, reject) => {
execFile("npm", ["pack"], { cwd: "./dist" }, (error, stdout, stderr) => {
if (error) {
reject(error);
}
console.log(stdout);
resolve(true);
});
});
}
exports.buildNpmPackage = series(
release,
cleanDistDirectory,
build,
addRunCommandInBuildFile,
copyPackageFileToDistPath,
copyReadmeFileToDistPath,
updatePackageFile,
makeFileExecutable,
buildNpmPackage
);
exports.buildNpmPackageWithoutRelease = series(
cleanDistDirectory,
build,
addRunCommandInBuildFile,
copyPackageFileToDistPath,
copyReadmeFileToDistPath,
updatePackageFile,
makeFileExecutable,
buildNpmPackage
);
exports.release = series(release);