forked from react-bootstrap/react-router-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbower-prepare.js
70 lines (56 loc) · 2.05 KB
/
bower-prepare.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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();