Permalink
Please sign in to comment.
Showing
with
76 additions
and 1 deletion.
- +6 −1 package.json
- +70 −0 scripts/bower-prepare.js
7
package.json
70
scripts/bower-prepare.js
| @@ -0,0 +1,70 @@ | ||
| +/* globals cat, config, cp, mkdir, rm, test */ | ||
| +/* eslint curly: 0 */ | ||
| +import 'colors'; | ||
| +import 'shelljs/global'; | ||
| +import path from 'path'; | ||
| +import _ from 'lodash'; | ||
| +import yargs from 'yargs'; | ||
| + | ||
| +// do not die on errors | ||
| +config.fatal = false; | ||
| + | ||
| +//------------------------------------------------------------------------------ | ||
| +// constants | ||
| +const repoRoot = path.resolve(__dirname, '../'); | ||
| +const libFolder = path.join(repoRoot, 'lib'); | ||
| +const bowerRoot = path.join(repoRoot, 'amd'); | ||
| +const bowerTemplate = path.join(repoRoot, 'bower.template.json'); | ||
| +const license = path.join(repoRoot, 'LICENSE'); | ||
| + | ||
| + | ||
| +//------------------------------------------------------------------------------ | ||
| +// command line options | ||
| +const argv = yargs | ||
| + .usage('Usage: $0 [--verbose]') | ||
| + .example('$0', 'Prepare bower package for releasing') | ||
| + .option('verbose', { | ||
| + demand: false, | ||
| + default: false, | ||
| + describe: 'Increased debug output' | ||
| + }) | ||
| + .argv; | ||
| + | ||
| +if (argv.dryRun) console.log('DRY RUN'.magenta); | ||
| + | ||
| +config.silent = !argv.verbose; | ||
| + | ||
| + | ||
| +//------------------------------------------------------------------------------ | ||
| +// functions | ||
| +function bower() { | ||
| + console.log('Creating: '.cyan + 'bower package'.green); | ||
| + | ||
| + rm('-rf', bowerRoot); | ||
| + mkdir('-p', bowerRoot); | ||
| + | ||
| + // generate bower.json from template | ||
| + const pkg = JSON.parse(cat(path.join(repoRoot, 'package.json'))); | ||
| + const template = _.template(cat(bowerTemplate)); | ||
| + const bowerConfigObject = template({ pkg }); | ||
| + const json = JSON.stringify(JSON.parse(bowerConfigObject), null, 2); // proper formatting hack | ||
| + json.to(path.join(bowerRoot, 'bower.json')); | ||
| + | ||
| + // copy readme and license | ||
| + const readmeBower = path.join(repoRoot, 'README.bower.md'); | ||
| + const readme = path.join(repoRoot, 'README.md'); | ||
| + if (test('-e', readmeBower)) { | ||
| + cp(readmeBower, path.join(bowerRoot, 'README.md')); | ||
| + } else { | ||
| + cp(readme, bowerRoot); | ||
| + } | ||
| + if (test('-e', license)) cp(license, bowerRoot); | ||
| + | ||
| + // copy distr files | ||
| + cp('-r', libFolder, bowerRoot); | ||
| + | ||
| + console.log('Created: '.cyan + 'bower package'.green); | ||
| +} | ||
| + | ||
| +//------------------------------------------------------------------------------ | ||
| +bower(); |
0 comments on commit
f80082b