-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
107 lines (95 loc) · 3.14 KB
/
gulpfile.js
File metadata and controls
107 lines (95 loc) · 3.14 KB
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
const gulp = require("gulp");
const uglify = require("gulp-uglify-es").default;
const pipeline = require("readable-stream").pipeline;
const fs = require("fs");
const chalk = require("chalk");
const rimraf = require("rimraf");
const path = require("path");
/**
* cleaning the all build when wrong goes
*/
gulp.task("clean", (cb) => {
rimraf("./build", () => {
console.log(chalk.red("Build Cleaned ..."));
});
cb();
});
/**
* compress the typescript original file into minify typescript file
*/
gulp.task("compress", (cb) => {
console.log(chalk.green("File created Succesfully ..."));
// compress file typescript.js imto minify to dist js folder
return pipeline(
gulp.src("static_file/typescript.js"),
uglify(),
gulp.dest("dist/js/")
);
});
/**
* build folder creation for storing all build files in it
*/
gulp.task("create_folder", (cb) => {
fs.mkdir(path.join(__dirname, "build"), () => {
console.log(chalk.red("build folder is created"));
});
cb();
});
/**
* move script to build folder and compress the static_file.js because for compiler of typescript with these file no need to load extra file in your html file
*/
gulp.task("move_script", (cb) => {
console.log(chalk.red("typescript.js moved"));
// move dist typescript.js to build typescript.js
gulp.src(path.join(__dirname, "dist", "js", "typescript.js")).pipe(
gulp.dest(path.join(__dirname, "build"))
);
console.log(chalk.red("middleware_ts.js moved"));
// move from dist middleware_ts.js to build folder
gulp.src(path.join(__dirname, "dist", "middleware_ts.js")).pipe(
gulp.dest(path.join(__dirname, "build"))
);
console.log(chalk.red("compressing static_file.js and moved"));
// compress and move into build folder
return pipeline(
gulp.src(path.join(__dirname, "dist", "js", "static_file.js")),
uglify(),
gulp.dest(path.join(__dirname, "build"))
);
cb();
});
/**
* merging static_file.js minified script to typescript at the end
* and remove the file static that is in build folder
*/
gulp.task("merge_to_typescript", (cb) => {
// read file from build static_file.js
let custom_js = fs.readFileSync(
path.join(__dirname, "build", "static_file.js")
);
// appending all files into typescript of static_file
fs.appendFile(
path.join(__dirname, "build", "typescript.js"),
custom_js.toString(),
(err) => {
if (err) throw err;
console.log(
chalk.grey("file appending done \n now deleting static_file.js")
);
// now unlink static_file after merging into main file
fs.unlink(
path.join(__dirname, "build", "static_file.js"),
(err) => {
console.log(chalk.red("File deleted ..."));
}
);
}
);
cb();
});
// clean gulp clean
exports.clean = gulp.series("clean");
// compress command gulp command
exports.compress = gulp.series("compress");
// run build script command gulp
exports.default = gulp.series("move_script", "merge_to_typescript");