Skip to content

Commit 729b178

Browse files
committed
Merge branch 'master' into v3.x
2 parents 53948af + 4ec271b commit 729b178

File tree

9 files changed

+37
-51
lines changed

9 files changed

+37
-51
lines changed

config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const errorHandler = err => {
2020

2121
// -- Validate Path
2222

23-
const bannerProject = path.join(cli.cwd, 'banner.txt');
2423
const confProject = require(path.join(cli.cwd, 'config'));
2524
const dataProject = require(path.join(cli.cwd, 'package.json'));
2625

@@ -45,7 +44,6 @@ module.exports = {
4544
//
4645

4746
project: {
48-
banner: bannerProject,
4947
data: dataProject,
5048
dir: cli.cwd,
5149
...confProject,

lib/trim.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const through = require('through2');
22

33
module.exports = () => {
44
return through.obj(function (file, enc, cb) {
5-
let content = file.contents.toString('utf8');
5+
let content = file.contents?.toString('utf8');
66

77
content = '\n\n\n\n' + content + '\n\n\n\n';
88
content = content.trim();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@buddywinangun/gulp-xtend",
3-
"version": "3.1.1",
3+
"version": "3.1.2",
44
"description": "A Starter kit for building web projects with Gulp.js",
55
"license": "MIT",
66
"homepage": "https://github.com/buddywinangun/gulp-xtend#readme",

start/banner.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

start/config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ module.exports = {
2424
},
2525
},
2626

27+
//
28+
// Banner Template | Append of banner in script js or css
29+
//
30+
31+
banner: ['/**',
32+
' * <%= data.title %> v<%= data.version %> <%= "("+data.homepage+")" %>',
33+
' * Copyright ' + (new Date()).getFullYear() + ' <%= data.author.name %>',
34+
' * Licensed under <%= data.license %>',
35+
' */',
36+
''
37+
].join('\n'),
38+
2739
//
2840
// Language Direction
2941
//

tasks/sass.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,10 @@ gulp.task('sass-compile', (done) => {
5555
if (!config.settings.sass) return done();
5656

5757
const banner = {
58-
text: stripIndent(
59-
fs.readFileSync(sassOpts.compile.banner.text, 'utf8').trim()
60-
) + '\n\n',
58+
text: sassOpts.compile.banner.text,
6159
data: sassOpts.compile.banner.data
6260
};
6361

64-
// theme.ext
65-
let buildExt = '.css'; // .ext
66-
6762
// Run tasks on all Sass files
6863
gulp.src(sassOpts.compile.src)
6964
.pipe(plumber(config.utils.errorHandler))
@@ -85,7 +80,7 @@ gulp.task('sass-compile', (done) => {
8580
]))
8681
.pipe(replace('/*!', '/*'))
8782
.pipe(rename(function (p) {
88-
p.extname = buildExt;
83+
p.extname = '.css';
8984
}))
9085
.pipe(trim())
9186
.pipe(!config.utils.isProd ? noop() : cleancss({

tasks/script.js

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88

99
const gulp = require('gulp');
1010
const sourcemaps = require("gulp-sourcemaps");
11-
const rename = require("gulp-rename");
1211
const noop = require("gulp-noop");
1312
const plumber = require("gulp-plumber");
1413
const path = require("path");
1514
const header = require("gulp-header");
16-
const glob = require('glob');
1715
const stripIndent = require('strip-indent');
1816
const fs = require("fs");
1917
const trim = require('../lib/trim');
@@ -45,14 +43,8 @@ const opts = config.paths.version(config.project, path);
4543

4644
const jsOpts = {
4745
compile: {
48-
src: {
49-
dir: path.join(opts.src, 'js', 'index.js'),
50-
filename: 'index.js',
51-
},
52-
dest: {
53-
dir: path.join(opts.build, config.project.paths.assets, 'js'),
54-
filename: 'script.js',
55-
},
46+
src: path.join(opts.src, 'js'),
47+
dest: path.join(opts.build, config.project.paths.assets, 'js'),
5648
banner: {
5749
text: config.project.banner,
5850
data: config.project
@@ -69,29 +61,22 @@ gulp.task('script-compile', (done) => {
6961
// Make sure this feature is activated before running
7062
if (!config.settings.script) return done();
7163

72-
// index.ext
73-
let srcExt = path.extname(jsOpts.compile.src.filename); // .ext
74-
let srcName = path.basename(jsOpts.compile.src.filename, srcExt); // index
75-
// script.ext
76-
let buildExt = path.extname(jsOpts.compile.dest.filename); // .ext
77-
let buildName = path.basename(jsOpts.compile.dest.filename, buildExt); // script
78-
79-
const variant = path.join(jsOpts.compile.src.dir, srcName + '-*' + srcExt);
80-
81-
const files = [
82-
jsOpts.compile.src.dir,
83-
...glob.sync(variant)
84-
];
64+
let files = [];
65+
const fileList = fs.readdirSync(jsOpts.compile.src)
66+
for (const file of fileList) {
67+
const filePath = `${path.join(jsOpts.compile.src, file)}`
68+
const srcExt = `${path.extname(file)}`; // .ext
69+
if (fs.statSync(filePath).isFile() && srcExt === '.js') {
70+
files.push(filePath)
71+
}
72+
}
8573

8674
const banner = {
87-
text: stripIndent(
88-
fs.readFileSync(jsOpts.compile.banner.text, 'utf8').trim()
89-
) + '\n\n',
75+
text: jsOpts.compile.banner.text,
9076
data: jsOpts.compile.banner.data
9177
};
9278

9379
const bundles = files.map(entry => {
94-
9580
const options = {
9681
input: entry,
9782
output: {
@@ -125,11 +110,6 @@ gulp.task('script-compile', (done) => {
125110
.pipe(plumber(config.utils.errorHandler))
126111
.pipe(source(path.basename(entry)))
127112
.pipe(buffer())
128-
.pipe(rename(function (p) {
129-
p.basename = p.basename.replace(srcName + '-', buildName + '-');
130-
p.basename = p.basename.replace(srcName, buildName);
131-
p.extname = buildExt;
132-
}))
133113
.pipe(trim())
134114
.pipe(!config.utils.isProd ? noop() : terser({
135115
mangle: true,
@@ -146,7 +126,7 @@ gulp.task('script-compile', (done) => {
146126
loadMaps: true
147127
}))
148128
.pipe(config.utils.isProd ? noop() : sourcemaps.write('./maps'))
149-
.pipe(gulp.dest(jsOpts.compile.dest.dir, {
129+
.pipe(gulp.dest(jsOpts.compile.dest, {
150130
overwrite: true
151131
}));
152132
});

tasks/static.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ gulp.task('static-compile', done => {
3434
if (!config.settings.static) return done();
3535

3636
// Copy static files
37-
return gulp.src(staticOpts.compile.src)
37+
gulp.src(staticOpts.compile.src)
3838
.pipe(gulp.dest(staticOpts.compile.dest, {
3939
overwrite: true
4040
}));
41+
42+
// Signal completion
43+
done();
4144
});
4245

4346
gulp.task('static-tasks', gulp.series(

tasks/svgs.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ gulp.task('svgs-compile', done => {
3535
if (!config.settings.svgs) return done();
3636

3737
// Optimize SVG files
38-
return gulp.src(svgOpts.compile.src)
38+
gulp.src(svgOpts.compile.src)
3939
.pipe(svgmin())
4040
.pipe(gulp.dest(svgOpts.compile.dest, {
4141
overwrite: true
4242
}));
43+
44+
// Signal completion
45+
done();
4346
});
4447

4548
gulp.task('svgs-tasks', gulp.series(

0 commit comments

Comments
 (0)