|
| 1 | +/* globals cat, config, cp, mkdir, rm, test */ |
| 2 | +/* eslint curly: 0 */ |
| 3 | +import 'colors'; |
| 4 | +import 'shelljs/global'; |
| 5 | +import path from 'path'; |
| 6 | +import _ from 'lodash'; |
| 7 | +import yargs from 'yargs'; |
| 8 | + |
| 9 | +// do not die on errors |
| 10 | +config.fatal = false; |
| 11 | + |
| 12 | +//------------------------------------------------------------------------------ |
| 13 | +// constants |
| 14 | +const repoRoot = path.resolve(__dirname, '../'); |
| 15 | +const libFolder = path.join(repoRoot, 'lib'); |
| 16 | +const bowerRoot = path.join(repoRoot, 'amd'); |
| 17 | +const bowerTemplate = path.join(repoRoot, 'bower.template.json'); |
| 18 | +const license = path.join(repoRoot, 'LICENSE'); |
| 19 | + |
| 20 | + |
| 21 | +//------------------------------------------------------------------------------ |
| 22 | +// command line options |
| 23 | +const argv = yargs |
| 24 | + .usage('Usage: $0 [--verbose]') |
| 25 | + .example('$0', 'Prepare bower package for releasing') |
| 26 | + .option('verbose', { |
| 27 | + demand: false, |
| 28 | + default: false, |
| 29 | + describe: 'Increased debug output' |
| 30 | + }) |
| 31 | + .argv; |
| 32 | + |
| 33 | +if (argv.dryRun) console.log('DRY RUN'.magenta); |
| 34 | + |
| 35 | +config.silent = !argv.verbose; |
| 36 | + |
| 37 | + |
| 38 | +//------------------------------------------------------------------------------ |
| 39 | +// functions |
| 40 | +function bower() { |
| 41 | + console.log('Creating: '.cyan + 'bower package'.green); |
| 42 | + |
| 43 | + rm('-rf', bowerRoot); |
| 44 | + mkdir('-p', bowerRoot); |
| 45 | + |
| 46 | + // generate bower.json from template |
| 47 | + const pkg = JSON.parse(cat(path.join(repoRoot, 'package.json'))); |
| 48 | + const template = _.template(cat(bowerTemplate)); |
| 49 | + const bowerConfigObject = template({ pkg }); |
| 50 | + const json = JSON.stringify(JSON.parse(bowerConfigObject), null, 2); // proper formatting hack |
| 51 | + json.to(path.join(bowerRoot, 'bower.json')); |
| 52 | + |
| 53 | + // copy readme and license |
| 54 | + const readmeBower = path.join(repoRoot, 'README.bower.md'); |
| 55 | + const readme = path.join(repoRoot, 'README.md'); |
| 56 | + if (test('-e', readmeBower)) { |
| 57 | + cp(readmeBower, path.join(bowerRoot, 'README.md')); |
| 58 | + } else { |
| 59 | + cp(readme, bowerRoot); |
| 60 | + } |
| 61 | + if (test('-e', license)) cp(license, bowerRoot); |
| 62 | + |
| 63 | + // copy distr files |
| 64 | + cp('-r', libFolder, bowerRoot); |
| 65 | + |
| 66 | + console.log('Created: '.cyan + 'bower package'.green); |
| 67 | +} |
| 68 | + |
| 69 | +//------------------------------------------------------------------------------ |
| 70 | +bower(); |
0 commit comments