-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
146 lines (125 loc) Β· 3.54 KB
/
gulpfile.babel.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
146
/*
Gulp file revised from ghost-theme-template and casper:
https://github.com/thoughtbot/ghost-theme-template/blob/master/gulpfile.babel.js
https://github.com/TryGhost/Casper/blob/master/gulpfile.js
- Use /assets/css/ and /assets/js/ folders
- Compiles and minifies app.scss to app.css
- Concatenates and minifies js files to app.js
*/
"use strict";
var gscan = require("gscan");
import _ from "lodash";
import autoprefix from "gulp-autoprefixer";
import chalk from "chalk";
import cleanCSS from "gulp-clean-css";
import concat from "gulp-concat";
import gulp from "gulp";
import jshint from "gulp-jshint";
import pkg from "./package.json";
import run from "run-sequence";
import sass from "gulp-sass";
import sasslint from "gulp-sass-lint";
import sourcemaps from "gulp-sourcemaps";
import stylish from "jshint-stylish";
import uglify from "gulp-uglify-es";
import zip from "gulp-zip";
const paths = {
scss: "./assets/css/**/*.scss",
scssApp: "./assets/css/app.scss",
js: "./assets/js/**/*.js",
jsBuilt: "app.js",
built: "./assets/built/",
};
const levels = {
error: chalk.red,
warning: chalk.yellow,
recommendation: chalk.yellow,
feature: chalk.green,
};
gulp.task("sass", (cb) =>
gulp
.src(paths.scssApp)
.pipe(sourcemaps.init())
.pipe(sass().on("error", sass.logError))
.pipe(autoprefix("last 2 versions"))
.pipe(cleanCSS({ compatibility: "ie8" }))
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest(paths.built))
);
gulp.task("sasslint", () =>
gulp
.src(paths.scss)
.pipe(
sasslint({
options: {
formatter: "stylish",
},
configFile: ".sass-lint.yml",
})
)
.pipe(sasslint.format())
);
gulp.task("js", () =>
gulp
.src(paths.js)
.pipe(sourcemaps.init())
.pipe(concat(paths.jsBuilt))
.pipe(gulp.dest(paths.built))
.pipe(uglify())
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest(paths.built))
);
gulp.task("jshint", (cb) =>
gulp.src(paths.js).pipe(jshint()).pipe(jshint.reporter("jshint-stylish"))
);
gulp.task("scan", (cb) => {
function outputResult(result) {
console.log("-", levels[result.level](result.level), result.rule);
}
function outputResults(theme) {
theme = gscan.format(theme);
console.log(chalk.bold.underline("\nRule Report:"));
if (!_.isEmpty(theme.results.error)) {
console.log(chalk.red.bold.underline("\n! Must fix:"));
_.each(theme.results.error, outputResult);
}
if (!_.isEmpty(theme.results.warning)) {
console.log(chalk.yellow.bold.underline("\n! Should fix:"));
_.each(theme.results.warning, outputResult);
}
if (!_.isEmpty(theme.results.recommendation)) {
console.log(chalk.red.yellow.underline("\n? Consider fixing:"));
_.each(theme.results.recommendation, outputResult);
}
if (!_.isEmpty(theme.results.pass)) {
console.log(
chalk.green.bold.underline(
"\n\u2713",
theme.results.pass.length,
"Passed Rules"
)
);
}
console.log("\n...checks complete.");
cb();
}
gscan
.checkZip({
path: `./${pkg.name}.zip`,
name: pkg.name,
})
.then(outputResults);
});
gulp.task("zip", () =>
gulp
.src(["./**/*", "!./node_modules/**", `!./${pkg.name}.zip`, "!**.map"])
.pipe(zip(`./${pkg.name}.zip`))
.pipe(gulp.dest("."))
);
gulp.task(
"default",
gulp.series("sass", "sasslint", "js", "jshint"),
gulp.watch(paths.scss, gulp.series("sass", "sasslint")),
gulp.watch(paths.js, gulp.series("js", "jshint"))
);
gulp.task("deploy", gulp.series("sass", "zip", "scan"));