Skip to content
This repository has been archived by the owner on Aug 8, 2019. It is now read-only.

Feature/update scripts #173

Open
wants to merge 7 commits into
base: feature/base-generator-v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 47 additions & 48 deletions __tests__/gulp.js
Original file line number Diff line number Diff line change
@@ -1,89 +1,88 @@
'use strict';
const path = require('path');
const assert = require('yeoman-assert');
const helpers = require('yeoman-test');
"use strict";
const path = require("path");
const assert = require("yeoman-assert");
const helpers = require("yeoman-test");

describe('generator-one-base:gulp', () => {
describe('default', () => {
describe("generator-one-base:gulp", () => {
describe("default", () => {
beforeAll(() => {
return helpers.run(path.join(__dirname, '../generators/gulp'))
return helpers
.run(path.join(__dirname, "../generators/gulp"))
.withOptions({
skipInstall: false,
rootDistPath: 'dist',
templateSrc: 'src/templates/',
templateDist: 'dist/',
serverBaseDir: 'dist/',
rootDistPath: "dist",
templateSrc: "src/templates/",
templateDist: "dist/",
serverBaseDir: "dist/",
useProxy: false,
useNunjucks: false
});
});

it('creates files', () => {
it("creates files", () => {
assert.file([
'gulpfile.js',
'.stylelintrc',
'gulp/tasks',
'gulp/tasks/base.js',
'gulp/tasks/build.js'
"gulpfile.js",
".stylelintrc",
"gulp/webpack.config.js",
"gulp/tasks",
"gulp/tasks/base.js",
"gulp/tasks/build.js"
]);
});

it('doesn\'t create index.html', () => {
assert.noFile('src/templates/index.twig');
it("doesn't create index.html", () => {
assert.noFile("src/templates/index.twig");
});

it('adds .gitgnore rules', () => {
assert.fileContent('.gitignore', '/dist');
it("adds .gitgnore rules", () => {
assert.fileContent(".gitignore", "/dist");
});

it('adds dependencies', () => {
assert.fileContent('package.json', 'gulp');
assert.fileContent('package.json', 'dotenv');
assert.fileContent('package.json', 'run-sequence');
it("adds dependencies", () => {
assert.fileContent("package.json", "gulp");
assert.fileContent("package.json", "dotenv");
assert.fileContent("package.json", "run-sequence");
});

it("doesn't create nunjucks build files", () => {
assert.noFile([
'gulp/tasks/nunjucks.js'
]);
assert.noFileContent('gulp/tasks/base.js', "'nunjucks',");
assert.noFileContent('gulp/tasks/watch.js', "runSequence('nunjucks')");
assert.noFile(["gulp/tasks/nunjucks.js"]);
assert.noFileContent("gulp/tasks/base.js", "'nunjucks',");
assert.noFileContent("gulp/tasks/watch.js", "runSequence('nunjucks')");
});

it("doesn't add nunjucks as a dep", () => {
assert.noFileContent('package.json', 'gulp-nunjucks-render');
assert.noFileContent("package.json", "gulp-nunjucks-render");
});
});

describe('with nunjucks enabled', () => {
describe("with nunjucks enabled", () => {
beforeAll(() => {
return helpers.run(path.join(__dirname, '../generators/gulp'))
return helpers
.run(path.join(__dirname, "../generators/gulp"))
.withOptions({
skipInstall: false,
rootDistPath: 'dist',
templateSrc: 'src/templates/',
templateDist: 'dist/',
serverBaseDir: 'dist/',
rootDistPath: "dist",
templateSrc: "src/templates/",
templateDist: "dist/",
serverBaseDir: "dist/",
useProxy: false,
useNunjucks: true
});
});

it('creates nunjucks build files', () => {
assert.file([
'gulp/tasks/nunjucks.js'
]);
assert.fileContent('gulp/tasks/base.js', "'nunjucks',");
assert.fileContent('gulp/tasks/watch.js', "runSequence('nunjucks')");
it("creates nunjucks build files", () => {
assert.file(["gulp/tasks/nunjucks.js"]);
assert.fileContent("gulp/tasks/base.js", "'nunjucks',");
assert.fileContent("gulp/tasks/watch.js", "runSequence('nunjucks')");
});

it('creates nunjucks templates', () => {
assert.file('src/templates/index.twig');
assert.file('src/templates/_layout.twig');
it("creates nunjucks templates", () => {
assert.file("src/templates/index.twig");
assert.file("src/templates/_layout.twig");
});

it('adds nunjucks as a dep', () => {
assert.fileContent('package.json', 'gulp-nunjucks-render');
it("adds nunjucks as a dep", () => {
assert.fileContent("package.json", "gulp-nunjucks-render");
});
});
});
134 changes: 73 additions & 61 deletions generators/gulp/index.js
Original file line number Diff line number Diff line change
@@ -1,117 +1,129 @@
'use strict';
const Generator = require('yeoman-generator');
const chalk = require('chalk');
const prompts = require('./modules/prompts');
const fs = require('fs');
"use strict";
const Generator = require("yeoman-generator");
const chalk = require("chalk");
const prompts = require("./modules/prompts");
const fs = require("fs");

module.exports = class extends Generator {
prompting() {
return this.prompt(prompts(this.options)).then(function(options) {
Object.assign(this.options, options);
}.bind(this));
return this.prompt(prompts(this.options)).then(
function(options) {
Object.assign(this.options, options);
}.bind(this)
);
}

eslint() {
this.composeWith(require.resolve('../eslint'));
this.composeWith(require.resolve("../eslint"));
}

stylelint() {
this.composeWith(require.resolve('../stylelint'));
this.composeWith(require.resolve("../stylelint"));
}

writing() {
this.log(chalk.green('Writing gulp files...'));
this.log(chalk.green("Writing gulp files..."));

this.fs.copy(
this.templatePath('gulpfile.js'),
this.destinationPath('gulpfile.js')
this.templatePath("gulpfile.js"),
this.destinationPath("gulpfile.js")
);

this.fs.copy(
this.templatePath("gulp/webpack.config.js"),
this.destinationPath("gulp/webpack.config.js")
),
this.fs.copyTpl(
this.templatePath('gulp/tasks'),
this.destinationPath('gulp/tasks'), this.options, {}, {
this.templatePath("gulp/tasks"),
this.destinationPath("gulp/tasks"),
this.options,
{},
{
globOptions: {
ignore: this.options.useNunjucks ? [] : ['**/nunjucks.js']
ignore: this.options.useNunjucks ? [] : ["**/nunjucks.js"]
}
}
);

if (this.fs.exists('.gitignore')) {
if (this.fs.exists(".gitignore")) {
this.fs.append(
this.destinationPath('.gitignore'),
fs.readFileSync(this.templatePath('.gitignore'))
this.destinationPath(".gitignore"),
fs.readFileSync(this.templatePath(".gitignore"))
);
} else {
this.fs.copy(
this.templatePath('.gitignore'),
this.destinationPath('.gitignore')
this.templatePath(".gitignore"),
this.destinationPath(".gitignore")
);
}

this.fs.copy(
this.templatePath('gulp/utils'),
this.destinationPath('gulp/utils')
this.templatePath("gulp/utils"),
this.destinationPath("gulp/utils")
);

this.fs.copyTpl(
this.templatePath('gulp/config.ejs'),
this.destinationPath('gulp/config.js'),
this.templatePath("gulp/config.ejs"),
this.destinationPath("gulp/config.js"),
this.options
);

if (this.options.useNunjucks) {
this.fs.copyTpl(
this.templatePath('templates'),
this.destinationPath('src/templates'),
this.templatePath("templates"),
this.destinationPath("src/templates"),
this.options
);
}
}

install() {
const devDependencies = [
'webpack@^3.11.0',
'babel-core',
'babel-loader',
'babel-preset-env',
'babel-preset-react',
'browser-sync',
'del',
'dotenv',
'gulp',
'autoprefixer',
'gulp-changed-in-place',
'gulp-css-globbing',
'gulp-eslint',
'gulp-postcss',
'gulp-imagemin',
'gulp-pixrem',
'gulp-replace',
'gulp-rev',
'gulp-sass',
'gulp-shell',
'gulp-stylelint',
'gulp-util',
'jsonfile',
'node-libs-browser',
'postcss-import',
'require-dir',
'run-sequence',
'script-loader',
'strip-ansi'
"autoprefixer",
"babel-core",
"babel-loader",
"babel-preset-env",
"babel-preset-react",
"browser-sync",
"del",
"dotenv",
"eslint-loader",
"gulp-changed-in-place",
"gulp-css-globbing",
"gulp-eslint",
"gulp-imagemin",
"gulp-pixrem",
"gulp-postcss",
"gulp-replace",
"gulp-rev",
"gulp-sass",
"gulp-shell",
"gulp-stylelint",
"gulp",
"jsonfile",
"node-libs-browser",
"postcss-import",
"require-dir",
"react-dev-utils",
"run-sequence",
"script-loader",
"strip-ansi",
"webpack",
"webpack-dev-middleware",
"webpack-hot-middleware"
];

// Add nunjucks if desired
if (this.options.useNunjucks) {
devDependencies.push('gulp-nunjucks-render');
devDependencies.push("gulp-nunjucks-render");
}

// Display a message
this.log(chalk.yellow('\nInstalling gulp-related dependencies…'));
this.log(chalk.yellow("\nInstalling gulp-related dependencies…"));

// Install dev dependencies
this.yarnInstall(devDependencies, { 'dev': true, silent: true }).then(() => {
this.log(chalk.green('Installed gulp-related dependencies.'));
// Install dev k
this.yarnInstall(devDependencies, { dev: true, silent: true }).then(() => {
this.log(chalk.green("Installed gulp-related dependencies."));
});
}
};
24 changes: 23 additions & 1 deletion generators/gulp/templates/gulp/config.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,23 @@ module.exports = {
proxyUrl: process.env.APP_SITE_URL || undefined,
serverBaseDir: '<%= serverBaseDir %>',

// @TODO: move this into package.json
// in here because babel won't support it in there until v7
browserlist: [
'> 1%',
'last 2 versions'
],

scripts: {
// Passed directly into webpack.ProvidePlugin
// @see https://webpack.js.org/plugins/provide-plugin/
provide: {
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
},


// entry files:
// each filename listed here (and found in scriptSrc)
// will have a file generated for it in scriptDist
Expand Down Expand Up @@ -70,6 +86,12 @@ module.exports = {

aliases: {

}
},

// Instantiate any additional webpack plugins here
additionalWebpackplugins: [],

// Set to false to disable hotModuleReplacement
hot: true
}
};
2 changes: 0 additions & 2 deletions generators/gulp/templates/gulp/tasks/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ module.exports = gulp.task('base', function(callback) {
[
'templates',<% if (useNunjucks) { %>
'nunjucks',<% } %>
'scripts:bundle',
'scripts:lint',
'styles',
'styles:copy',
'styles:lint',
Expand Down
Loading