Skip to content

Commit

Permalink
[fixed] bower building and publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKVal committed Oct 9, 2015
1 parent c182385 commit f80082b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"main": "./lib/index.js",
"scripts": {
"prepublish": "npm run build",
"build": "babel src --out-dir=lib && webpack && webpack -p",
"build": "babel src --out-dir=lib && webpack && webpack -p && npm run bower-prepare",
"test": "npm run lint && karma start --single-run",
"tdd": "karma start",
"visual-test": "open http://localhost:8080/ && webpack-dev-server --config webpack.visual.config.babel.js",
"lint": "eslint *.babel.js src tests",
"bower-prepare": "babel-node scripts/bower-prepare.js",
"release": "release"
},
"repository": {
Expand Down Expand Up @@ -40,6 +41,7 @@
"babel-eslint": "^4.1.3",
"babel-loader": "^5.3.2",
"bootstrap": "^3.3.5",
"colors": "^1.1.2",
"css-loader": "^0.19.0",
"es5-shim": "^4.1.14",
"eslint": "1.6.x",
Expand All @@ -60,6 +62,7 @@
"karma-webpack": "^1.7.0",
"less": "^2.5.3",
"less-loader": "^2.2.1",
"lodash": "^3.10.1",
"mocha": "^2.3.3",
"mt-changelog": "^0.6.2",
"node-libs-browser": "^0.5.3",
Expand All @@ -69,6 +72,8 @@
"react-dom": "^0.14.0",
"react-router": "^1.0.0-rc3",
"release-script": "^0.5.3",
"rimraf": "^2.4.3",
"shelljs": "^0.5.3",
"style-loader": "^0.12.4",
"url-loader": "^0.5.6",
"webpack": "^1.12.2",
Expand Down
70 changes: 70 additions & 0 deletions scripts/bower-prepare.js
Original file line number Diff line number Diff line change
@@ -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

Please sign in to comment.