Skip to content

Commit

Permalink
Update publishing script to bundle all modules
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerun committed Jan 25, 2016
1 parent ad27112 commit bbaaee6
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 86 deletions.
156 changes: 76 additions & 80 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
'use strict';

var tmp = require('tmp');
var childProcess = require('child_process');
var arraydiff = require('arr-diff');
var fs = require('fs');
var wrench = require('wrench');
var inquirer = require('inquirer');
var path = require('path');

module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
Expand Down Expand Up @@ -82,7 +85,7 @@ module.exports = function (grunt) {
grunt.registerTask('travis', ['jshint', 'exec:assets', 'exec:cover', 'exec:coveralls']);
grunt.registerTask('default', 'test');

grunt.task.registerTask('prepublish', 'Prepublish checks', function () {
grunt.task.registerTask('publish', 'Perform final checks and publish Bower', function () {
var npmVersion = JSON.parse(childProcess.execSync('npm version --json').toString()).npm.split('.');
var npmMajor = parseInt(npmVersion[0], 10);
var npmMinor = parseInt(npmVersion[1], 10);
Expand All @@ -94,22 +97,6 @@ module.exports = function (grunt) {
process.exit(1);
}

var bundledDependencies = require('./package').bundledDependencies;
var dependencies = Object.keys(require('./package').dependencies);
var missing = arraydiff(dependencies, bundledDependencies);

if (missing.length > 0) {
grunt.log.writeln('You need to add all bower\'s dependencies to bundledDependencies in package.json');
grunt.log.writeln('It is to freeze all dependencies so bower does not randomly break');
grunt.log.writeln('Following dependencies need to be added to bundledDependencies:');

for(var i = 0; i < missing.length; i++) {
grunt.log.writeln(' "' + missing[i] + '",\n');
}

process.exit(1);
}

var version = require('./package').version;
var changelog = fs.readFileSync('./CHANGELOG.md');

Expand Down Expand Up @@ -137,6 +124,66 @@ module.exports = function (grunt) {
grunt.log.writeln('Running test suite...');
childProcess.execSync('grunt test', { stdio: [0, 1, 2] });

var dir = tmp.dirSync().name;
var pkgDir = path.resolve(dir, 'lib');

wrench.copyDirSyncRecursive(__dirname, pkgDir, {
forceDelete: true,
include: function (path) {
return !path.match(/node_modules|\.git|test/);
}
});

grunt.log.writeln('Installing dependencies');
childProcess.execSync('npm install --production --silent', { cwd: pkgDir, stdio: [0, 1, 2] });

fs.createReadStream(
path.resolve(__dirname, 'README.md')
).pipe(
fs.createWriteStream(path.resolve(dir, 'README.md'))
);

var json = require('./package');
json.bin = 'lib/' + json.bin;
json.main = 'lib/' + json.main;
delete json.dependencies;
delete json.devDependencies;
delete json.scripts;
delete json.files;

fs.writeFileSync(path.resolve(dir, 'package.json'), JSON.stringify(json, null, ' '));

// So node_modules are not ignored
fs.unlinkSync(path.resolve(pkgDir, 'package.json'));

childProcess.execSync('npm install --production --silent', { cwd: pkgDir, stdio: [0, 1, 2] });

grunt.log.writeln('Testing bower on sample project...');

childProcess.execSync(
'cd test/sample && rm -rf bower_components && ' + pkgDir + '/bin/bower install --force', { stdio: [0, 1, 2] }
);

var expectedPackages = (
'SHA-1 ace-builds almond angular angular-animate angular-bootstrap angular-charts angular-contenteditable ' +
'angular-deckgrid angular-fullscreen angular-gravatar angular-hotkeys angular-local-storage angular-marked ' +
'angular-moment angular-sanitize angular-touch angular-ui-router angular-ui-sortable ' +
'angulartics asEvented bootstrap coffee-script d3 es6-shim font-awesome howler jquery ' +
'jquery-ui jquery-waypoints js-beautify lodash lz-string marked moment ng-file-upload peerjs ' +
'requirejs restangular slimScroll slimScrollHorizontal venturocket-angular-slider'
).split(' ');

var installedPackages = fs.readdirSync('./test/sample/bower_components');

var installedDiff = arraydiff(expectedPackages, installedPackages);

if (installedDiff.length > 0) {
grunt.log.writeln('ERROR. Some packages were not installed by bower: ');
grunt.log.writeln(installedDiff.join(', '));

process.exit(1);
}

var questions = [
{
type: 'confirm',
Expand All @@ -155,82 +202,31 @@ module.exports = function (grunt) {
name: 'tests',
message: 'Are you sure all tests are passing on Travis and Appveyor?',
default: false
},
{
type: 'confirm',
name: 'publish',
message: 'Are you SURE you want to publish ' + require('./package').name + '@' + require('./package').version + '?',
default: false
}
];

var done = this.async();

inquirer.prompt(questions, function (answers) {
if (!answers.review || !answers.changelog || !answers.tests) {
if (!answers.review || !answers.changelog || !answers.tests || !answers.publish) {
grunt.log.writeln('Please publish bower after you fix this issue');

process.exit(1);
}

try {
grunt.log.writeln('Reinstalling dependencies in production mode...');

childProcess.execSync('rm -rf node_modules && npm install --production', { stdio: [0, 1, 2] });

grunt.log.writeln('Testing bower on sample project...');

childProcess.execSync(
'cd test/sample && rm -rf bower_components && ../../bin/bower install --force', { stdio: [0, 1, 2] }
);

var expectedPackages = (
'SHA-1 ace-builds almond angular angular-animate angular-bootstrap angular-charts angular-contenteditable ' +
'angular-deckgrid angular-fullscreen angular-gravatar angular-hotkeys angular-local-storage angular-marked ' +
'angular-moment angular-sanitize angular-touch angular-ui-router angular-ui-sortable ' +
'angulartics asEvented bootstrap coffee-script d3 es6-shim font-awesome howler jquery ' +
'jquery-ui jquery-waypoints js-beautify lodash lz-string marked moment ng-file-upload peerjs ' +
'requirejs restangular slimScroll slimScrollHorizontal venturocket-angular-slider'
).split(' ');

var installedPackages = fs.readdirSync('./test/sample/bower_components');

var installedDiff = arraydiff(expectedPackages, installedPackages);

if (installedDiff.length > 0) {
grunt.log.writeln('ERROR. Some packages were not installed by bower: ');
grunt.log.writeln(installedDiff.join(', '));

process.exit(1);
}
} catch (e) {
grunt.log.writeln('There was an error. Reverting development dependencies...');

childProcess.execSync('npm install', { stdio: [0, 1, 2] });

process.exit(1);
}

grunt.log.writeln('Everything seems OK! You are likely good to publish bower.');

var questions = [
{
type: 'confirm',
name: 'publish',
message: 'Are you SURE you want to publish bower@' + require('./package').version + '?',
default: false
}
];

inquirer.prompt(questions, function (answers) {
if (!answers.publish) {
grunt.log.writeln('Bower publishing cancelled..');

childProcess.execSync('npm install', { stdio: [0, 1, 2] });

process.exit(1);
}
grunt.log.writeln('\nPlease remember to tag this relese, and add a release on Github!');
grunt.log.writeln('\nAlso, please remember to test published Bower one more time!');
grunt.log.writeln('\nPublishing Bower...');

grunt.log.writeln('\nPlease remember to tag this relese, and add a release on Github!');
grunt.log.writeln('\nAlso, please remember to test published Bower one more time!');
grunt.log.writeln('\nPublishing Bower...');
childProcess.execSync('npm publish', { cwd: dir, stdio: [0, 1, 2] });

done();
});
done();
});
});
};
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"chai": "^1.10.0",
"coveralls": "^2.11.2",
"expect.js": "^0.3.1",
"fs-extra": "^0.26.4",
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-contrib-jshint": "^0.10.0",
Expand All @@ -84,12 +83,13 @@
"nock": "^3.1.0",
"node-uuid": "^1.4.2",
"proxyquire": "^1.3.0",
"spawn-sync": "1.0.13"
"spawn-sync": "1.0.13",
"wrench": "^1.5.8"
},
"scripts": {
"test": "grunt test",
"ci": "grunt travis",
"coveralls": "coveralls",
"prepublish": "in-publish && grunt prepublish || not-in-publish"
"prepublish": "in-publish && echo 'You need to use \"grunt publush\" to publish bower' && false || not-in-publish"
}
}
2 changes: 2 additions & 0 deletions test/commands/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ describe('bower update', function () {
});

it('does not install ignored dependencies when updating a package', function () {
this.timeout(15000);

var package3 = new helpers.TempDir({
'bower.json': {
name: 'package3'
Expand Down
6 changes: 3 additions & 3 deletions test/core/resolvers/gitResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ describe('GitResolver', function () {
expect(process.env).to.not.have.property('GIT_SSL_NO_VERIFY');

resolver = new GitResolver(decEndpoint, defaultConfig(), logger);
expect(process.env).to.have.property('GIT_SSL_NO_VERIFY','false');
expect(process.env).to.have.property('GIT_SSL_NO_VERIFY', 'false');
delete process.env.GIT_SSL_NO_VERIFY;

resolver = new GitResolver(decEndpoint, defaultConfig({strictSsl: false}), logger);
expect(process.env).to.have.property('GIT_SSL_NO_VERIFY','true');
expect(process.env).to.have.property('GIT_SSL_NO_VERIFY', 'true');
delete process.env.GIT_SSL_NO_VERIFY;

resolver = new GitResolver(decEndpoint, defaultConfig({strictSsl: true}), logger);
expect(process.env).to.have.property('GIT_SSL_NO_VERIFY','false');
expect(process.env).to.have.property('GIT_SSL_NO_VERIFY', 'false');
delete process.env.GIT_SSL_NO_VERIFY;
});
});
Expand Down

3 comments on commit bbaaee6

@vijayk
Copy link

@vijayk vijayk commented on bbaaee6 Jan 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm install bower

Install latest version of bower: 1.7.5 but looks like the directory structure is having some issue. Bower installation directory structure:

drwxr-xr-x 6 jenkins users 4096 Jan 27 06:01 lib
-rw-r--r-- 1 jenkins users 5857 Jan 27 06:01 package.json
-rw-r--r-- 1 jenkins users 5125 Jan 26 21:39 README.md

Wherein 1.7.2 install directory structure was:

drwxr-xr-x 2 jenkins users 4096 Dec 31 02:06 bin
drwxr-xr-x 6 jenkins users 4096 Jan 27 06:10 lib
drwxr-xr-x 50 jenkins users 4096 Jan 27 06:11 node_modules
-rw-r--r-- 1 jenkins users 8625 Jan 27 06:11 package.json
-rw-r--r-- 1 jenkins users 5121 Dec 31 02:01 README.md
drwxr-xr-x 5 jenkins users 4096 Jan 27 06:10 templates

In case of 1.7.5, i see ALL moved inside a top level "lib" directory.

Is this an intentional change ?

@benmann
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vijayk yes, see #2157
does it cause you problems?

@vijayk
Copy link

@vijayk vijayk commented on bbaaee6 Jan 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted my comment to #2157

Please sign in to comment.