From 389d4879da4aa620ee95d789b19ff9be44eb730a Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Wed, 12 Feb 2014 22:47:42 +0000 Subject: chore(doc-gen): new docs chore(doc-gen): implement dgeni --- lib/grunt/plugins.js | 19 ++-------- lib/grunt/utils.js | 103 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 99 insertions(+), 23 deletions(-) (limited to 'lib') diff --git a/lib/grunt/plugins.js b/lib/grunt/plugins.js index 59fee2e4..56836aae 100644 --- a/lib/grunt/plugins.js +++ b/lib/grunt/plugins.js @@ -1,6 +1,6 @@ var bower = require('bower'); var util = require('./utils.js'); -var spawn = require('child_process').spawn; +var shelljs = require('shelljs'); module.exports = function(grunt) { @@ -34,21 +34,8 @@ module.exports = function(grunt) { }); - grunt.registerMultiTask('docs', 'create angular docs', function(){ - var done = this.async(); - var files = this.data; - var docs = spawn('node', ['docs/src/gen-docs.js']); - docs.stdout.pipe(process.stdout); - docs.stderr.pipe(process.stderr); - docs.on('exit', function(code){ - if(code !== 0) grunt.fail.warn('Error creating docs'); - grunt.file.expand(files).forEach(function(file){ - var content = util.process(grunt.file.read(file), grunt.config('NG_VERSION'), false); - grunt.file.write(file, content); - }); - grunt.log.ok('docs created'); - done(); - }); + grunt.registerTask('docs', 'create angular docs', function(){ + shelljs.exec('node_modules/gulp/bin/gulp.js --gulpfile docs/gulpfile.js'); }); diff --git a/lib/grunt/utils.js b/lib/grunt/utils.js index a3a7e7b2..1c356c18 100644 --- a/lib/grunt/utils.js +++ b/lib/grunt/utils.js @@ -1,9 +1,11 @@ var fs = require('fs'); +var path = require('path'); var shell = require('shelljs'); var grunt = require('grunt'); var spawn = require('child_process').spawn; var semver = require('semver'); -var version; +var _ = require('lodash'); +var version, pkg; var CSP_CSS_HEADER = '/* Include this file in your html if you are using the CSP mode. */\n\n'; var PORT_MIN = 8000; @@ -21,6 +23,23 @@ var getRandomPorts = function() { ]; }; +var getPackage = function() { + if ( !pkg ) { + + // Search up the folder hierarchy for the first package.json + var packageFolder = path.resolve('.'); + while ( !fs.existsSync(path.join(packageFolder, 'package.json')) ) { + var parent = path.dirname(packageFolder); + if ( parent === packageFolder) { break; } + packageFolder = parent; + } + pkg = JSON.parse(fs.readFileSync(path.join(packageFolder,'package.json'), 'UTF-8')); + + } + + return pkg; +}; + module.exports = { @@ -31,9 +50,20 @@ module.exports = { }, + getGitRepoInfo: function() { + var GITURL_REGEX = /^https:\/\/github.com\/([^\/]+)\/(.+).git$/; + var match = GITURL_REGEX.exec(getPackage().repository.url); + var git = { + owner: match[1], + repo: match[2] + }; + return git; + }, + + getVersion: function(){ if (version) return version; - var package = JSON.parse(fs.readFileSync('package.json', 'UTF-8')); + try { var gitTag = getTagOfCurrentCommit(); @@ -46,7 +76,7 @@ module.exports = { // snapshot release semVerVersion = getSnapshotVersion(); fullVersion = semVerVersion + '-' + getSnapshotSuffix(); - codeName = 'snapshot' + codeName = 'snapshot'; } var versionParts = semVerVersion.match(/(\d+)\.(\d+)\.(\d+)/); @@ -57,9 +87,12 @@ module.exports = { minor: versionParts[2], dot: versionParts[3], codename: codeName, - cdn: package.cdnVersion + cdn: getPackage().cdnVersion }; + // Stable versions have an even minor version + version.isStable = version.minor%2 === 0; + return version; } catch (e) { @@ -69,7 +102,7 @@ module.exports = { function getTagOfCurrentCommit() { var gitTagResult = shell.exec('git describe --exact-match', {silent:true}); var gitTagOutput = gitTagResult.output.trim(); - var branchVersionPattern = new RegExp(package.branchVersion.replace('.', '\\.').replace('*', '\\d+')); + var branchVersionPattern = new RegExp(getPackage().branchVersion.replace('.', '\\.').replace('*', '\\d+')); if (gitTagResult.code === 0 && gitTagOutput.match(branchVersionPattern)) { return gitTagOutput; } else { @@ -88,7 +121,7 @@ module.exports = { } function getSnapshotVersion() { - var oldTags = shell.exec('git tag -l v'+package.branchVersion, {silent:true}).output.trim().split('\n'); + var oldTags = shell.exec('git tag -l v'+getPackage().branchVersion, {silent:true}).output.trim().split('\n'); // ignore non semver versions. oldTags = oldTags.filter(function(version) { return version && semver.valid(version); @@ -102,7 +135,7 @@ module.exports = { semVerVersion = semver.inc(semVerVersion, 'patch'); } } else { - semVerVersion = semver.valid(package.branchVersion.replace(/\*/g, '0')); + semVerVersion = semver.valid(getPackage().branchVersion.replace(/\*/g, '0')); } return semVerVersion; } @@ -114,6 +147,62 @@ module.exports = { } }, + getPreviousVersions: function() { + var VERSION_REGEX = /([1-9]\d*)\.(\d+)\.(\d+)(?:-?rc\.?(\d+)|-(snapshot))?/; + + // Pad out a number with zeros at the front to make it `digits` characters long + function pad(num, digits) { + var zeros = Array(digits+1).join('0'); + return (zeros+num).slice(-digits); + } + + function padVersion(version) { + // We pad out the version numbers with 0s so they sort nicely + // - Non-Release Candidates get 9999 for their release candidate section to make them appear earlier + // - Snapshots get 9 added to the front to move them to the top of the list + var maxLength = 4; + var padded = (version.snapshot ? '9' : '0') + pad(version.major, maxLength) + + pad(version.minor, maxLength) + pad(version.dot, maxLength) + + pad(version.rc || 9999, maxLength); + return padded; + } + + function getVersionFromTag(tag) { + var match = VERSION_REGEX.exec(tag); + if ( match ) { + var version = { + tag: tag, + major: match[1], minor: match[2], dot: match[3], rc: match[4], + snapshot: !!match[5] && getSnapshotSuffix() + }; + + if(version.snapshot) { + version.full = version.major + '.' + version.minor + '.x (edge)'; + } else { + version.full = version.major + '.' + version.minor + '.' + version.dot + + (version.rc ? '-rc.' + version.rc : ''); + } + + // Stable versions have an even minor version and are not a release candidate + version.isStable = !(version.minor%2 || version.rc); + + // Versions before 1.0.2 had a different docs folder name + version.docsUrl = 'http://code.angularjs.org/' + version.full + '/docs'; + if ( version.major < 1 || (version.major === 1 && version.minor === 0 && version.dot < 2 ) ) { + version.docsUrl += '-' + version.full; + } + + return version; + } + } + + var tags = shell.exec('git tag', {silent: true}).output.split(/\s*\n\s*/); + return _(tags) + .map(getVersionFromTag) + .filter() // getVersion can map to undefined - this clears those out + .sortBy(padVersion) + .value(); + }, startKarma: function(config, singleRun, done){ var browsers = grunt.option('browsers'); -- cgit v1.2.3