Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-14249] Publishing scripts #226

Merged
merged 4 commits into from
Jun 17, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
/node_modules
._*
.DS_Store
tests/test-262
/tests/test-262
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/docs
/tests
/test_projects
/tools
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"dependencies": {
"uglify-js": "2.x.x",
"wrench": "1.x.x",
"nomnom": "1.x.x",
"winston": "0.6.x",
"async": "0.1.x",
"xml2js": "0.2.x",
Expand All @@ -25,6 +24,9 @@
"source-map": "0.1.x",
"node-appc": "git://github.com/appcelerator/node-appc.git#3_1_X"
},
"devDependencies": {
"commander": "1.2.x"
},
"engine": {
"node": ">=0.8"
}
Expand Down
File renamed without changes.
208 changes: 208 additions & 0 deletions tools/dev-publish
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
#!/usr/bin/env node

var fs = require('fs'),
spawn = require('child_process').spawn,
path = require('path'),

program = require('commander'),
async = require('async'),

pkgPath = path.join(__dirname, '..', 'package.json'),
pkg = JSON.parse(fs.readFileSync(pkgPath)),

APPCELERATOR_REMOTE_NAME = 'appcelerator',

startTime = Date.now();

// Validate the arguments
program.version('0.0.1')
.option('-p, --package-version [value]', 'the version to publish')
.option('-n, --node-appc-version [value]', 'the node-appc version to publish against')
.option('--non-interactive', 'disables prompting for values')
.option('-s, --silent', 'does not print anything to the console and disables prompting')
.parse(process.argv);

// Validate a version string
function validateVersion(version, type, callback) {
if (!/^\d+\.\d+\.\d+-(?:alpha|beta|cr)\d*$/.test(version)) {
if (!program.silent) {
console.error('\n error: "' + version + '" is not a valid development ' + type + ' version number\n');
}
process.exit(1);
}
callback(undefined, version);
}

// Process the version string, prompting for it if necessary
function processVersion(version, type, callback) {
if (version) {
validateVersion(version, type, callback);
} else if (!program.nonInteractive) {
program.prompt(type + ' version: ', function(promptedVersion){
validateVersion(promptedVersion, type, callback);
});
} else {
if (!program.silent) {
console.error('\n error: ' + type + ' version must be supplied\n');
}
process.exit(1);
}
}

// Determine the package version and, if appropriate, the node-appc version
async.series({
packageVersion: function (next) {
processVersion(program.packageVersion, 'package', next);
},
nodeAppcVersion: function (next) {
if (pkg.dependencies && pkg.dependencies['node-appc']) {
processVersion(program.nodeAppcVersion, 'node-appc', next);
} else {
next();
}
}
}, function (err, results) {
if (!program.silent && !program.nonInteractive) {
program.confirm('\nPublish version ' + results.packageVersion + ' of ' + pkg.name +
(results.nodeAppcVersion ? ' against node-appc version ' + results.nodeAppcVersion : '') +
' [y/n]? ', function(ok){
if (ok) {
publish(results.packageVersion, results.nodeAppcVersion);
} else {
console.log('');
process.exit(1);
}
});
} else {
publish(results.packageVersion, results.nodeAppcVersion);
}
});

// Publish the package
function publish(packageVersion, nodeAppcVersion) {

var newPkg = JSON.parse(fs.readFileSync(pkgPath)),
STATE_NONE = 0,
STATE_PACKAGE_UPDATED = 1,
STATE_REPO_TAGGED = 2,
STATE_REPO_PUSHED = 3,
STATE_NPM_PUBLISHED = 4,
STATE_NPM_VERIFIED = 5,
state = STATE_NONE,
step = 1,
tasks;

function getStep() {
return '(' + (step++) + '/' + tasks.length + ')';
}

// Create the tasks
tasks = [

// Update the package.json with the new version number and, if applicable, the new node-appc version
function (next) {
console.log('\n* Updating package.json ' + getStep());
newPkg.version = packageVersion;
if (nodeAppcVersion) {
newPkg.dependencies['node-appc'] = nodeAppcVersion;
}
fs.writeFileSync(pkgPath, JSON.stringify(newPkg, false, '\t'));
state = STATE_PACKAGE_UPDATED;
next();
},

// Tag the release in git with an annotated tag
function (next) {
console.log('\n* Tagging release in git ' + getStep());
spawn('git', ['tag', '-a', packageVersion, '-m', 'Tagged the ' + packageVersion + ' release'], {
stdio: 'inherit'
}).on('exit', function (code) {
if (code) {
next(code);
} else {
state = STATE_REPO_TAGGED;
next();
}
});
},

// Push the tag to github
function (next) {
console.log('\n* Pushing tag to GitHub ' + getStep());
spawn('git', ['push', APPCELERATOR_REMOTE_NAME, packageVersion], {
stdio: 'inherit'
}).on('exit', function (code) {
if (code) {
next(code);
} else {
state = STATE_REPO_PUSHED;
next();
}
});
},

// Publish the npm package
function (next) {
console.log('\n* Publishing to NPM ' + getStep());
spawn('npm', ['publish', '--tag', packageVersion], {
stdio: 'inherit',
cwd: path.join(__dirname, '..')
}).on('exit', function (code) {
if (code) {
next(code);
} else {
state = STATE_NPM_PUBLISHED;
next();
}
});
},

// Verify that the package was published correctly
function (next) {
console.log('\n* Verifying published package ' + getStep());
var info = spawn('npm', ['info', pkg.name, '--json']),
stderrData = '',
stdoutData = '';
info.stdout.on('data', function (data) {
stdoutData += data.toString();
});
info.stderr.on('data', function (data) {
stderrData += data.toString();
});
info.on('exit', function (code) {
if (code) {
console.warn('\n warning: could not verify that the package was published properly.\n' +
' You should verify manually by calling "npm info ' + pkg.name + '".\n');
next();
} else {
var infoResult = JSON.parse(stdoutData);
if (infoResult['dist-tags'].latest === packageVersion) {
console.error('\n error: The latest version in NPM is pointing to the just published version. YOUR PACKAGE IS LIVE BUT SHOULD NOT BE!');
next(1);
} else if (infoResult['dist-tags'][packageVersion] !== packageVersion) {
console.error('\n error: Something has gone wrong, the published version isn\'t showing up in NPM\n');
next(1);
} else {
next();
}
}
});
state = STATE_NPM_VERIFIED;
}
];
async.series(tasks, function (err) {

// Cleanup after publishing
console.log('\n* Cleaning up');
if (state >= STATE_PACKAGE_UPDATED) {
fs.writeFileSync(pkgPath, JSON.stringify(pkg, false, '\t'));
}

// Time to exit
if (err) {
console.error('\n' + pkg.name + ' WAS NOT properly published!');
}
console.log('\nProcessing completed in ' + ((Date.now() - startTime) / 1000).toFixed(1) + ' seconds\n');
process.exit(err ? 1 : 0);
});
}
File renamed without changes.
File renamed without changes.
143 changes: 143 additions & 0 deletions tools/release-publish
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#!/usr/bin/env node

var fs = require('fs'),
spawn = require('child_process').spawn,
path = require('path'),

program = require('commander'),
async = require('async'),

pkgPath = path.join(__dirname, '..', 'package.json'),
pkg = JSON.parse(fs.readFileSync(pkgPath)),

nodeAppcVersion = pkg.dependencies && pkg.dependencies['node-appc'],

APPCELERATOR_REMOTE_NAME = 'appcelerator',

startTime = Date.now();

// Validate the arguments
program.version('0.0.1')
.option('--non-interactive', 'disables prompting for values')
.option('-s, --silent', 'does not print anything to the console and disables prompting')
.parse(process.argv);

if (!program.silent && !program.nonInteractive) {
program.confirm('\nPublish version ' + pkg.version + ' of ' + pkg.name +
(nodeAppcVersion ? ' against node-appc version ' + nodeAppcVersion : '') +
' [y/n]? ', function(ok){
if (ok) {
publish();
} else {
console.log('');
process.exit(1);
}
});
} else {
publish();
}

function publish() {

var STATE_NONE = 0,
STATE_REPO_TAGGED = 2,
STATE_REPO_PUSHED = 3,
STATE_NPM_PUBLISHED = 4,
STATE_NPM_VERIFIED = 5,
state = STATE_NONE,
step = 1,
tasks;

function getStep() {
return '(' + (step++) + '/' + tasks.length + ')';
}

// Create the tasks
tasks = [

// Tag the release in git with an annotated tag
function (next) {
console.log('\n* Tagging release in git ' + getStep());
spawn('git', ['tag', '-a', pkg.version, '-m', 'Tagged the ' + pkg.version + ' release'], {
stdio: 'inherit'
}).on('exit', function (code) {
if (code) {
next(code);
} else {
state = STATE_REPO_TAGGED;
next();
}
});
},

// Push the tag to github
function (next) {
console.log('\n* Pushing tag to GitHub ' + getStep());
spawn('git', ['push', APPCELERATOR_REMOTE_NAME, pkg.version], {
stdio: 'inherit'
}).on('exit', function (code) {
if (code) {
next(code);
} else {
state = STATE_REPO_PUSHED;
next();
}
});
},

// Publish the npm package
function (next) {
console.log('\n* Publishing to NPM ' + getStep());
spawn('npm', ['publish'], {
stdio: 'inherit',
cwd: path.join(__dirname, '..')
}).on('exit', function (code) {
if (code) {
next(code);
} else {
state = STATE_NPM_PUBLISHED;
next();
}
});
},

// Verify that the package was published correctly
function (next) {
console.log('\n* Verifying published package ' + getStep());
var info = spawn('npm', ['info', pkg.name, '--json']),
stderrData = '',
stdoutData = '';
info.stdout.on('data', function (data) {
stdoutData += data.toString();
});
info.stderr.on('data', function (data) {
stderrData += data.toString();
});
info.on('exit', function (code) {
if (code) {
console.warn('\n warning: could not verify that the package was published properly.\n' +
' You should verify manually by calling "npm info ' + pkg.name + '".\n');
next();
} else {
var infoResult = JSON.parse(stdoutData);
if (infoResult['dist-tags'].latest !== pkg.version) {
console.error('\n error: Something has gone wrong, the published version isn\'t showing up in NPM as latest\n');
next(1);
} else {
next();
}
}
});
state = STATE_NPM_VERIFIED;
}
];
async.series(tasks, function (err) {

// Time to exit
if (err) {
console.error('\n' + pkg.name + ' WAS NOT properly published!');
}
console.log('\nProcessing completed in ' + ((Date.now() - startTime) / 1000).toFixed(1) + ' seconds\n');
process.exit(err ? 1 : 0);
});
}