/
Gruntfile.js
101 lines (86 loc) · 2.63 KB
/
Gruntfile.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
const cp = require("child_process");
const pkg = require("./package.json");
const path = require("path");
const PATH_DIST = path.resolve(process.cwd(), "dist");
const PATH_BUILD = path.resolve(process.cwd(), "build");
process.env = Object.assign({
NODE_ENV: "production"
}, process.env);
module.exports = (grunt) => {
// Project configuration.
grunt.initConfig({
pkg,
env: {
options: {
//Shared Options Hash
},
prod: {
NODE_ENV: "production",
}
},
/*
compress: {
main: {
options: {
archive: `frontend-v${pkg.version}.tgz`
},
files: [{
expand: true,
src: "**",
cwd: "dist/"
}]
}
}
*/
});
grunt.loadNpmTasks("grunt-contrib-compress");
grunt.loadNpmTasks("grunt-env");
grunt.registerTask("build:docker", () => {
let buildArgs = [
`--build-arg version=${pkg.version}`,
`--build-arg buildDate=${Date.now()}`,
].join(" ");
cp.execSync(`docker build . -t openhaus/${pkg.name}:${pkg.version} ${buildArgs}`, {
env: process.env,
stdio: "inherit"
});
cp.execSync(`docker build . -t openhaus/${pkg.name}:latest ${buildArgs}`, {
env: process.env,
stdio: "inherit"
});
});
grunt.registerTask("compress", () => {
cp.execSync(`cd ${PATH_BUILD} && tar -czvf ${path.join(PATH_DIST, `${pkg.name}-v${pkg.version}.tgz`)} *`, {
env: process.env,
stdio: "inherit"
});
});
grunt.registerTask("release", () => {
[
`mkdir -p ${PATH_BUILD}`,
`mkdir -p ${PATH_DIST}`,
`rm -rf ${PATH_BUILD}/*`,
`rm -rf ${PATH_DIST}/*`,
"npm run build",
"npm run build:docker",
`docker save openhaus/${pkg.name}:latest | gzip > ${path.join(PATH_DIST, `${pkg.name}-v${pkg.version}-docker.tgz`)}`,
"grunt compress"
].forEach((cmd) => {
cp.execSync(cmd, {
env: process.env,
stdio: "inherit"
});
});
});
grunt.registerTask("publish", () => {
[
`docker push openhaus/${pkg.name}:${pkg.version}`,
`docker push openhaus/${pkg.name}:latest`
].forEach((cmd) => {
cp.execSync(cmd, {
env: process.env,
stdio: "inherit"
});
});
});
};