Skip to content

Commit

Permalink
Remove bower references and bundle/inject references.
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Bloom committed Jun 13, 2018
1 parent 1fd4bef commit 56c1486
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 171 deletions.
4 changes: 0 additions & 4 deletions config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ module.exports = {
sourceMapEmbed: false,
uglify: false,
babel: false,
// Will bundle all bower JS dependencies (not devDeps) and create a `bower_components.min.js` file in `js.dest`.
bundleBower: true,
bundleBowerExclusions: [],
bowerBasePath: './',
eslint: {
enabled: true,
src: [
Expand Down
8 changes: 0 additions & 8 deletions docs/asset-injection-and-bower.md

This file was deleted.

2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const defaultConfig = require('./config.default');
module.exports = (gulp, userConfig, tasks) => {
const config = _.merge(defaultConfig, userConfig);

console.log('hello');

/* eslint-disable global-require */
if (config.browserSync.enabled) {
require('./lib/browser-sync')(gulp, config, tasks);
Expand Down
54 changes: 0 additions & 54 deletions lib/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const cached = require('gulp-cached');
const gulpif = require('gulp-if');
const del = require('del');
const browserSync = require('browser-sync');
const bowerFiles = require('main-bower-files');
const path = require('path');

module.exports = (gulp, config, tasks) => {
function validateJs() {
Expand Down Expand Up @@ -58,58 +56,6 @@ module.exports = (gulp, config, tasks) => {
});
});

/**
* Bundle up Bower JS Dependencies.
* Creates `bower--{devDeps,deps}.min.js` in `config.js.dest`.
* @param devDeps {boolean} If true, just devDeps, else just deps.
* @param done {function}
*/
function bundleBower(done, devDeps) {
const exclusions = config.js.bundleBowerExclusions;
const files = bowerFiles({
paths: config.patternLab.bowerBasePath || './',
filter: (filePath) => {
let isExcluded = false;
if (exclusions && exclusions.length) {
const directories = filePath.split('/');
// see if any directory name matches anything in the excluded list
isExcluded = directories.some(dir => exclusions.some(item => item === dir));
}
return path.extname(filePath) === '.js' && !(isExcluded);
},
includeDev: devDeps ? 'exclusive' : false, // `'exclusive'` does just devDeps w/o deps
});
if (files.length) {
gulp.src(files)
.pipe(sourcemaps.init())
.pipe(concat(`bower--${devDeps ? 'devDeps' : 'deps'}.min.js`))
.pipe(uglify())
.pipe(sourcemaps.write((config.js.sourceMapEmbed) ? null : './'))
.pipe(gulp.dest(config.js.dest))
.on('end', () => {
process.stdout.write(`Bower ${devDeps ? 'devDeps' : 'deps'} bundled: ${files.map(file => path.basename(file)).join(', ')}.\n`);
done();
});
} else {
done();
}
}

if (config.js.bundleBower) {
gulp.task('js:bundleBower', gulp.parallel(
function bundleBowerDeps(done) { bundleBower(done); },
function bundleBowerDevDeps(done) { bundleBower(done, true); }
));

// @todo remove `config.patternLab.bowerBasePath` in v10.0.0
const bowerBasePath = config.js.bowerBasePath || config.patternLab.bowerBasePath || './';
gulp.task('watch:bower', () => {
gulp.watch(path.join(bowerBasePath, 'bower.json'), gulp.series('js:bundleBower'));
});
tasks.compile.push('js:bundleBower');
tasks.watch.push('watch:bower');
}

tasks.clean.push('clean:js');
tasks.compile.push('js');
tasks.watch.push('watch:js');
Expand Down
45 changes: 2 additions & 43 deletions lib/pattern-lab--php-twig.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const _ = require('lodash');
const browserSync = require('browser-sync');
const glob = require('glob');

const plFullDependencies = [];

module.exports = (gulp, config, tasks) => {
let plConfig = yaml.safeLoad(
fs.readFileSync(config.patternLab.configFile, 'utf8')
Expand All @@ -30,49 +32,6 @@ module.exports = (gulp, config, tasks) => {

gulp.task('pl', done => plBuild(done, true));

// Begin `<link>` & `<script>` injecting code.
// Will look for these HTML comments in `plSource/_meta/*.twig:
// `<!-- inject:css -->`
// `<!-- endinject -->`
// `<!-- inject:js -->`
// `<!-- endinject -->`

function injectPl(done) {
let sources = [];
if (config.patternLab.injectFiles) {
sources = sources.concat(config.patternLab.injectFiles);
}
sources = sources.concat(glob.sync(path.normalize(`${config.js.dest}/*.js`)));
sources = sources.concat(glob.sync(path.normalize(`${config.css.dest}/*.css`)));

// We need to make sure our JS deps like jQuery are loaded before ours (`config.js.destName`)
const rearrangedSources = [];
sources.forEach((source) => {
if (path.basename(source) === config.js.destName) {
// add to end
rearrangedSources.push(source);
} else {
// add to beginning
rearrangedSources.unshift(source);
}
});

gulp
.src(['*.twig'], { cwd: plMeta })
.pipe(inject(gulp.src(rearrangedSources, { read: false }), {
relative: false,
addRootSlash: false,
addSuffix: '?cacheBuster={{ cacheBuster }}',
addPrefix: path.join('../..', path.relative(plPublic, process.cwd())),
}))
.pipe(gulp.dest(plMeta))
.on('end', done);
}

gulp.task('inject:pl', injectPl);

const plFullDependencies = ['inject:pl'];

// turns scss files full of variables into json files that PL can iterate on
function scssToJson(done) {
config.patternLab.scssToJson.forEach((pair) => {
Expand Down
59 changes: 0 additions & 59 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@
"gulp-uglify": "^1.5.1",
"js-yaml": "^3.12.0",
"lodash": "^4.17.10",
"main-bower-files": "^2.13.1",
"node-notifier": "^4.6.0",
"sassdoc": "^2.5.0"
},
"devDependencies": {
"eslint": "^3.4.0",
"gulp-debug": "^2.1.2",
"gulp-util": "^3.0.7",
"nodemon": "^1.17.5"
}
}
1 change: 0 additions & 1 deletion todos.md

This file was deleted.

0 comments on commit 56c1486

Please sign in to comment.