Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grunt task for browserify #75

Open
wants to merge 2 commits into
base: master
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
56 changes: 56 additions & 0 deletions generators/browserify/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const yeoman = require('yeoman-generator');
const yosay = require('yosay');
const _merge = require('lodash/merge');
const _includes = require('lodash/includes');

module.exports = yeoman.Base.extend({
prompting: {
browserify() {
const self = this;

this.log(yosay(
'Installing Browserify using create Bundle'
));
return this.prompt([{
type: 'input',
name: 'bundleFile',
message: 'which created bundle file?',
default: 'src/main.js',
when: () => !self.config.get('bundleFile'),
}])
.then(answers => {
self.bundleFile = self.config.get('bundleFile') || answers.bundleFile;
});
},
},
writing() {
// Read a package.json if it exists or create it
const packageJSON = this.fs.readJSON(this.destinationPath('package.json'), {});

// Read a aliases.js if it exists or create it
let aliasesJS = require(this.destinationPath('./grunt/aliases.js'));
// CodeCept
this.log('Configuring for Browserify');
// Convert JSON to an indented JS module.
aliasesJS = 'module.exports=' + JSON.stringify(_merge(aliasesJS, {
default: [],
bundle: [
'browserify',
],
}), null, 2);
_merge(packageJSON, {
devDependencies: {
'grunt-browserify': '^5.0.0',
},
});
this.fs.write(this.destinationPath('grunt/aliases.js'), aliasesJS);
this.fs.copyTpl(
this.templatePath('grunt/browserify.js'),
this.destinationPath('./grunt/browserify.js'),
{ fileName: this.bundleFile }
);
this.log('Writing to package.json');
this.fs.writeJSON(this.destinationPath('package.json'), packageJSON);
this.installDependencies();
},
});
6 changes: 6 additions & 0 deletions generators/browserify/templates/grunt/aliases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
default: [],
bundle: [
'browserify',
],
};
13 changes: 13 additions & 0 deletions generators/browserify/templates/grunt/browserify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
browserify: {
options: {
debug: true,
sourceMaps: true,
verbose: true,
keepAlive: true,
},
files: {
'dist/bundle.js': '<%= fileName %>',
},
},
};