init
This commit is contained in:
commit
3d91068e08
71 changed files with 4490 additions and 0 deletions
58
build/task/smartcss.js
Normal file
58
build/task/smartcss.js
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
const gulp = require('gulp'),
|
||||
HelperUnit = require('./../tools/helperUnit'),
|
||||
sass = require('gulp-sass'),
|
||||
clean = require('gulp-clean-css'),
|
||||
path = require('path'),
|
||||
workers = [];
|
||||
|
||||
class SCSSWorker {
|
||||
constructor(config, helper) {
|
||||
this.config = config;
|
||||
this.helper = helper.clone();
|
||||
this.input = this.helper.replaceVariables(this.config.input);
|
||||
this.watchInput = '.' + this.helper.replaceAbsolutePath(this.input);
|
||||
this.helper.addConfigItem("$name", this.config.name);
|
||||
this.helper.addConfigItem("$watch", this.watchInput);
|
||||
this.helper.addConfigItem("$", this.input);
|
||||
this.out = this.helper.replaceVariables(this.config.output);
|
||||
this.watch = this.helper.replaceVariables(this.config.watch || '$watch');
|
||||
gulp.task(this.taskName, this.work.bind(this));
|
||||
}
|
||||
|
||||
startWatch() {
|
||||
console.log(`[WATCH][${this.config.name}] >> ${this.watch}`);
|
||||
gulp.watch(this.watch, gulp.series(this.taskName))
|
||||
}
|
||||
|
||||
get taskName() {
|
||||
return `scss-${this.config.name || 'unknown'}`;
|
||||
}
|
||||
|
||||
work() {
|
||||
return gulp.src(this.input)
|
||||
.pipe(sass().on('error', sass.logError))
|
||||
.pipe(clean())
|
||||
.pipe(gulp.dest(this.out));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
build: function () {
|
||||
let array = [];
|
||||
for (let worker of workers) {
|
||||
array.push(worker.taskName);
|
||||
}
|
||||
return array;
|
||||
},
|
||||
prepare: function (config) {
|
||||
const scss = config.scss || [];
|
||||
for (let scssItem of scss) {
|
||||
workers.push(new SCSSWorker(scssItem, config.helper));
|
||||
}
|
||||
},
|
||||
startWatch: function () {
|
||||
for (let worker of workers) {
|
||||
worker.startWatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
53
build/task/smarticon.js
Normal file
53
build/task/smarticon.js
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
const gulp = require('gulp'),
|
||||
builder = require('./../tools/iconSprite'),
|
||||
workers = [];
|
||||
|
||||
class IconWorker {
|
||||
constructor(icon, helper) {
|
||||
this.config = icon;
|
||||
this.helper = helper.clone();
|
||||
this.input = this.helper.replaceVariables(this.config.input);
|
||||
this.watchInput = '.' + this.helper.replaceAbsolutePath(this.input);
|
||||
this.helper.addConfigItem("$name", this.config.name);
|
||||
this.helper.addConfigItem("$watch", this.watchInput);
|
||||
this.helper.addConfigItem("$", this.input);
|
||||
this.out = this.helper.replaceVariables(this.config.output);
|
||||
this.watch = this.helper.replaceVariables(this.config.watch || '$watch');
|
||||
gulp.task(this.taskName, this.work.bind(this));
|
||||
}
|
||||
|
||||
startWatch() {
|
||||
console.log(`[WATCH][${this.config.name}] >> ${this.watch}`);
|
||||
gulp.watch(this.watch, gulp.series(this.taskName))
|
||||
}
|
||||
|
||||
get taskName() {
|
||||
return `icon-${this.config.name}`;
|
||||
}
|
||||
|
||||
work() {
|
||||
builder.buildIconSprites(this);
|
||||
return gulp.src(this.input)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
build: function () {
|
||||
let array = [];
|
||||
for (let worker of workers) {
|
||||
array.push(worker.taskName);
|
||||
}
|
||||
return array;
|
||||
},
|
||||
prepare: function (config) {
|
||||
const icons = config.icons || [];
|
||||
for (let icon of icons) {
|
||||
workers.push(new IconWorker(icon, config.helper));
|
||||
}
|
||||
},
|
||||
startWatch: function () {
|
||||
for (let worker of workers) {
|
||||
worker.startWatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
116
build/task/smartjs.js
Normal file
116
build/task/smartjs.js
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
const closureCompiler = require('google-closure-compiler').gulp(),
|
||||
concat = require('gulp-concat'),
|
||||
gulp = require('gulp'),
|
||||
path = require('path'),
|
||||
fileInclude = require('./../tools/file-includer'),
|
||||
workers = [];
|
||||
|
||||
class JSWorker {
|
||||
constructor(config, helper) {
|
||||
this.config = config;
|
||||
this.helper = helper.clone();
|
||||
if (!this.config.name) {
|
||||
throw Error("Found Empty name for JS Job...");
|
||||
}
|
||||
this.validateConfig();
|
||||
this.input = this.helper.replaceVariables(this.config.input);
|
||||
this.watchInput = '.' + this.helper.replaceAbsolutePath(this.input);
|
||||
this.helper.addConfigItem("$name", this.config.name);
|
||||
this.helper.addConfigItem("$watch", this.watchInput)
|
||||
this.helper.addConfigItem("$", this.input);
|
||||
this.getCompilerConfig();
|
||||
this.out = this.helper.replaceVariables(this.config.output);
|
||||
this.watch = this.helper.replaceVariables(this.config.watch || '$watch/**/*.js');
|
||||
if (this.config.includeFile) {
|
||||
this.includeFile = `${this.input}/${this.config.includeFile}`;
|
||||
}
|
||||
this.prepareFiles()
|
||||
this.path = path.parse(this.out);
|
||||
this.path = this.path.dir + "/" + this.path.base + "/";
|
||||
gulp.task(this.taskName, this.work.bind(this));
|
||||
}
|
||||
|
||||
validateConfig() {
|
||||
let config = this.config;
|
||||
config.onlyMinify = config.onlyMinify || false;
|
||||
config.minify = config.minify || false;
|
||||
if (!this.config.input || !this.config.output || !(this.config.files || this.config.includeFile)) {
|
||||
throw Error("Invalid Config for: " + this.config.name + ")");
|
||||
}
|
||||
}
|
||||
|
||||
getCompilerConfig() {
|
||||
this.compiler = {
|
||||
compilation_level: 'SIMPLE',
|
||||
warning_level: 'VERBOSE',
|
||||
language_in: 'ECMASCRIPT6_STRICT',
|
||||
language_out: 'ECMASCRIPT6_STRICT',
|
||||
js_output_file: this.config.name + ".min.js"
|
||||
}
|
||||
if (this.config.compiler) {
|
||||
this.compiler = Object.assign(this.compiler, this.config.compiler);
|
||||
}
|
||||
this.compiler.js_output_file = this.helper.replaceVariables(this.compiler.js_output_file);
|
||||
}
|
||||
|
||||
startWatch() {
|
||||
console.log(`[WATCH][${this.config.name}] >> ${this.watch}`);
|
||||
const watchArray = [this.watch];
|
||||
if (this.includeFile) {
|
||||
watchArray.push(this.includeFile);
|
||||
}
|
||||
gulp.watch(watchArray, gulp.parallel([this.taskName]));
|
||||
}
|
||||
|
||||
get taskName() {
|
||||
return `js-${this.config.name}`;
|
||||
}
|
||||
|
||||
prepareFiles() {
|
||||
if (this.config.includeFile) {
|
||||
this.files = fileInclude.findFiles(this.input, this.includeFile, this.helper);
|
||||
} else {
|
||||
this.files = [];
|
||||
for (const file of this.config.files) {
|
||||
this.files.push(this.input + "/" + this.helper.replaceVariables(file));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
work() {
|
||||
if (this.config.includeFile) {
|
||||
this.prepareFiles();
|
||||
}
|
||||
let d = gulp.src(this.files).pipe(concat(this.config.name + '.js'))
|
||||
if (!this.config.onlyMinify) {
|
||||
d.pipe(gulp.dest(this.path));
|
||||
}
|
||||
if (this.config.minify) {
|
||||
d.pipe(closureCompiler(this.compiler)).pipe(gulp.dest(this.path));
|
||||
}
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
build: function () {
|
||||
let array = [];
|
||||
for (let worker of workers) {
|
||||
array.push(worker.taskName);
|
||||
}
|
||||
return array;
|
||||
},
|
||||
prepare: function (config) {
|
||||
// we load the json and parse it here
|
||||
const js = config.js || [];
|
||||
for (let jsConfig of js) {
|
||||
const worker = new JSWorker(jsConfig, config.helper);
|
||||
workers.push(worker);
|
||||
}
|
||||
},
|
||||
startWatch: function () {
|
||||
for (let worker of workers) {
|
||||
worker.startWatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue