-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
93 lines (87 loc) · 2.9 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
module.exports = function (grunt) {
jsOutputName = "bundle.js";
buildFullName = grunt.option("build");
buildPlatform = buildFullName.split(":").at(-1);
buildIsDev = buildFullName.includes("dev");
buildVariant = buildIsDev ? "dev" : "prod";
bundleLocation = `build/${buildPlatform}/${jsOutputName}`;
electronVersion = "1.3.5";
browserifyOptionDict = {
debug: buildIsDev ? true : false,
};
copyFiles = [];
if (buildFullName.includes("electron")) {
copyFiles = [
{src: ["package.json"], dest: "build/electron/package.json"},
{src: ["main-electron.js"], dest: "build/electron/index.js"},
{src: ["main.html"], dest: "build/electron/index.html"},
{expand: true, src: ["assets/**"], dest: "build/electron"}
];
}
else {
copyFiles = [
{src: ["main.html"], dest: "build/native/index.html"},
{expand: true, src: ["assets/**"], dest: "build/native"},
];
}
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
browserify: {
build: {
src: `main-native${buildIsDev ? "-dev" : ""}.js`,
dest: bundleLocation,
options: {
browserifyOptions: browserifyOptionDict,
transform: [["babelify", { "presets": ["@babel/preset-env"] }]],
}
}
},
uglify: {
options: {
banner: "// Copyright ProgrammingIncluded",
compress: false
},
dist: {
files: JSON.parse(`{"${bundleLocation}":"${bundleLocation}"}`)
}
},
copy: {
main: {
files: copyFiles
}
},
electron: {
winBuild: {
options: {
name: "Synthesia",
dir: "build/electron",
out: "build/electron/out",
version: electronVersion,
platform: "win32",
arch: "x64",
overwrite: true
}
}
},
watch: {
files: ["src/**/*.js", `main-${buildPlatform}.js`],
tasks: ["browserify"]
},
});
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-uglify-es');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-electron');
grunt.loadNpmTasks('grunt-contrib-watch');
let defaultTask = ["browserify", "copy"];
if(!buildFullName.includes("dev")) {
defaultTask.push("uglify");
}
else {
defaultTask.push("watch")
}
if(buildFullName.includes("electron")) {
defaultTask.push("electron");
}
grunt.registerTask("default", defaultTask);
};