-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
145 lines (116 loc) · 3.66 KB
/
gulpfile.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Node.js
const exec = require("child_process").exec;
const spawn = require("child_process").spawn;
const http = require("https");
const fs = require("fs-extra");
const Path = require("path");
const gulp = require("gulp");
const gulpClean = require("gulp-clean");
// Constants
const _outputDir = "dist";
const _outputTestDir = "test/build/test";
const _inputDir = "src";
const _inputTestDir = "test";
const _webpackConfigDevelop = "webpack.dev.config.js";
const _webpackConfigProduction = "webpack.prod.config.js";
////////////////////
// UTILITY TASKS //
////////////////////
// Clean all the content in the dist directory
function clean()
{
return gulp.src(_outputDir, {read: false, allowEmpty:true})
.pipe(gulpClean());
//runCmd("rm -rf " + _outputDir + "/*" ,cb);
};
// Copy the non script assets to the destination folder
function copyAssets(cb)
{
gulp.src(_inputDir + "/css/**/*").pipe(gulp.dest(_outputDir + "/css"));
gulp.src(_inputDir + "/lib/**/*").pipe(gulp.dest(_outputDir + "/lib"));
gulp.src(_inputDir + "/html/**/*").pipe(gulp.dest(_outputDir + "/html"));
gulp.src(_inputDir + "/img/**/*").pipe(gulp.dest(_outputDir + "/img"));
gulp.src(_inputDir + "/fonts/**/*").pipe(gulp.dest(_outputDir + "/fonts"));
gulp.src(_inputDir + "/js/**/*").pipe(gulp.dest(_outputDir + "/js"));
cb();
};
///////////////////////
// DEVELOPMENT BUILD //
///////////////////////
function run(cb)
{
runCmd("electron .",cb);
}
// Compile the proyect into to files using webpack
function webpackDevelop(cb)
{
runCmd("webpack --config "+_webpackConfigDevelop,cb);
};
// Build the project in develop mode
let buildDevelop = gulp.series(clean,copyAssets,webpackDevelop);
// Compile and run the project in develop mode
exports.dev = gulp.series(buildDevelop, run);
//////////////////////
// PRODUCTION BUILD //
//////////////////////
// Compile the proyect into to files using webpack
function webpackProduction(cb)
{
runCmd("webpack --config "+_webpackConfigProduction,cb);
};
// Build the project with post proccesses
let buildProduction = gulp.series(clean,copyAssets,webpackProduction);
// Compile and run the project in production mode
exports.prod = gulp.series(buildProduction, run);
//////////////
// Publish //
//////////////
function publishPostProcess(cb)
{
gulp.src("package.json").pipe(gulp.dest(_outputDir)).on("end",()=>
{
let packagePath = Path.join(".",_outputDir,"package.json");
let json = fs.readJSONSync(packagePath);
json.main = "main.js";
fs.writeJSONSync(packagePath,json);
cb();
});
}
function packageWin32(cb)
{
runCmd("electron-packager ./dist --overwrite --asar --platform=win32 --prune=true --out=publish --icon=src/img/tray.ico",cb);
};
// Publish the project
exports.publishWin32 = gulp.series(buildProduction, publishPostProcess, packageWin32);
/////////////////
// OTHER TASKS //
/////////////////
exports.css = gulp.series(copyAssets,run);
exports.clean = clean;
///////////////////////
// Utility Functions //
///////////////////////
// Run function to run a command and write the output live.
function runCmd(command, callback)
{
let process = exec(command, function (err, stdout, stderr)
{
if(callback != undefined)
{
callback(err);
}
});
process.stdout.on("data", function(data)
{
console.log(data);
});
}
// Download a file from the url and write it into target path.
function downloadFile(url, target, callback)
{
var file = fs.createWriteStream(target);
var request = http.get(url, function(response)
{
response.pipe(file).on("finish", callback);
});
}