This repository has been archived by the owner on Oct 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
44 lines (42 loc) · 2.14 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
/* jshint esversion: 6, undef: true, node: true */
/* \CONFIG\ */
const config= (function(){
const { spawn, exec }= require("child_process");
let $o_default= {spawn, exec, fs: require("fs")};
const gulp= require('gulp'),
$gulp_folder= "./gulp/",
{ fullName, name, version, build, directories, sequence, dependencies, devDependencies, homepage }= JSON.parse($o_default.fs.readFileSync('./package.json')),
{ $g, $o }= mapDependencies(Object.assign({}, dependencies, devDependencies), $o_default);
const app= { name: fullName, folderName: name, version, build, directories, sequence, homepage };
return {gulp, $gulp_folder, $g, $o, app, error: error()};
})();
/* /CONFIG/ */
/* \Tasks\ */
var c_output= [], if_error= 0;
const tasks= ['default', 'doc', 'javascript', 'examples'], tasks_length= tasks.length;
for(let i=0, task; i<tasks_length; i++){ task= tasks[i]; config.gulp.task(task, require(config.$gulp_folder+'task-'+task)(config)); }
/* /Tasks/ */
/* \Global functions\ */
function error(){
function getText(){ return c_output.join("\n"); }
function addText(err){ c_output.push(err); }
function getNum(){ return if_error; }
function addNum(num=1){ if_error+= num; }
function handler(err){ addNum(); config.$g.util.log(config.$g.util.colors.red('[Error]'), err.toString()); }
return { getText, addText, getNum, addNum, handler };
}
function mapDependencies(dependencies, $o_default){
const dependencies_keys= Object.keys(dependencies);
const pre= "gulp-";
const rename= {"gulp-minify": "gulp-minify_js", "gulp-javascript-obfuscator": "gulp-js_obfuscator"}, rename_keys= Object.keys(rename);
let out= {$g: {} /* for "gulp-" */ , $o: $o_default /* for others */};
dependencies_keys.forEach(cmd=>{
if(cmd==="gulp") return false;
let out_key= "$o";
const name= rename_keys.indexOf(cmd)!==-1 ? rename[cmd].replace(pre, setTo$g) : cmd.replace(pre, setTo$g);
out[out_key][name]= require(cmd);
function setTo$g(...arg){ if(arg.length){ out_key= "$g"; } return ""; }
});
return out;
}
/* /Global functions/ */