Skip to content

Commit

Permalink
Add client side build functionality (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Aug 25, 2018
1 parent d345e0c commit d61b876
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 26 deletions.
51 changes: 35 additions & 16 deletions packages/generator-feathers-plugin/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const Generator = require('yeoman-generator');
const path = require('path');
const pkgForClient = require('./templates/client/package.json.js');

module.exports = class FeathersPluginGenerator extends Generator {
constructor (args, opts) {
Expand All @@ -23,8 +24,7 @@ module.exports = class FeathersPluginGenerator extends Generator {
}

prompting () {
var done = this.async();
var prompts = [{
const prompts = [{
name: 'name',
message: 'Project name',
when: !this.pkg.name,
Expand All @@ -37,22 +37,42 @@ module.exports = class FeathersPluginGenerator extends Generator {
name: 'description',
message: 'Description',
when: !this.pkg.description
}, {
type: 'confirm',
name: 'client',
default: false,
message: 'Does this plugin require a client side build?'
}];

this.prompt(prompts).then(function (props) {
return this.prompt(prompts).then(props => {
this.props = Object.assign(this.props, props);

done();
}.bind(this));
});
}

writing () {
const devDependencies = [
'semistandard',
'mocha',
'istanbul@1.1.0-alpha.1',
'chai@^3.5.0'
];

if (this.props.client) {
devDependencies.push('babel-core',
'babel-preset-es2015',
'babelify',
'browserify',
'shx',
'uglify-js'
);
}

this.fs.copy(this.templatePath('static/.*'), this.destinationPath());
this.fs.copy(this.templatePath('static/**/*'), this.destinationPath());
this.fs.copy(this.templatePath('static/.github/**/*'), this.destinationPath('.github/'));

Object.keys(this.fileMap).forEach(function (src) {
var target = this.fileMap[src];
const target = this.fileMap[src];

this.fs.copyTpl(
this.templatePath(src),
Expand All @@ -61,16 +81,15 @@ module.exports = class FeathersPluginGenerator extends Generator {
);
}.bind(this));

this.npmInstall(['debug'], {
save: true
});
if (this.props.client) {
const pkgFile = this.destinationPath('package.json');
const pkg = this.fs.readJSON(pkgFile);

this.npmInstall([
'semistandard',
'mocha',
'istanbul@1.1.0-alpha.1',
'chai@^3.5.0'
], {
this.fs.writeJSON(pkgFile, pkgForClient(pkg));
this.fs.copy(this.templatePath('client/_babelrc'), this.destinationPath('.babelrc'));
}

this.npmInstall(devDependencies, {
saveDev: true
});
}
Expand Down
2 changes: 2 additions & 0 deletions packages/generator-feathers-plugin/app/templates/__gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ node_modules

# Users Environment Variables
.lock-wscript

dist/
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [ ["es2015", { "loose": true }] ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const camelCase = require('lodash/camelCase');

module.exports = function(pkg) {
const { scripts, name } = pkg;

Object.assign(scripts, {
clean: 'shx rm -rf dist/ && shx mkdir -p dist',
prepublish: 'npm run browserify',
'browserify:dist': `browserify lib/index.js -t babelify --standalone ${camelCase(name)} --outfile dist/${name}.js`,
'browserify:min': `browserify lib/index.js -t babelify --standalone ${camelCase(name)} | uglifyjs > dist/${name}.min.js`,
browserify: 'npm run clean && npm run browserify:dist && npm run browserify:min',
'add-dist': 'npm run browserify && git add dist/ --force && git commit -am "Updating dist"',
'release:pre': 'npm run add-dist && npm version prerelease && npm publish --tag pre',
'release:patch': 'npm run add-dist && npm version patch && npm publish',
'release:minor': 'npm run add-dist && npm version minor && npm publish',
'release:major': 'npm run add-dist && npm version major && npm publish',
test: 'npm run browserify && npm run lint && npm run coverage'
});

return pkg;
};
4 changes: 0 additions & 4 deletions packages/generator-feathers-plugin/app/templates/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// import errors from 'feathers-errors';
const debug = require('debug')('<%= name %>');

module.exports = function init () {
debug('Initializing <%= name %> plugin');
return '<%= name %>';
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
},
"scripts": {
"publish": "git push origin --tags && npm run changelog && git push origin",
"release:pre": "npm version prerelease && npm publish --tag pre",
"release:patch": "npm version patch && npm publish",
"release:minor": "npm version minor && npm publish",
"release:major": "npm version major && npm publish",
"changelog": "github_changelog_generator && git add CHANGELOG.md && git commit -am \"Updating changelog\"",
"lint": "semistandard src/**/*.js test/**/*.js --fix",
"lint": "semistandard lib/**/*.js test/**/*.js --fix",
"mocha": "mocha --opts mocha.opts",
"coverage": "istanbul cover node_modules/mocha/bin/_mocha -- --opts mocha.opts",
"test": "npm run lint && npm run coverage"
Expand Down
8 changes: 4 additions & 4 deletions packages/generator-feathers-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
"email": "hello@feathersjs.com",
"url": "https://feathersjs.com"
},
"engines": {
"node": ">= 6.0.0"
},
"contributors": [],
"main": "app/index.js",
"repository": {
"type": "git",
"url": "git://github.com/feathersjs/generator-feathers-plugin.git"
},
"scripts": {
"lint": "semistandard --fix",
"lint": "semistandard --fix app/index.js test/**/*.js",
"test": "npm run lint && mocha test/ --timeout 180000",
"publish": "git push origin && git push origin --tags",
"changelog": "github_changelog_generator && git add CHANGELOG.md && git commit -am \"Updating changelog\"",
Expand All @@ -44,8 +47,5 @@
"semistandard": "^11.0.0",
"yeoman-test": "^1.4.0"
},
"engines": {
"node": ">= 6.0.0"
},
"license": "MIT"
}
3 changes: 2 additions & 1 deletion packages/generator-feathers-plugin/test/test-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ describe('feathers-plugin generator', () => {
.withPrompts({
name: 'feathers-tmp',
repository: 'feathersjs/feathers-tmp',
description: 'Plugin description here'
description: 'Plugin description here',
client: true
})
.on('end', function () {
assert.ok(fs.existsSync(path.join(tmpDir, '.npmignore')));
Expand Down

0 comments on commit d61b876

Please sign in to comment.