Remove IIFE in all scripts
It is not required by node.js, but introduce troubles while generating documents with jsdoc3. Refer to https://github.com/jsdoc3/jsdoc/issues/456 Change-Id: I6664f1be0fc3e86f3a7e3843d557786c37df1c5e
This commit is contained in:
parent
9a7e0c3a6e
commit
5c9e5bbeaf
|
@ -2,3 +2,5 @@ extends: openstack
|
||||||
env:
|
env:
|
||||||
node: true
|
node: true
|
||||||
jasmine: true
|
jasmine: true
|
||||||
|
rules:
|
||||||
|
strict: ["error", "global"]
|
||||||
|
|
|
@ -14,118 +14,116 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var yeoman = require('yeoman-generator');
|
var yeoman = require('yeoman-generator');
|
||||||
var projectBuilder = require('./lib/project_builder');
|
var projectBuilder = require('./lib/project_builder');
|
||||||
var Q = require('q');
|
var Q = require('q');
|
||||||
|
|
||||||
var pkg = require('./lib/component/pkg');
|
var pkg = require('./lib/component/pkg');
|
||||||
var gerrit = require('./lib/component/gerrit');
|
var gerrit = require('./lib/component/gerrit');
|
||||||
var editorconfig = require('./lib/component/editorconfig');
|
var editorconfig = require('./lib/component/editorconfig');
|
||||||
var license = require('./lib/component/license');
|
var license = require('./lib/component/license');
|
||||||
var structure = require('./lib/component/structure');
|
var structure = require('./lib/component/structure');
|
||||||
var eslint = require('./lib/component/eslint');
|
var eslint = require('./lib/component/eslint');
|
||||||
var gitignore = require('./lib/component/gitignore');
|
var gitignore = require('./lib/component/gitignore');
|
||||||
var nsp = require('./lib/component/nsp');
|
var nsp = require('./lib/component/nsp');
|
||||||
|
|
||||||
module.exports = yeoman.Base.extend({
|
module.exports = yeoman.Base.extend({
|
||||||
|
|
||||||
constructor: function () {
|
constructor: function () {
|
||||||
yeoman.Base.apply(this, arguments);
|
yeoman.Base.apply(this, arguments);
|
||||||
|
|
||||||
// Add support for a `--non-interactive` flag
|
// Add support for a `--non-interactive` flag
|
||||||
this.option('non-interactive');
|
this.option('non-interactive');
|
||||||
|
|
||||||
// If non-interactive is set, force-override all files.
|
// If non-interactive is set, force-override all files.
|
||||||
this.conflicter.force = this.options['non-interactive'];
|
this.conflicter.force = this.options['non-interactive'];
|
||||||
},
|
},
|
||||||
|
|
||||||
initializing: function () {
|
initializing: function () {
|
||||||
var done = this.async();
|
var done = this.async();
|
||||||
|
|
||||||
// Initialize components.
|
// Initialize components.
|
||||||
Q(this)
|
Q(this)
|
||||||
.then(pkg.init) // Package.json
|
.then(pkg.init) // Package.json
|
||||||
.then(gerrit.init) // Gerrit
|
.then(gerrit.init) // Gerrit
|
||||||
.then(editorconfig.init) // Editorconfig
|
.then(editorconfig.init) // Editorconfig
|
||||||
.then(license.init) // Licensing
|
.then(license.init) // Licensing
|
||||||
.then(structure.init) // Project Structure
|
.then(structure.init) // Project Structure
|
||||||
.then(eslint.init) // Linting
|
.then(eslint.init) // Linting
|
||||||
.then(gitignore.init) // Gitignore
|
.then(gitignore.init) // Gitignore
|
||||||
.then(nsp.init) // NSP
|
.then(nsp.init) // NSP
|
||||||
.then(function () {
|
.then(function () {
|
||||||
done();
|
done();
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
prompting: function () {
|
|
||||||
var done = this.async();
|
|
||||||
|
|
||||||
// Prompt components.
|
|
||||||
Q(this)
|
|
||||||
.then(pkg.prompt) // Package.json
|
|
||||||
.then(gerrit.prompt) // Gerrit
|
|
||||||
.then(editorconfig.prompt) // Editorconfig
|
|
||||||
.then(license.prompt) // Licensing
|
|
||||||
.then(structure.prompt) // Project Structure
|
|
||||||
.then(eslint.prompt) // Linting
|
|
||||||
.then(gitignore.prompt) // Gitignore
|
|
||||||
.then(nsp.prompt) // NSP
|
|
||||||
.then(function () {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
configuring: function () {
|
|
||||||
var done = this.async();
|
|
||||||
|
|
||||||
// Configure components.
|
|
||||||
Q(this)
|
|
||||||
.then(pkg.configure) // Package.json
|
|
||||||
.then(gerrit.configure) // Gerrit
|
|
||||||
.then(editorconfig.configure) // Editorconfig
|
|
||||||
.then(license.configure) // Licensing
|
|
||||||
.then(structure.configure) // Project Structure
|
|
||||||
.then(eslint.configure) // Linting
|
|
||||||
.then(gitignore.configure) // Gitignore
|
|
||||||
.then(nsp.configure) // NSP
|
|
||||||
.then(function () {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
writing: function () {
|
|
||||||
var self = this;
|
|
||||||
var config = self.config.getAll();
|
|
||||||
var included = projectBuilder.getIncludedFiles();
|
|
||||||
var excluded = projectBuilder.getExcludedFiles();
|
|
||||||
|
|
||||||
// Write out all files included in the project builder.
|
|
||||||
included.forEach(function (fileRef) {
|
|
||||||
if (fileRef.hasOwnProperty('content')) {
|
|
||||||
var content = typeof fileRef.content === 'function'
|
|
||||||
? "" + fileRef.content()
|
|
||||||
: "" + fileRef.content;
|
|
||||||
self.fs.write(fileRef.to, content);
|
|
||||||
} else {
|
|
||||||
self.fs.copyTpl(
|
|
||||||
self.templatePath(fileRef.from),
|
|
||||||
self.destinationPath(fileRef.to),
|
|
||||||
config
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
// Delete all files explicitly excluded in the project builder.
|
prompting: function () {
|
||||||
excluded.forEach(function (path) {
|
var done = this.async();
|
||||||
self.fs.delete(self.destinationPath(path));
|
|
||||||
|
// Prompt components.
|
||||||
|
Q(this)
|
||||||
|
.then(pkg.prompt) // Package.json
|
||||||
|
.then(gerrit.prompt) // Gerrit
|
||||||
|
.then(editorconfig.prompt) // Editorconfig
|
||||||
|
.then(license.prompt) // Licensing
|
||||||
|
.then(structure.prompt) // Project Structure
|
||||||
|
.then(eslint.prompt) // Linting
|
||||||
|
.then(gitignore.prompt) // Gitignore
|
||||||
|
.then(nsp.prompt) // NSP
|
||||||
|
.then(function () {
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
install: function () {
|
configuring: function () {
|
||||||
this.npmInstall();
|
var done = this.async();
|
||||||
}
|
|
||||||
});
|
// Configure components.
|
||||||
})();
|
Q(this)
|
||||||
|
.then(pkg.configure) // Package.json
|
||||||
|
.then(gerrit.configure) // Gerrit
|
||||||
|
.then(editorconfig.configure) // Editorconfig
|
||||||
|
.then(license.configure) // Licensing
|
||||||
|
.then(structure.configure) // Project Structure
|
||||||
|
.then(eslint.configure) // Linting
|
||||||
|
.then(gitignore.configure) // Gitignore
|
||||||
|
.then(nsp.configure) // NSP
|
||||||
|
.then(function () {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
writing: function () {
|
||||||
|
var self = this;
|
||||||
|
var config = self.config.getAll();
|
||||||
|
var included = projectBuilder.getIncludedFiles();
|
||||||
|
var excluded = projectBuilder.getExcludedFiles();
|
||||||
|
|
||||||
|
// Write out all files included in the project builder.
|
||||||
|
included.forEach(function (fileRef) {
|
||||||
|
if (fileRef.hasOwnProperty('content')) {
|
||||||
|
var content = typeof fileRef.content === 'function'
|
||||||
|
? "" + fileRef.content()
|
||||||
|
: "" + fileRef.content;
|
||||||
|
self.fs.write(fileRef.to, content);
|
||||||
|
} else {
|
||||||
|
self.fs.copyTpl(
|
||||||
|
self.templatePath(fileRef.from),
|
||||||
|
self.destinationPath(fileRef.to),
|
||||||
|
config
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Delete all files explicitly excluded in the project builder.
|
||||||
|
excluded.forEach(function (path) {
|
||||||
|
self.fs.delete(self.destinationPath(path));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
install: function () {
|
||||||
|
this.npmInstall();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
|
@ -13,36 +13,33 @@
|
||||||
* License for the specific language governing permissions and limitations
|
* License for the specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
'use strict';
|
||||||
|
|
||||||
(function () {
|
var projectBuilder = require('../project_builder');
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var projectBuilder = require('../project_builder');
|
/**
|
||||||
|
* No-op placeholder method, for handlers we don't need.
|
||||||
|
*
|
||||||
|
* @param {generator} generator The currently active generator.
|
||||||
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
|
*/
|
||||||
|
function noop (generator) {
|
||||||
|
return generator;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* No-op placeholder method, for handlers we don't need.
|
* Configure the project by adding required files.
|
||||||
*
|
*
|
||||||
* @param {generator} generator The currently active generator.
|
* @param {generator} generator The currently active generator.
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
*/
|
*/
|
||||||
function noop (generator) {
|
function configureEC (generator) {
|
||||||
return generator;
|
projectBuilder.addFile('.editorconfig');
|
||||||
}
|
return generator;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
module.exports = {
|
||||||
* Configure the project by adding required files.
|
init: noop,
|
||||||
*
|
prompt: noop,
|
||||||
* @param {generator} generator The currently active generator.
|
configure: configureEC
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
};
|
||||||
*/
|
|
||||||
function configureEC (generator) {
|
|
||||||
projectBuilder.addFile('.editorconfig');
|
|
||||||
return generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
init: noop,
|
|
||||||
prompt: noop,
|
|
||||||
configure: configureEC
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
|
|
|
@ -14,115 +14,113 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var pkgBuilder = require('../pkg_builder');
|
var pkgBuilder = require('../pkg_builder');
|
||||||
var projectBuilder = require('../project_builder');
|
var projectBuilder = require('../project_builder');
|
||||||
var yaml = require('js-yaml');
|
var yaml = require('js-yaml');
|
||||||
|
|
||||||
var excludedPaths = [];
|
var excludedPaths = [];
|
||||||
var ignoreFile = '.eslintignore';
|
var ignoreFile = '.eslintignore';
|
||||||
var rcFile = '.eslintrc';
|
var rcFile = '.eslintrc';
|
||||||
var eslintrc = {extends: 'openstack'};
|
var eslintrc = {extends: 'openstack'};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method configures the package builder with all options necessary to support eslint.
|
* This method configures the package builder with all options necessary to support eslint.
|
||||||
*
|
*
|
||||||
* @param {generator} generator The currently active generator.
|
* @param {generator} generator The currently active generator.
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
*/
|
*/
|
||||||
function promptEslint (generator) {
|
function promptEslint (generator) {
|
||||||
// At this time, we don't actually need to prompt the user.
|
// At this time, we don't actually need to prompt the user.
|
||||||
|
|
||||||
// Add the dependencies.
|
// Add the dependencies.
|
||||||
pkgBuilder.addDependencies(['eslint', 'eslint-config-openstack'], 'devDependencies');
|
pkgBuilder.addDependencies(['eslint', 'eslint-config-openstack'], 'devDependencies');
|
||||||
pkgBuilder.addCommand('lint', 'eslint ./');
|
pkgBuilder.addCommand('lint', 'eslint ./');
|
||||||
|
|
||||||
return generator;
|
return generator;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read the existing .eslintrc and .eslintignore files, and populate our initial configuration
|
* Read the existing .eslintrc and .eslintignore files, and populate our initial configuration
|
||||||
* with them.
|
* with them.
|
||||||
*
|
*
|
||||||
* @param {generator} generator The currently active generator.
|
* @param {generator} generator The currently active generator.
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
*/
|
*/
|
||||||
function initializeEslint (generator) {
|
function initializeEslint (generator) {
|
||||||
var fs = generator.fs;
|
var fs = generator.fs;
|
||||||
|
|
||||||
// Re-initialize excluded paths.
|
// Re-initialize excluded paths.
|
||||||
excludedPaths = [];
|
excludedPaths = [];
|
||||||
|
|
||||||
// Read .eslintignore.
|
// Read .eslintignore.
|
||||||
if (fs.exists(ignoreFile)) {
|
if (fs.exists(ignoreFile)) {
|
||||||
var paths = fs.read(ignoreFile)
|
var paths = fs.read(ignoreFile)
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.filter(function (item) {
|
.filter(function (item) {
|
||||||
// Remove empty lines.
|
// Remove empty lines.
|
||||||
return item.length > 0;
|
return item.length > 0;
|
||||||
});
|
|
||||||
|
|
||||||
paths.forEach(function (item) {
|
|
||||||
excludedPaths.push(item);
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
// Read .eslintrc
|
paths.forEach(function (item) {
|
||||||
if (fs.exists(rcFile)) {
|
excludedPaths.push(item);
|
||||||
eslintrc = yaml.safeLoad(fs.read(rcFile));
|
|
||||||
}
|
|
||||||
|
|
||||||
return generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configure the project by adding required files.
|
|
||||||
*
|
|
||||||
* @param {generator} generator The currently active generator.
|
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
|
||||||
*/
|
|
||||||
function configureEslint (generator) {
|
|
||||||
if (buildEslintIgnore().length === 0) {
|
|
||||||
projectBuilder.removeFile('.eslintignore');
|
|
||||||
} else {
|
|
||||||
projectBuilder.writeFile('.eslintignore', buildEslintIgnore);
|
|
||||||
}
|
|
||||||
projectBuilder.writeFile('.eslintrc', buildEslintRc);
|
|
||||||
|
|
||||||
return generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate the content of our .eslintignore file from the configured list of excluded paths,
|
|
||||||
* as well as any project-level configured ignoreFiles.
|
|
||||||
*
|
|
||||||
* @returns {string} The content of the .eslintignore file.
|
|
||||||
*/
|
|
||||||
function buildEslintIgnore () {
|
|
||||||
var ignoredFiles = projectBuilder.getIgnoredFiles();
|
|
||||||
ignoredFiles.forEach(function (item) {
|
|
||||||
if (excludedPaths.indexOf(item) === -1) {
|
|
||||||
excludedPaths.push(item);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return excludedPaths.sort().join('\n');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Read .eslintrc
|
||||||
* Generate the content of our .eslintrc file from the current configuration.
|
if (fs.exists(rcFile)) {
|
||||||
*
|
eslintrc = yaml.safeLoad(fs.read(rcFile));
|
||||||
* @returns {string} The content of the .eslintrc file.
|
|
||||||
*/
|
|
||||||
function buildEslintRc () {
|
|
||||||
return yaml.safeDump(eslintrc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
return generator;
|
||||||
init: initializeEslint,
|
}
|
||||||
prompt: promptEslint,
|
|
||||||
configure: configureEslint
|
/**
|
||||||
};
|
* Configure the project by adding required files.
|
||||||
})();
|
*
|
||||||
|
* @param {generator} generator The currently active generator.
|
||||||
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
|
*/
|
||||||
|
function configureEslint (generator) {
|
||||||
|
if (buildEslintIgnore().length === 0) {
|
||||||
|
projectBuilder.removeFile('.eslintignore');
|
||||||
|
} else {
|
||||||
|
projectBuilder.writeFile('.eslintignore', buildEslintIgnore);
|
||||||
|
}
|
||||||
|
projectBuilder.writeFile('.eslintrc', buildEslintRc);
|
||||||
|
|
||||||
|
return generator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the content of our .eslintignore file from the configured list of excluded paths,
|
||||||
|
* as well as any project-level configured ignoreFiles.
|
||||||
|
*
|
||||||
|
* @returns {string} The content of the .eslintignore file.
|
||||||
|
*/
|
||||||
|
function buildEslintIgnore () {
|
||||||
|
var ignoredFiles = projectBuilder.getIgnoredFiles();
|
||||||
|
ignoredFiles.forEach(function (item) {
|
||||||
|
if (excludedPaths.indexOf(item) === -1) {
|
||||||
|
excludedPaths.push(item);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return excludedPaths.sort().join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the content of our .eslintrc file from the current configuration.
|
||||||
|
*
|
||||||
|
* @returns {string} The content of the .eslintrc file.
|
||||||
|
*/
|
||||||
|
function buildEslintRc () {
|
||||||
|
return yaml.safeDump(eslintrc);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
init: initializeEslint,
|
||||||
|
prompt: promptEslint,
|
||||||
|
configure: configureEslint
|
||||||
|
};
|
||||||
|
|
|
@ -14,134 +14,131 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var projectBuilder = require('../project_builder');
|
var projectBuilder = require('../project_builder');
|
||||||
var pkgBuilder = require('../pkg_builder');
|
var pkgBuilder = require('../pkg_builder');
|
||||||
var ini = require('ini');
|
var ini = require('ini');
|
||||||
var Q = require('q');
|
var Q = require('q');
|
||||||
|
|
||||||
var gerritFile = '.gitreview';
|
var gerritFile = '.gitreview';
|
||||||
var iniContent;
|
var iniContent;
|
||||||
var gerritFileExists = false;
|
var gerritFileExists = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal helper method. Returns true if gerrit has been enabled.
|
* Internal helper method. Returns true if gerrit has been enabled.
|
||||||
*
|
*
|
||||||
* @param {String} answers The collection of answers.
|
* @param {String} answers The collection of answers.
|
||||||
* @returns {Function} True if enableGerrit is set, otherwise false.
|
* @returns {Function} True if enableGerrit is set, otherwise false.
|
||||||
*/
|
*/
|
||||||
var gerritEnabled = function(answers) {
|
var gerritEnabled = function(answers) {
|
||||||
return !!answers.enableGerrit;
|
return !!answers.enableGerrit;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the gerrit component of this generator. In this case, we're
|
||||||
|
* only adding default configuration values.
|
||||||
|
*
|
||||||
|
* @param {generator} generator The currently active generator.
|
||||||
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
|
*/
|
||||||
|
function initializeGerrit (generator) {
|
||||||
|
// Define our defaults
|
||||||
|
iniContent = {
|
||||||
|
gerrit: {
|
||||||
|
host: 'review.openstack.org',
|
||||||
|
port: '29418',
|
||||||
|
project: 'openstack/test-project.git'
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
return generator;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the gerrit component of this generator. In this case, we're
|
* Initialize the gerrit component of this generator. In this case, we're
|
||||||
* only adding default configuration values.
|
* only adding default configuration values.
|
||||||
*
|
*
|
||||||
* @param {generator} generator The currently active generator.
|
* @param {generator} generator The currently active generator.
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
*/
|
*/
|
||||||
function initializeGerrit (generator) {
|
function promptUserOptions (generator) {
|
||||||
// Define our defaults
|
|
||||||
iniContent = {
|
// Read the existing file and populate it as defaults.
|
||||||
gerrit: {
|
if (generator.fs.exists(gerritFile)) {
|
||||||
host: 'review.openstack.org',
|
gerritFileExists = true;
|
||||||
port: '29418',
|
iniContent = ini.parse(generator.fs.read(gerritFile));
|
||||||
project: 'openstack/test-project.git'
|
} else {
|
||||||
}
|
// Create project name from package name if gerrit file does not exist
|
||||||
};
|
var projectName = pkgBuilder.getValue("name");
|
||||||
return generator;
|
iniContent.gerrit.project = 'openstack/' + projectName + '.git';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
var deferred = Q.defer();
|
||||||
* Initialize the gerrit component of this generator. In this case, we're
|
|
||||||
* only adding default configuration values.
|
|
||||||
*
|
|
||||||
* @param {generator} generator The currently active generator.
|
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
|
||||||
*/
|
|
||||||
function promptUserOptions (generator) {
|
|
||||||
|
|
||||||
// Read the existing file and populate it as defaults.
|
if (!generator.options['non-interactive']) {
|
||||||
if (generator.fs.exists(gerritFile)) {
|
// Go through the prompts.
|
||||||
gerritFileExists = true;
|
generator.prompt(
|
||||||
iniContent = ini.parse(generator.fs.read(gerritFile));
|
[{
|
||||||
} else {
|
type: 'confirm',
|
||||||
// Create project name from package name if gerrit file does not exist
|
name: 'enableGerrit',
|
||||||
var projectName = pkgBuilder.getValue("name");
|
message: 'Gerrit- Enable:',
|
||||||
iniContent.gerrit.project = 'openstack/' + projectName + '.git';
|
default: gerritFileExists
|
||||||
}
|
}, {
|
||||||
|
when: gerritEnabled,
|
||||||
|
type: 'input',
|
||||||
|
name: 'gerritHost',
|
||||||
|
message: 'Gerrit- Host:',
|
||||||
|
default: iniContent.gerrit.host
|
||||||
|
}, {
|
||||||
|
when: gerritEnabled,
|
||||||
|
type: 'input',
|
||||||
|
name: 'gerritPort',
|
||||||
|
message: 'Gerrit- Port:',
|
||||||
|
default: iniContent.gerrit.port
|
||||||
|
}, {
|
||||||
|
when: gerritEnabled,
|
||||||
|
type: 'input',
|
||||||
|
name: 'gerritProject',
|
||||||
|
message: 'Gerrit- Project Path:',
|
||||||
|
default: iniContent.gerrit.project
|
||||||
|
}],
|
||||||
|
function(answers) {
|
||||||
|
gerritFileExists = answers.enableGerrit;
|
||||||
|
iniContent.gerrit = {
|
||||||
|
host: answers.gerritHost,
|
||||||
|
port: answers.gerritPort,
|
||||||
|
project: answers.gerritProject
|
||||||
|
};
|
||||||
|
deferred.resolve(generator);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
deferred.resolve(generator);
|
||||||
|
}
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
|
||||||
var deferred = Q.defer();
|
/**
|
||||||
|
* Configure gerrit
|
||||||
if (!generator.options['non-interactive']) {
|
*
|
||||||
// Go through the prompts.
|
* @param {generator} generator The currently active generator.
|
||||||
generator.prompt(
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
[{
|
*/
|
||||||
type: 'confirm',
|
function configureGerrit (generator) {
|
||||||
name: 'enableGerrit',
|
if (gerritFileExists) {
|
||||||
message: 'Gerrit- Enable:',
|
projectBuilder.writeFile(gerritFile, buildGerritFile);
|
||||||
default: gerritFileExists
|
} else {
|
||||||
}, {
|
projectBuilder.removeFile(gerritFile);
|
||||||
when: gerritEnabled,
|
|
||||||
type: 'input',
|
|
||||||
name: 'gerritHost',
|
|
||||||
message: 'Gerrit- Host:',
|
|
||||||
default: iniContent.gerrit.host
|
|
||||||
}, {
|
|
||||||
when: gerritEnabled,
|
|
||||||
type: 'input',
|
|
||||||
name: 'gerritPort',
|
|
||||||
message: 'Gerrit- Port:',
|
|
||||||
default: iniContent.gerrit.port
|
|
||||||
}, {
|
|
||||||
when: gerritEnabled,
|
|
||||||
type: 'input',
|
|
||||||
name: 'gerritProject',
|
|
||||||
message: 'Gerrit- Project Path:',
|
|
||||||
default: iniContent.gerrit.project
|
|
||||||
}],
|
|
||||||
function(answers) {
|
|
||||||
gerritFileExists = answers.enableGerrit;
|
|
||||||
iniContent.gerrit = {
|
|
||||||
host: answers.gerritHost,
|
|
||||||
port: answers.gerritPort,
|
|
||||||
project: answers.gerritProject
|
|
||||||
};
|
|
||||||
deferred.resolve(generator);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
deferred.resolve(generator);
|
|
||||||
}
|
|
||||||
return deferred.promise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
return generator;
|
||||||
* Configure gerrit
|
}
|
||||||
*
|
|
||||||
* @param {generator} generator The currently active generator.
|
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
|
||||||
*/
|
|
||||||
function configureGerrit (generator) {
|
|
||||||
if (gerritFileExists) {
|
|
||||||
projectBuilder.writeFile(gerritFile, buildGerritFile);
|
|
||||||
} else {
|
|
||||||
projectBuilder.removeFile(gerritFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
return generator;
|
function buildGerritFile () {
|
||||||
}
|
return ini.stringify(iniContent);
|
||||||
|
}
|
||||||
|
|
||||||
function buildGerritFile () {
|
module.exports = {
|
||||||
return ini.stringify(iniContent);
|
init: initializeGerrit,
|
||||||
}
|
prompt: promptUserOptions,
|
||||||
|
configure: configureGerrit
|
||||||
module.exports = {
|
};
|
||||||
init: initializeGerrit,
|
|
||||||
prompt: promptUserOptions,
|
|
||||||
configure: configureGerrit
|
|
||||||
};
|
|
||||||
})
|
|
||||||
();
|
|
||||||
|
|
|
@ -14,92 +14,90 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var projectBuilder = require('../project_builder');
|
var projectBuilder = require('../project_builder');
|
||||||
|
|
||||||
var excludedPaths = {};
|
var excludedPaths = {};
|
||||||
var filePath = '.gitignore';
|
var filePath = '.gitignore';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* No-op placeholder method, for handlers we don't need.
|
* No-op placeholder method, for handlers we don't need.
|
||||||
*
|
*
|
||||||
* @param {generator} generator The currently active generator.
|
* @param {generator} generator The currently active generator.
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
*/
|
*/
|
||||||
function noop (generator) {
|
function noop (generator) {
|
||||||
return generator;
|
return generator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read the existing .gitignore file, and populate our current list of ignores.
|
||||||
|
*
|
||||||
|
* @param {generator} generator The currently active generator.
|
||||||
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
|
*/
|
||||||
|
function initGitignore (generator) {
|
||||||
|
var fs = generator.fs;
|
||||||
|
|
||||||
|
// Reinitialize the ignore map.
|
||||||
|
excludedPaths = {};
|
||||||
|
|
||||||
|
// Read .gitignore.
|
||||||
|
if (fs.exists(filePath)) {
|
||||||
|
fs.read(filePath)
|
||||||
|
// Split into lines
|
||||||
|
.split('\n')
|
||||||
|
// Remove empty lines and comments.
|
||||||
|
.filter(function (item) {
|
||||||
|
return item.length > 0 && !item.match(/\s*#/);
|
||||||
|
})
|
||||||
|
// Add to our list.
|
||||||
|
.map(function (line) {
|
||||||
|
excludedPaths[line] = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
return generator;
|
||||||
* Read the existing .gitignore file, and populate our current list of ignores.
|
}
|
||||||
*
|
|
||||||
* @param {generator} generator The currently active generator.
|
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
|
||||||
*/
|
|
||||||
function initGitignore (generator) {
|
|
||||||
var fs = generator.fs;
|
|
||||||
|
|
||||||
// Reinitialize the ignore map.
|
/**
|
||||||
excludedPaths = {};
|
* Generate the .gitignore file from the data we've imported.
|
||||||
|
*
|
||||||
|
* @param {generator} generator The currently active generator.
|
||||||
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
|
*/
|
||||||
|
function configureGitIgnore (generator) {
|
||||||
|
var ignoreContent = buildGitignore();
|
||||||
|
if (ignoreContent.length === 0) {
|
||||||
|
// Delete the file if there's nothing to ignore.
|
||||||
|
projectBuilder.removeFile(filePath);
|
||||||
|
} else {
|
||||||
|
projectBuilder.writeFile(filePath, buildGitignore);
|
||||||
|
}
|
||||||
|
|
||||||
// Read .gitignore.
|
return generator;
|
||||||
if (fs.exists(filePath)) {
|
}
|
||||||
fs.read(filePath)
|
|
||||||
// Split into lines
|
/**
|
||||||
.split('\n')
|
* Generate the content of our .gitignore file from the configured list of excluded paths,
|
||||||
// Remove empty lines and comments.
|
* as well as any project-level configured ignoreFiles.
|
||||||
.filter(function (item) {
|
*
|
||||||
return item.length > 0 && !item.match(/\s*#/);
|
* @returns {string} The content of the .eslintignore file.
|
||||||
})
|
*/
|
||||||
// Add to our list.
|
function buildGitignore () {
|
||||||
.map(function (line) {
|
var ignoredFiles = projectBuilder.getIgnoredFiles();
|
||||||
excludedPaths[line] = true;
|
for (var i = 0; i < ignoredFiles.length; i++) {
|
||||||
});
|
if (!excludedPaths.hasOwnProperty(ignoredFiles[i])) {
|
||||||
|
excludedPaths[ignoredFiles[i]] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return generator;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
return Object.keys(excludedPaths).sort().join('\n');
|
||||||
* Generate the .gitignore file from the data we've imported.
|
}
|
||||||
*
|
|
||||||
* @param {generator} generator The currently active generator.
|
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
|
||||||
*/
|
|
||||||
function configureGitIgnore (generator) {
|
|
||||||
var ignoreContent = buildGitignore();
|
|
||||||
if (ignoreContent.length === 0) {
|
|
||||||
// Delete the file if there's nothing to ignore.
|
|
||||||
projectBuilder.removeFile(filePath);
|
|
||||||
} else {
|
|
||||||
projectBuilder.writeFile(filePath, buildGitignore);
|
|
||||||
}
|
|
||||||
|
|
||||||
return generator;
|
module.exports = {
|
||||||
}
|
init: initGitignore,
|
||||||
|
prompt: noop,
|
||||||
/**
|
configure: configureGitIgnore
|
||||||
* Generate the content of our .gitignore file from the configured list of excluded paths,
|
};
|
||||||
* as well as any project-level configured ignoreFiles.
|
|
||||||
*
|
|
||||||
* @returns {string} The content of the .eslintignore file.
|
|
||||||
*/
|
|
||||||
function buildGitignore () {
|
|
||||||
var ignoredFiles = projectBuilder.getIgnoredFiles();
|
|
||||||
for (var i = 0; i < ignoredFiles.length; i++) {
|
|
||||||
if (!excludedPaths.hasOwnProperty(ignoredFiles[i])) {
|
|
||||||
excludedPaths[ignoredFiles[i]] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Object.keys(excludedPaths).sort().join('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
init: initGitignore,
|
|
||||||
prompt: noop,
|
|
||||||
configure: configureGitIgnore
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
|
|
|
@ -14,38 +14,36 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var projectBuilder = require('../project_builder');
|
var projectBuilder = require('../project_builder');
|
||||||
var pkgBuilder = require('../pkg_builder');
|
var pkgBuilder = require('../pkg_builder');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* No-op placeholder method, for handlers we don't need.
|
* No-op placeholder method, for handlers we don't need.
|
||||||
*
|
*
|
||||||
* @param {generator} generator The currently active generator.
|
* @param {generator} generator The currently active generator.
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
*/
|
*/
|
||||||
function noop (generator) {
|
function noop (generator) {
|
||||||
return generator;
|
return generator;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure the project by adding required files.
|
* Configure the project by adding required files.
|
||||||
*
|
*
|
||||||
* @param {generator} generator The currently active generator.
|
* @param {generator} generator The currently active generator.
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
*/
|
*/
|
||||||
function configureLicense (generator) {
|
function configureLicense (generator) {
|
||||||
projectBuilder.addFile('LICENSE');
|
projectBuilder.addFile('LICENSE');
|
||||||
pkgBuilder.setValues({license: 'Apache-2.0'});
|
pkgBuilder.setValues({license: 'Apache-2.0'});
|
||||||
|
|
||||||
return generator;
|
return generator;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
init: noop,
|
init: noop,
|
||||||
prompt: noop,
|
prompt: noop,
|
||||||
configure: configureLicense
|
configure: configureLicense
|
||||||
};
|
};
|
||||||
})();
|
|
||||||
|
|
|
@ -19,53 +19,52 @@
|
||||||
* Its job is to identify known vulnerabilities by scanning the projects
|
* Its job is to identify known vulnerabilities by scanning the projects
|
||||||
* source and dependencies.
|
* source and dependencies.
|
||||||
*/
|
*/
|
||||||
(function () {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var projectBuilder = require('../project_builder');
|
'use strict';
|
||||||
var pkgBuilder = require('../pkg_builder');
|
|
||||||
|
|
||||||
/**
|
var projectBuilder = require('../project_builder');
|
||||||
* No-op placeholder method, for handlers we don't need.
|
var pkgBuilder = require('../pkg_builder');
|
||||||
*
|
|
||||||
* @param {generator} generator The currently active generator.
|
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
|
||||||
*/
|
|
||||||
function noop (generator) {
|
|
||||||
return generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method configures the package builder with all options necessary
|
* No-op placeholder method, for handlers we don't need.
|
||||||
* to run nsp.
|
*
|
||||||
*
|
* @param {generator} generator The currently active generator.
|
||||||
* @param {generator} generator The currently active generator.
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
*/
|
||||||
*/
|
function noop (generator) {
|
||||||
function promptNsp (generator) {
|
return generator;
|
||||||
// At this time, we don't actually need to prompt the user.
|
}
|
||||||
|
|
||||||
// Add the dependencies.
|
/**
|
||||||
pkgBuilder.addDependencies(['nsp'], 'devDependencies');
|
* This method configures the package builder with all options necessary
|
||||||
pkgBuilder.addCommand('prepublish', 'nsp check');
|
* to run nsp.
|
||||||
|
*
|
||||||
|
* @param {generator} generator The currently active generator.
|
||||||
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
|
*/
|
||||||
|
function promptNsp (generator) {
|
||||||
|
// At this time, we don't actually need to prompt the user.
|
||||||
|
|
||||||
return generator;
|
// Add the dependencies.
|
||||||
}
|
pkgBuilder.addDependencies(['nsp'], 'devDependencies');
|
||||||
|
pkgBuilder.addCommand('prepublish', 'nsp check');
|
||||||
|
|
||||||
/**
|
return generator;
|
||||||
* Configure the project by adding required files.
|
}
|
||||||
*
|
|
||||||
* @param {generator} generator The currently active generator.
|
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
|
||||||
*/
|
|
||||||
function configureNsp (generator) {
|
|
||||||
projectBuilder.addFile('.nsprc');
|
|
||||||
return generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
/**
|
||||||
init: noop,
|
* Configure the project by adding required files.
|
||||||
prompt: promptNsp,
|
*
|
||||||
configure: configureNsp
|
* @param {generator} generator The currently active generator.
|
||||||
};
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
})();
|
*/
|
||||||
|
function configureNsp (generator) {
|
||||||
|
projectBuilder.addFile('.nsprc');
|
||||||
|
return generator;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
init: noop,
|
||||||
|
prompt: promptNsp,
|
||||||
|
configure: configureNsp
|
||||||
|
};
|
||||||
|
|
|
@ -14,110 +14,108 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var Q = require('q');
|
var Q = require('q');
|
||||||
var hyphenize = require('hyphenize');
|
var hyphenize = require('hyphenize');
|
||||||
var pkgBuilder = require('../pkg_builder');
|
var pkgBuilder = require('../pkg_builder');
|
||||||
var projectBuilder = require('../project_builder');
|
var projectBuilder = require('../project_builder');
|
||||||
|
|
||||||
var packagePath = 'package.json';
|
var packagePath = 'package.json';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterate over needed package components, ensuring that required
|
* Iterate over needed package components, ensuring that required
|
||||||
* parameters are set.
|
* parameters are set.
|
||||||
*
|
*
|
||||||
* @param {generator} generator The currently active generator.
|
* @param {generator} generator The currently active generator.
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
*/
|
*/
|
||||||
function promptPackage (generator) {
|
function promptPackage (generator) {
|
||||||
var deferred = Q.defer();
|
var deferred = Q.defer();
|
||||||
|
|
||||||
if (!generator.options['non-interactive']) {
|
if (!generator.options['non-interactive']) {
|
||||||
generator.prompt(
|
generator.prompt(
|
||||||
[{
|
[{
|
||||||
type: 'input',
|
type: 'input',
|
||||||
name: 'name',
|
name: 'name',
|
||||||
message: 'Project- Name:',
|
message: 'Project- Name:',
|
||||||
default: pkgBuilder.getValue('name', hyphenize(generator.appname))
|
default: pkgBuilder.getValue('name', hyphenize(generator.appname))
|
||||||
}, {
|
}, {
|
||||||
type: 'input',
|
type: 'input',
|
||||||
name: 'description',
|
name: 'description',
|
||||||
message: 'Project- Description:',
|
message: 'Project- Description:',
|
||||||
default: pkgBuilder.getValue('description')
|
default: pkgBuilder.getValue('description')
|
||||||
}, {
|
}, {
|
||||||
type: 'input',
|
type: 'input',
|
||||||
name: 'version',
|
name: 'version',
|
||||||
message: 'Project- Version:',
|
message: 'Project- Version:',
|
||||||
default: pkgBuilder.getValue('version', '0.0.1')
|
default: pkgBuilder.getValue('version', '0.0.1')
|
||||||
}, {
|
}, {
|
||||||
type: 'input',
|
type: 'input',
|
||||||
name: 'homepage',
|
name: 'homepage',
|
||||||
message: 'Project- Homepage:',
|
message: 'Project- Homepage:',
|
||||||
default: pkgBuilder.getValue('homepage', 'http://www.openstack.org/')
|
default: pkgBuilder.getValue('homepage', 'http://www.openstack.org/')
|
||||||
}, {
|
}, {
|
||||||
type: 'input',
|
type: 'input',
|
||||||
name: 'author',
|
name: 'author',
|
||||||
message: 'Project- Author:',
|
message: 'Project- Author:',
|
||||||
default: pkgBuilder.getValue('author',
|
default: pkgBuilder.getValue('author',
|
||||||
'OpenStack <openstack-dev@lists.openstack.org> (http://www.openstack.org/)')
|
'OpenStack <openstack-dev@lists.openstack.org> (http://www.openstack.org/)')
|
||||||
}],
|
}],
|
||||||
function (answers) {
|
function (answers) {
|
||||||
pkgBuilder.setValues(answers);
|
pkgBuilder.setValues(answers);
|
||||||
deferred.resolve(generator);
|
deferred.resolve(generator);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
deferred.resolve(generator);
|
deferred.resolve(generator);
|
||||||
}
|
|
||||||
|
|
||||||
return deferred.promise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
return deferred.promise;
|
||||||
* Read any existing package.json file, to set our defaults.
|
}
|
||||||
*
|
|
||||||
* @param {generator} generator The currently active generator.
|
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
|
||||||
*/
|
|
||||||
function initializePackage (generator) {
|
|
||||||
var fs = generator.fs;
|
|
||||||
|
|
||||||
// Read package.json
|
/**
|
||||||
if (fs.exists(packagePath)) {
|
* Read any existing package.json file, to set our defaults.
|
||||||
pkgBuilder.fromJSON(fs.read(packagePath));
|
*
|
||||||
}
|
* @param {generator} generator The currently active generator.
|
||||||
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
|
*/
|
||||||
|
function initializePackage (generator) {
|
||||||
|
var fs = generator.fs;
|
||||||
|
|
||||||
// Add files that should be ignored overall.
|
// Read package.json
|
||||||
projectBuilder.ignoreFile('node_modules');
|
if (fs.exists(packagePath)) {
|
||||||
// NPM execution failures.
|
pkgBuilder.fromJSON(fs.read(packagePath));
|
||||||
projectBuilder.ignoreFile('npm-debug.log');
|
|
||||||
// If you unzip something generated by npm pack, this is the directory it ends up in.
|
|
||||||
projectBuilder.ignoreFile('package');
|
|
||||||
// Local .npm cache
|
|
||||||
projectBuilder.ignoreFile('.npm');
|
|
||||||
|
|
||||||
var devDeps = ['istanbul', 'jasmine'];
|
|
||||||
|
|
||||||
pkgBuilder.addDependencies(devDeps, 'devDependencies');
|
|
||||||
|
|
||||||
return generator;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Add files that should be ignored overall.
|
||||||
* Configure the project by adding required files.
|
projectBuilder.ignoreFile('node_modules');
|
||||||
*
|
// NPM execution failures.
|
||||||
* @param {generator} generator The currently active generator.
|
projectBuilder.ignoreFile('npm-debug.log');
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
// If you unzip something generated by npm pack, this is the directory it ends up in.
|
||||||
*/
|
projectBuilder.ignoreFile('package');
|
||||||
function configurePkg (generator) {
|
// Local .npm cache
|
||||||
projectBuilder.writeFile('package.json', pkgBuilder.toJSON);
|
projectBuilder.ignoreFile('.npm');
|
||||||
return generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
var devDeps = ['istanbul', 'jasmine'];
|
||||||
init: initializePackage,
|
|
||||||
prompt: promptPackage,
|
pkgBuilder.addDependencies(devDeps, 'devDependencies');
|
||||||
configure: configurePkg
|
|
||||||
};
|
return generator;
|
||||||
})();
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the project by adding required files.
|
||||||
|
*
|
||||||
|
* @param {generator} generator The currently active generator.
|
||||||
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
|
*/
|
||||||
|
function configurePkg (generator) {
|
||||||
|
projectBuilder.writeFile('package.json', pkgBuilder.toJSON);
|
||||||
|
return generator;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
init: initializePackage,
|
||||||
|
prompt: promptPackage,
|
||||||
|
configure: configurePkg
|
||||||
|
};
|
||||||
|
|
|
@ -20,120 +20,119 @@
|
||||||
* other generators, such as test framework generation, packaging tools,
|
* other generators, such as test framework generation, packaging tools,
|
||||||
* and/or configuration files.
|
* and/or configuration files.
|
||||||
*/
|
*/
|
||||||
(function () {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var Q = require('q');
|
'use strict';
|
||||||
var projectBuilder = require('../project_builder');
|
|
||||||
|
|
||||||
/**
|
var Q = require('q');
|
||||||
* Initialize the component by setting configuration defaults. These, or previously set
|
var projectBuilder = require('../project_builder');
|
||||||
* versions, will be accessible immediately, however it's good practice not to access them
|
|
||||||
* until after the prompting phase, as we cannot guarantee that they will be properly set.
|
|
||||||
*
|
|
||||||
* @param {generator} generator The currently active generator.
|
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
|
||||||
*/
|
|
||||||
function initialize (generator) {
|
|
||||||
|
|
||||||
// Set our defaults:
|
/**
|
||||||
generator.config.defaults({
|
* Initialize the component by setting configuration defaults. These, or previously set
|
||||||
engine: 'browser',
|
* versions, will be accessible immediately, however it's good practice not to access them
|
||||||
language: 'es5',
|
* until after the prompting phase, as we cannot guarantee that they will be properly set.
|
||||||
srcDir: './src',
|
*
|
||||||
distDir: './dist',
|
* @param {generator} generator The currently active generator.
|
||||||
testDir: './test'
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
});
|
*/
|
||||||
|
function initialize (generator) {
|
||||||
|
|
||||||
return generator;
|
// Set our defaults:
|
||||||
}
|
generator.config.defaults({
|
||||||
|
engine: 'browser',
|
||||||
|
language: 'es5',
|
||||||
|
srcDir: './src',
|
||||||
|
distDir: './dist',
|
||||||
|
testDir: './test'
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
return generator;
|
||||||
* If applicable, prompt the user for a project type.
|
}
|
||||||
*
|
|
||||||
* @param {generator} generator The currently active generator.
|
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
|
||||||
*/
|
|
||||||
function prompt (generator) {
|
|
||||||
var deferred = Q.defer();
|
|
||||||
|
|
||||||
// We default to a node.js project.
|
/**
|
||||||
if (!generator.options['non-interactive']) {
|
* If applicable, prompt the user for a project type.
|
||||||
// Go through the prompts.
|
*
|
||||||
generator.prompt(
|
* @param {generator} generator The currently active generator.
|
||||||
[{
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
type: 'list',
|
*/
|
||||||
name: 'engine',
|
function prompt (generator) {
|
||||||
message: 'Structure- Runtime Engine:',
|
var deferred = Q.defer();
|
||||||
choices: [
|
|
||||||
{
|
// We default to a node.js project.
|
||||||
name: 'Browser',
|
if (!generator.options['non-interactive']) {
|
||||||
value: 'browser'
|
// Go through the prompts.
|
||||||
},
|
generator.prompt(
|
||||||
{
|
[{
|
||||||
name: 'Node.js',
|
type: 'list',
|
||||||
value: 'node'
|
name: 'engine',
|
||||||
}
|
message: 'Structure- Runtime Engine:',
|
||||||
],
|
choices: [
|
||||||
default: generator.config.get('engine')
|
{
|
||||||
}, {
|
name: 'Browser',
|
||||||
type: 'list',
|
value: 'browser'
|
||||||
name: 'language',
|
},
|
||||||
message: 'Structure- Language:',
|
{
|
||||||
choices: [
|
name: 'Node.js',
|
||||||
{
|
value: 'node'
|
||||||
name: 'ECMAScript 5',
|
|
||||||
value: 'es5'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'ECMAScript 6',
|
|
||||||
value: 'es6'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
default: generator.config.get('language')
|
|
||||||
}, {
|
|
||||||
type: 'input',
|
|
||||||
name: 'srcDir',
|
|
||||||
message: 'Structure- Source Directory:',
|
|
||||||
default: generator.config.get('srcDir')
|
|
||||||
}, {
|
|
||||||
type: 'input',
|
|
||||||
name: 'testDir',
|
|
||||||
message: 'Structure- Test Directory:',
|
|
||||||
default: generator.config.get('testDir')
|
|
||||||
}, {
|
|
||||||
type: 'input',
|
|
||||||
name: 'distDir',
|
|
||||||
message: 'Structure- Dist Directory:',
|
|
||||||
default: generator.config.get('distDir'),
|
|
||||||
when: function (answers) {
|
|
||||||
return answers.engine === 'browser';
|
|
||||||
}
|
}
|
||||||
}],
|
],
|
||||||
function (answers) {
|
default: generator.config.get('engine')
|
||||||
generator.config.set(answers);
|
}, {
|
||||||
deferred.resolve(generator);
|
type: 'list',
|
||||||
});
|
name: 'language',
|
||||||
} else {
|
message: 'Structure- Language:',
|
||||||
deferred.resolve(generator);
|
choices: [
|
||||||
}
|
{
|
||||||
return deferred.promise;
|
name: 'ECMAScript 5',
|
||||||
|
value: 'es5'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ECMAScript 6',
|
||||||
|
value: 'es6'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
default: generator.config.get('language')
|
||||||
|
}, {
|
||||||
|
type: 'input',
|
||||||
|
name: 'srcDir',
|
||||||
|
message: 'Structure- Source Directory:',
|
||||||
|
default: generator.config.get('srcDir')
|
||||||
|
}, {
|
||||||
|
type: 'input',
|
||||||
|
name: 'testDir',
|
||||||
|
message: 'Structure- Test Directory:',
|
||||||
|
default: generator.config.get('testDir')
|
||||||
|
}, {
|
||||||
|
type: 'input',
|
||||||
|
name: 'distDir',
|
||||||
|
message: 'Structure- Dist Directory:',
|
||||||
|
default: generator.config.get('distDir'),
|
||||||
|
when: function (answers) {
|
||||||
|
return answers.engine === 'browser';
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
function (answers) {
|
||||||
|
generator.config.set(answers);
|
||||||
|
deferred.resolve(generator);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
deferred.resolve(generator);
|
||||||
}
|
}
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add any output directories to the ignore files.
|
* Add any output directories to the ignore files.
|
||||||
*
|
*
|
||||||
* @param {generator} generator The currently active generator.
|
* @param {generator} generator The currently active generator.
|
||||||
* @returns {generator} The passed generator, for promise chaining.
|
* @returns {generator} The passed generator, for promise chaining.
|
||||||
*/
|
*/
|
||||||
function configure (generator) {
|
function configure (generator) {
|
||||||
projectBuilder.ignoreFile(generator.config.get('distDir'));
|
projectBuilder.ignoreFile(generator.config.get('distDir'));
|
||||||
return generator;
|
return generator;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
init: initialize,
|
init: initialize,
|
||||||
prompt: prompt,
|
prompt: prompt,
|
||||||
configure: configure
|
configure: configure
|
||||||
};
|
};
|
||||||
})();
|
|
||||||
|
|
|
@ -13,57 +13,55 @@
|
||||||
* License for the specific language governing permissions and limitations
|
* License for the specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access to the global-dependencies.json file.
|
* Access to the global-dependencies.json file.
|
||||||
*/
|
*/
|
||||||
(function () {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var globalDependencies = require('../../../global-dependencies.json');
|
'use strict';
|
||||||
|
|
||||||
/**
|
var globalDependencies = require('../../../global-dependencies.json');
|
||||||
* Returns whether a dependency is in the global-dependencies list.
|
|
||||||
*
|
|
||||||
* @param {String} name The name of the dependency.
|
|
||||||
* @returns {Boolean} True if the dependency exists, otherwise false.
|
|
||||||
*/
|
|
||||||
function containsDependency (name) {
|
|
||||||
return globalDependencies.hasOwnProperty(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the current acceptable version of the dependencies, or null.
|
* Returns whether a dependency is in the global-dependencies list.
|
||||||
*
|
*
|
||||||
* @param {String} name The dependency name.
|
* @param {String} name The name of the dependency.
|
||||||
* @returns {String|undefined} The version, or undefined.
|
* @returns {Boolean} True if the dependency exists, otherwise false.
|
||||||
*/
|
*/
|
||||||
function getVersion (name) {
|
function containsDependency (name) {
|
||||||
return globalDependencies[name] || undefined;
|
return globalDependencies.hasOwnProperty(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a list of dependencies, updates this list of dependencies to the versions that are
|
* Return the current acceptable version of the dependencies, or null.
|
||||||
* currently set in global-dependencies.
|
*
|
||||||
*
|
* @param {String} name The dependency name.
|
||||||
* @param {{}} dependencies The list of dependencies.
|
* @returns {String|undefined} The version, or undefined.
|
||||||
* @returns {{}} The above list of dependencies, with only the appropriate versions updated.
|
*/
|
||||||
*/
|
function getVersion (name) {
|
||||||
function synchronizeDependencies (dependencies) {
|
return globalDependencies[name] || undefined;
|
||||||
var results = {};
|
}
|
||||||
for (var key in dependencies) {
|
|
||||||
if (globalDependencies.hasOwnProperty(key)) {
|
/**
|
||||||
results[key] = globalDependencies[key];
|
* Given a list of dependencies, updates this list of dependencies to the versions that are
|
||||||
} else {
|
* currently set in global-dependencies.
|
||||||
results[key] = dependencies[key];
|
*
|
||||||
}
|
* @param {{}} dependencies The list of dependencies.
|
||||||
|
* @returns {{}} The above list of dependencies, with only the appropriate versions updated.
|
||||||
|
*/
|
||||||
|
function synchronizeDependencies (dependencies) {
|
||||||
|
var results = {};
|
||||||
|
for (var key in dependencies) {
|
||||||
|
if (globalDependencies.hasOwnProperty(key)) {
|
||||||
|
results[key] = globalDependencies[key];
|
||||||
|
} else {
|
||||||
|
results[key] = dependencies[key];
|
||||||
}
|
}
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
contains: containsDependency,
|
contains: containsDependency,
|
||||||
read: getVersion,
|
read: getVersion,
|
||||||
synchronize: synchronizeDependencies
|
synchronize: synchronizeDependencies
|
||||||
};
|
};
|
||||||
})();
|
|
||||||
|
|
|
@ -14,153 +14,151 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var dependencies = require('./global_dependencies');
|
var dependencies = require('./global_dependencies');
|
||||||
var pkgContent = {};
|
var pkgContent = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a package.json formatted list of dependencies and update them to the versions
|
* Convert a package.json formatted list of dependencies and update them to the versions
|
||||||
* listed in our global dependencies.
|
* listed in our global dependencies.
|
||||||
*
|
*
|
||||||
* @param {{}} dependencyMap The map of dependencies.
|
* @param {{}} dependencyMap The map of dependencies.
|
||||||
* @returns {{}} A clone of the map, updated with current common versions.
|
* @returns {{}} A clone of the map, updated with current common versions.
|
||||||
*/
|
*/
|
||||||
function synchronizeDependencies (dependencyMap) {
|
function synchronizeDependencies (dependencyMap) {
|
||||||
if (!dependencyMap) {
|
if (!dependencyMap) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
|
||||||
|
|
||||||
// Cloning not necessary, handled in dependencies.synchronize();
|
|
||||||
return dependencies.synchronize(dependencyMap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Cloning not necessary, handled in dependencies.synchronize();
|
||||||
* Initialize this builder from a JSON string.
|
return dependencies.synchronize(dependencyMap);
|
||||||
*
|
}
|
||||||
* @param {String} pkgString The package string content.
|
|
||||||
* @returns {void}
|
/**
|
||||||
*/
|
* Initialize this builder from a JSON string.
|
||||||
function readPackage (pkgString) {
|
*
|
||||||
pkgContent = JSON.parse(pkgString);
|
* @param {String} pkgString The package string content.
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
function readPackage (pkgString) {
|
||||||
|
pkgContent = JSON.parse(pkgString);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write the package content to a JSON string.
|
||||||
|
*
|
||||||
|
* @returns {String} The JSON content of the package, as a string.
|
||||||
|
*/
|
||||||
|
function writePackage () {
|
||||||
|
// Clone the package content so we don't destroy what's in memory...
|
||||||
|
var newContent = JSON.parse(JSON.stringify(pkgContent));
|
||||||
|
|
||||||
|
// Synchronize all the dependencies.
|
||||||
|
newContent.peerDependencies = synchronizeDependencies(newContent.peerDependencies);
|
||||||
|
newContent.dependencies = synchronizeDependencies(newContent.dependencies);
|
||||||
|
newContent.devDependencies = synchronizeDependencies(newContent.devDependencies);
|
||||||
|
return JSON.stringify(newContent, null, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add libraries to the package dependencies.
|
||||||
|
*
|
||||||
|
* @param {[]|String} libraryNames A list of all libraries to add to the dependencies.
|
||||||
|
* @param {String} type The type of dependency.
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
function addDependencies (libraryNames, type) {
|
||||||
|
// Default the type.
|
||||||
|
type = type || 'dependencies';
|
||||||
|
|
||||||
|
// Valuecheck type.
|
||||||
|
if (['devDependencies', 'peerDependencies', 'dependencies'].indexOf(type) === -1) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Default the array.
|
||||||
* Write the package content to a JSON string.
|
if (!Array.isArray(libraryNames)) {
|
||||||
*
|
libraryNames = [libraryNames];
|
||||||
* @returns {String} The JSON content of the package, as a string.
|
|
||||||
*/
|
|
||||||
function writePackage () {
|
|
||||||
// Clone the package content so we don't destroy what's in memory...
|
|
||||||
var newContent = JSON.parse(JSON.stringify(pkgContent));
|
|
||||||
|
|
||||||
// Synchronize all the dependencies.
|
|
||||||
newContent.peerDependencies = synchronizeDependencies(newContent.peerDependencies);
|
|
||||||
newContent.dependencies = synchronizeDependencies(newContent.dependencies);
|
|
||||||
newContent.devDependencies = synchronizeDependencies(newContent.devDependencies);
|
|
||||||
return JSON.stringify(newContent, null, 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Make sure the property exists.
|
||||||
* Add libraries to the package dependencies.
|
if (!pkgContent.hasOwnProperty(type)) {
|
||||||
*
|
pkgContent[type] = {};
|
||||||
* @param {[]|String} libraryNames A list of all libraries to add to the dependencies.
|
|
||||||
* @param {String} type The type of dependency.
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
function addDependencies (libraryNames, type) {
|
|
||||||
// Default the type.
|
|
||||||
type = type || 'dependencies';
|
|
||||||
|
|
||||||
// Valuecheck type.
|
|
||||||
if (['devDependencies', 'peerDependencies', 'dependencies'].indexOf(type) === -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default the array.
|
|
||||||
if (!Array.isArray(libraryNames)) {
|
|
||||||
libraryNames = [libraryNames];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure the property exists.
|
|
||||||
if (!pkgContent.hasOwnProperty(type)) {
|
|
||||||
pkgContent[type] = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the dependency
|
|
||||||
libraryNames.forEach(function (library) {
|
|
||||||
var version = dependencies.read(library);
|
|
||||||
if (version && !pkgContent[type].hasOwnProperty(library)) {
|
|
||||||
pkgContent[type][library] = version;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Add the dependency
|
||||||
* Set values on the current package.
|
libraryNames.forEach(function (library) {
|
||||||
*
|
var version = dependencies.read(library);
|
||||||
* @param {{}} values A map of values.
|
if (version && !pkgContent[type].hasOwnProperty(library)) {
|
||||||
* @returns {void}
|
pkgContent[type][library] = version;
|
||||||
*/
|
}
|
||||||
function setValues (values) {
|
});
|
||||||
for (var key in values) {
|
}
|
||||||
// Filter out things from prototype.
|
|
||||||
if (values.hasOwnProperty(key)) {
|
/**
|
||||||
pkgContent[key] = values[key];
|
* Set values on the current package.
|
||||||
}
|
*
|
||||||
|
* @param {{}} values A map of values.
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
function setValues (values) {
|
||||||
|
for (var key in values) {
|
||||||
|
// Filter out things from prototype.
|
||||||
|
if (values.hasOwnProperty(key)) {
|
||||||
|
pkgContent[key] = values[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the values of the current package.
|
* Get the values of the current package.
|
||||||
*
|
*
|
||||||
* @returns {{}} A cloned map of the values.
|
* @returns {{}} A cloned map of the values.
|
||||||
*/
|
*/
|
||||||
function getValues () {
|
function getValues () {
|
||||||
return JSON.parse(JSON.stringify(pkgContent));
|
return JSON.parse(JSON.stringify(pkgContent));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a specific value from the package.json file, or a default if the
|
||||||
|
* value is not set.
|
||||||
|
*
|
||||||
|
* @param {String} name The name of the value.
|
||||||
|
* @param {String} defaultValue A default value to return.
|
||||||
|
* @returns {{}} A clone of the referenced value.
|
||||||
|
*/
|
||||||
|
function getValue (name, defaultValue) {
|
||||||
|
if (pkgContent.hasOwnProperty(name)) {
|
||||||
|
return JSON.parse(JSON.stringify(pkgContent[name]));
|
||||||
|
}
|
||||||
|
return defaultValue || undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a specific NPM script command, invoked by 'npm run <name>' or 'npm <name>'.
|
||||||
|
*
|
||||||
|
* @param {String} name The name of the script.
|
||||||
|
* @param {String} command The command to invoke.
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
function addCommand (name, command) {
|
||||||
|
|
||||||
|
// sanity check, does 'scripts' exist?
|
||||||
|
if (!pkgContent.hasOwnProperty('scripts')) {
|
||||||
|
pkgContent.scripts = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Save/Override the command.
|
||||||
* Get a specific value from the package.json file, or a default if the
|
pkgContent.scripts[name] = command;
|
||||||
* value is not set.
|
}
|
||||||
*
|
|
||||||
* @param {String} name The name of the value.
|
|
||||||
* @param {String} defaultValue A default value to return.
|
|
||||||
* @returns {{}} A clone of the referenced value.
|
|
||||||
*/
|
|
||||||
function getValue (name, defaultValue) {
|
|
||||||
if (pkgContent.hasOwnProperty(name)) {
|
|
||||||
return JSON.parse(JSON.stringify(pkgContent[name]));
|
|
||||||
}
|
|
||||||
return defaultValue || undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
module.exports = {
|
||||||
* Create a specific NPM script command, invoked by 'npm run <name>' or 'npm <name>'.
|
fromJSON: readPackage,
|
||||||
*
|
toJSON: writePackage,
|
||||||
* @param {String} name The name of the script.
|
setValues: setValues,
|
||||||
* @param {String} command The command to invoke.
|
getValues: getValues,
|
||||||
* @returns {void}
|
getValue: getValue,
|
||||||
*/
|
addDependencies: addDependencies,
|
||||||
function addCommand (name, command) {
|
addCommand: addCommand
|
||||||
|
};
|
||||||
// sanity check, does 'scripts' exist?
|
|
||||||
if (!pkgContent.hasOwnProperty('scripts')) {
|
|
||||||
pkgContent.scripts = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save/Override the command.
|
|
||||||
pkgContent.scripts[name] = command;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
fromJSON: readPackage,
|
|
||||||
toJSON: writePackage,
|
|
||||||
setValues: setValues,
|
|
||||||
getValues: getValues,
|
|
||||||
getValue: getValue,
|
|
||||||
addDependencies: addDependencies,
|
|
||||||
addCommand: addCommand
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
|
|
|
@ -14,105 +14,103 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var includedFiles = [];
|
var includedFiles = [];
|
||||||
var excludedFiles = [];
|
var excludedFiles = [];
|
||||||
var ignoredFiles = [];
|
var ignoredFiles = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure that a file is removed, or not present, in the project.
|
* Ensure that a file is removed, or not present, in the project.
|
||||||
*
|
*
|
||||||
* @param {String} destinationPath Path to the file, relative to output root.
|
* @param {String} destinationPath Path to the file, relative to output root.
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function removeFile (destinationPath) {
|
function removeFile (destinationPath) {
|
||||||
excludedFiles.push(destinationPath);
|
excludedFiles.push(destinationPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flag a file path as 'ignored'.
|
* Flag a file path as 'ignored'.
|
||||||
*
|
*
|
||||||
* This does not have a real impact on which files are created/removed from the bootstrapped
|
* This does not have a real impact on which files are created/removed from the bootstrapped
|
||||||
* project, however it does permit other modules to retrieve this list and modify their
|
* project, however it does permit other modules to retrieve this list and modify their
|
||||||
* behavior accordingly. For example, eslint could use this to generate .eslintignore
|
* behavior accordingly. For example, eslint could use this to generate .eslintignore
|
||||||
*
|
*
|
||||||
* @param {String} destinationPath Path to the file, relative to output root.
|
* @param {String} destinationPath Path to the file, relative to output root.
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function ignoreFile (destinationPath) {
|
function ignoreFile (destinationPath) {
|
||||||
ignoredFiles.push(destinationPath);
|
ignoredFiles.push(destinationPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a file to the project.
|
* Add a file to the project.
|
||||||
*
|
*
|
||||||
* @param {String} sourcePath Path to the file, relative to ./templates/
|
* @param {String} sourcePath Path to the file, relative to ./templates/
|
||||||
* @param {String} destinationPath Destination path relative to output root.
|
* @param {String} destinationPath Destination path relative to output root.
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function addFile (sourcePath, destinationPath) {
|
function addFile (sourcePath, destinationPath) {
|
||||||
includedFiles.push({from: sourcePath, to: destinationPath || sourcePath});
|
includedFiles.push({from: sourcePath, to: destinationPath || sourcePath});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a file to the project.
|
* Write a file to the project.
|
||||||
*
|
*
|
||||||
* @param {String} destinationPath The destination for the file.
|
* @param {String} destinationPath The destination for the file.
|
||||||
* @param {String|Function} content A string of content, or method that returns one.
|
* @param {String|Function} content A string of content, or method that returns one.
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function writeFile (destinationPath, content) {
|
function writeFile (destinationPath, content) {
|
||||||
includedFiles.push({to: destinationPath, content: content});
|
includedFiles.push({to: destinationPath, content: content});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of all files that are to be included.
|
* Get a list of all files that are to be included.
|
||||||
*
|
*
|
||||||
* @returns {Array} A list of all file mappings: {from:, to:}
|
* @returns {Array} A list of all file mappings: {from:, to:}
|
||||||
*/
|
*/
|
||||||
function getIncludedFiles () {
|
function getIncludedFiles () {
|
||||||
return includedFiles;
|
return includedFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of all file paths that should be excluded.
|
* Get a list of all file paths that should be excluded.
|
||||||
*
|
*
|
||||||
* @returns {Array} A list of file paths.
|
* @returns {Array} A list of file paths.
|
||||||
*/
|
*/
|
||||||
function getExcludedFiles () {
|
function getExcludedFiles () {
|
||||||
return excludedFiles;
|
return excludedFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of all file paths that should be ignored.
|
* Get a list of all file paths that should be ignored.
|
||||||
*
|
*
|
||||||
* @returns {Array} A list of file paths.
|
* @returns {Array} A list of file paths.
|
||||||
*/
|
*/
|
||||||
function getIgnoredFiles () {
|
function getIgnoredFiles () {
|
||||||
return ignoredFiles;
|
return ignoredFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear the current configuration.
|
* Clear the current configuration.
|
||||||
*
|
*
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function clearAll () {
|
function clearAll () {
|
||||||
includedFiles = [];
|
includedFiles = [];
|
||||||
excludedFiles = [];
|
excludedFiles = [];
|
||||||
ignoredFiles = [];
|
ignoredFiles = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
addFile: addFile,
|
addFile: addFile,
|
||||||
writeFile: writeFile,
|
writeFile: writeFile,
|
||||||
removeFile: removeFile,
|
removeFile: removeFile,
|
||||||
ignoreFile: ignoreFile,
|
ignoreFile: ignoreFile,
|
||||||
getIncludedFiles: getIncludedFiles,
|
getIncludedFiles: getIncludedFiles,
|
||||||
getIgnoredFiles: getIgnoredFiles,
|
getIgnoredFiles: getIgnoredFiles,
|
||||||
getExcludedFiles: getExcludedFiles,
|
getExcludedFiles: getExcludedFiles,
|
||||||
clear: clearAll
|
clear: clearAll
|
||||||
};
|
};
|
||||||
})();
|
|
||||||
|
|
|
@ -14,100 +14,99 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
var path = require('path');
|
|
||||||
var assert = require('yeoman-assert');
|
|
||||||
var helpers = require('yeoman-test');
|
|
||||||
|
|
||||||
var generator = path.join(__dirname, '../../generators/app');
|
var path = require('path');
|
||||||
var modules = ['gerrit', 'license', 'editorconfig'];
|
var assert = require('yeoman-assert');
|
||||||
var projectBuilder = require('../../generators/app/lib/project_builder');
|
var helpers = require('yeoman-test');
|
||||||
|
|
||||||
describe('generator-openstack:app', function () {
|
var generator = path.join(__dirname, '../../generators/app');
|
||||||
|
var modules = ['gerrit', 'license', 'editorconfig'];
|
||||||
|
var projectBuilder = require('../../generators/app/lib/project_builder');
|
||||||
|
|
||||||
beforeEach(function () {
|
describe('generator-openstack:app', function () {
|
||||||
projectBuilder.clear();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call all module lifecycle prompts',
|
beforeEach(function () {
|
||||||
function (done) {
|
projectBuilder.clear();
|
||||||
var spies = [];
|
|
||||||
modules.forEach(function (name) {
|
|
||||||
var module = require('../../generators/app/lib/component/' + name);
|
|
||||||
spies.push(spyOn(module, 'init').and.callThrough());
|
|
||||||
spies.push(spyOn(module, 'prompt').and.callThrough());
|
|
||||||
spies.push(spyOn(module, 'configure').and.callThrough());
|
|
||||||
});
|
|
||||||
|
|
||||||
helpers.run(generator)
|
|
||||||
.withArguments(['--non-interactive'])
|
|
||||||
.on('end', function () {
|
|
||||||
spies.forEach(function (spy) {
|
|
||||||
expect(spy.calls.any()).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should force overwrite if --non-interactive is set.',
|
|
||||||
function (done) {
|
|
||||||
helpers.run(generator)
|
|
||||||
.withArguments(['--non-interactive'])
|
|
||||||
.on('ready', function (generator) {
|
|
||||||
expect(generator.conflicter.force).toBeTruthy();
|
|
||||||
})
|
|
||||||
.on('end', function () {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('writing()', function () {
|
|
||||||
it('should create all files created in the project builder',
|
|
||||||
function (done) {
|
|
||||||
helpers.run(generator)
|
|
||||||
.withArguments(['--non-interactive'])
|
|
||||||
.on('end', function () {
|
|
||||||
assert.file(['package.json']);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should write any files provided to the content builder',
|
|
||||||
function (done) {
|
|
||||||
projectBuilder.writeFile('test.json', function () {
|
|
||||||
return 'foo';
|
|
||||||
});
|
|
||||||
projectBuilder.writeFile('test_null.json', function () {
|
|
||||||
// do nothing.
|
|
||||||
});
|
|
||||||
projectBuilder.writeFile('test_empty.json', function () {
|
|
||||||
return '';
|
|
||||||
});
|
|
||||||
projectBuilder.writeFile('test_static.json', 'static_content');
|
|
||||||
projectBuilder.writeFile('test_undefined.json');
|
|
||||||
|
|
||||||
helpers.run(generator)
|
|
||||||
.withArguments(['--non-interactive'])
|
|
||||||
.on('end', function () {
|
|
||||||
assert.file(['test.json', 'test_static.json', 'test_empty.json', 'test_null.json',
|
|
||||||
'test_undefined.json']);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should delete all files flagged in the project builder',
|
|
||||||
function (done) {
|
|
||||||
projectBuilder.removeFile('test.json');
|
|
||||||
|
|
||||||
helpers.run(generator)
|
|
||||||
.withArguments(['--non-interactive'])
|
|
||||||
.on('end', function () {
|
|
||||||
assert.noFile(['test.json']);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
})();
|
|
||||||
|
it('should call all module lifecycle prompts',
|
||||||
|
function (done) {
|
||||||
|
var spies = [];
|
||||||
|
modules.forEach(function (name) {
|
||||||
|
var module = require('../../generators/app/lib/component/' + name);
|
||||||
|
spies.push(spyOn(module, 'init').and.callThrough());
|
||||||
|
spies.push(spyOn(module, 'prompt').and.callThrough());
|
||||||
|
spies.push(spyOn(module, 'configure').and.callThrough());
|
||||||
|
});
|
||||||
|
|
||||||
|
helpers.run(generator)
|
||||||
|
.withArguments(['--non-interactive'])
|
||||||
|
.on('end', function () {
|
||||||
|
spies.forEach(function (spy) {
|
||||||
|
expect(spy.calls.any()).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should force overwrite if --non-interactive is set.',
|
||||||
|
function (done) {
|
||||||
|
helpers.run(generator)
|
||||||
|
.withArguments(['--non-interactive'])
|
||||||
|
.on('ready', function (generator) {
|
||||||
|
expect(generator.conflicter.force).toBeTruthy();
|
||||||
|
})
|
||||||
|
.on('end', function () {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('writing()', function () {
|
||||||
|
it('should create all files created in the project builder',
|
||||||
|
function (done) {
|
||||||
|
helpers.run(generator)
|
||||||
|
.withArguments(['--non-interactive'])
|
||||||
|
.on('end', function () {
|
||||||
|
assert.file(['package.json']);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write any files provided to the content builder',
|
||||||
|
function (done) {
|
||||||
|
projectBuilder.writeFile('test.json', function () {
|
||||||
|
return 'foo';
|
||||||
|
});
|
||||||
|
projectBuilder.writeFile('test_null.json', function () {
|
||||||
|
// do nothing.
|
||||||
|
});
|
||||||
|
projectBuilder.writeFile('test_empty.json', function () {
|
||||||
|
return '';
|
||||||
|
});
|
||||||
|
projectBuilder.writeFile('test_static.json', 'static_content');
|
||||||
|
projectBuilder.writeFile('test_undefined.json');
|
||||||
|
|
||||||
|
helpers.run(generator)
|
||||||
|
.withArguments(['--non-interactive'])
|
||||||
|
.on('end', function () {
|
||||||
|
assert.file(['test.json', 'test_static.json', 'test_empty.json', 'test_null.json',
|
||||||
|
'test_undefined.json']);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should delete all files flagged in the project builder',
|
||||||
|
function (done) {
|
||||||
|
projectBuilder.removeFile('test.json');
|
||||||
|
|
||||||
|
helpers.run(generator)
|
||||||
|
.withArguments(['--non-interactive'])
|
||||||
|
.on('end', function () {
|
||||||
|
assert.noFile(['test.json']);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -14,75 +14,74 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
var libDir = '../../../../generators/app/lib';
|
|
||||||
|
|
||||||
var editorconfig = require(libDir + '/component/editorconfig');
|
var libDir = '../../../../generators/app/lib';
|
||||||
var projectBuilder = require(libDir + '/project_builder');
|
|
||||||
var mocks = require('../../../helpers/mocks');
|
|
||||||
var mockGenerator;
|
|
||||||
|
|
||||||
describe('generator-openstack:lib/component/editorconfig', function () {
|
var editorconfig = require(libDir + '/component/editorconfig');
|
||||||
|
var projectBuilder = require(libDir + '/project_builder');
|
||||||
|
var mocks = require('../../../helpers/mocks');
|
||||||
|
var mockGenerator;
|
||||||
|
|
||||||
beforeEach(function () {
|
describe('generator-openstack:lib/component/editorconfig', function () {
|
||||||
mockGenerator = mocks.buildGenerator();
|
|
||||||
projectBuilder.clear();
|
beforeEach(function () {
|
||||||
|
mockGenerator = mocks.buildGenerator();
|
||||||
|
projectBuilder.clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should define init, prompt, and configure',
|
||||||
|
function () {
|
||||||
|
expect(typeof editorconfig.init).toBe('function');
|
||||||
|
expect(typeof editorconfig.prompt).toBe('function');
|
||||||
|
expect(typeof editorconfig.configure).toBe('function');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should define init, prompt, and configure',
|
describe('init()', function () {
|
||||||
|
it('should return a generator',
|
||||||
function () {
|
function () {
|
||||||
expect(typeof editorconfig.init).toBe('function');
|
var outputGenerator = editorconfig.init(mockGenerator);
|
||||||
expect(typeof editorconfig.prompt).toBe('function');
|
expect(outputGenerator).toEqual(mockGenerator);
|
||||||
expect(typeof editorconfig.configure).toBe('function');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('init()', function () {
|
it('should do nothing',
|
||||||
it('should return a generator',
|
function () {
|
||||||
function () {
|
var spy = spyOn(mockGenerator.config, 'defaults');
|
||||||
var outputGenerator = editorconfig.init(mockGenerator);
|
editorconfig.init(mockGenerator);
|
||||||
expect(outputGenerator).toEqual(mockGenerator);
|
expect(spy.calls.any()).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should do nothing',
|
|
||||||
function () {
|
|
||||||
var spy = spyOn(mockGenerator.config, 'defaults');
|
|
||||||
editorconfig.init(mockGenerator);
|
|
||||||
expect(spy.calls.any()).toBeFalsy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('prompt()', function () {
|
|
||||||
it('should return a generator',
|
|
||||||
function () {
|
|
||||||
var outputGenerator = editorconfig.prompt(mockGenerator);
|
|
||||||
expect(outputGenerator).toEqual(mockGenerator);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should do nothing',
|
|
||||||
function () {
|
|
||||||
var spy = spyOn(mockGenerator, 'prompt');
|
|
||||||
editorconfig.prompt(mockGenerator);
|
|
||||||
expect(spy.calls.any()).toBeFalsy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('configure()', function () {
|
|
||||||
it('should return a generator',
|
|
||||||
function () {
|
|
||||||
var outputGenerator = editorconfig.configure(mockGenerator);
|
|
||||||
expect(outputGenerator).toEqual(mockGenerator);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should add editorconfig to the project files.',
|
|
||||||
function () {
|
|
||||||
editorconfig.configure(mockGenerator);
|
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
|
||||||
expect(files.length).toBe(1);
|
|
||||||
expect(files[0].from).toBe('.editorconfig');
|
|
||||||
expect(files[0].to).toBe('.editorconfig');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
})();
|
|
||||||
|
describe('prompt()', function () {
|
||||||
|
it('should return a generator',
|
||||||
|
function () {
|
||||||
|
var outputGenerator = editorconfig.prompt(mockGenerator);
|
||||||
|
expect(outputGenerator).toEqual(mockGenerator);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should do nothing',
|
||||||
|
function () {
|
||||||
|
var spy = spyOn(mockGenerator, 'prompt');
|
||||||
|
editorconfig.prompt(mockGenerator);
|
||||||
|
expect(spy.calls.any()).toBeFalsy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('configure()', function () {
|
||||||
|
it('should return a generator',
|
||||||
|
function () {
|
||||||
|
var outputGenerator = editorconfig.configure(mockGenerator);
|
||||||
|
expect(outputGenerator).toEqual(mockGenerator);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add editorconfig to the project files.',
|
||||||
|
function () {
|
||||||
|
editorconfig.configure(mockGenerator);
|
||||||
|
|
||||||
|
var files = projectBuilder.getIncludedFiles();
|
||||||
|
expect(files.length).toBe(1);
|
||||||
|
expect(files[0].from).toBe('.editorconfig');
|
||||||
|
expect(files[0].to).toBe('.editorconfig');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -14,251 +14,250 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
var libDir = '../../../../generators/app/lib';
|
|
||||||
var mockGenerator;
|
|
||||||
var mockEslintIgnore = ['node_modules', 'bower_components', 'dist'];
|
|
||||||
|
|
||||||
var eslint = require(libDir + '/component/eslint');
|
var libDir = '../../../../generators/app/lib';
|
||||||
var pkgBuilder = require(libDir + '/pkg_builder');
|
var mockGenerator;
|
||||||
var projectBuilder = require(libDir + '/project_builder');
|
var mockEslintIgnore = ['node_modules', 'bower_components', 'dist'];
|
||||||
var mocks = require('../../../helpers/mocks');
|
|
||||||
var yaml = require('js-yaml');
|
|
||||||
|
|
||||||
describe('generator-openstack:lib/component/eslint', function () {
|
var eslint = require(libDir + '/component/eslint');
|
||||||
|
var pkgBuilder = require(libDir + '/pkg_builder');
|
||||||
|
var projectBuilder = require(libDir + '/project_builder');
|
||||||
|
var mocks = require('../../../helpers/mocks');
|
||||||
|
var yaml = require('js-yaml');
|
||||||
|
|
||||||
beforeEach(function () {
|
describe('generator-openstack:lib/component/eslint', function () {
|
||||||
mockGenerator = mocks.buildGenerator();
|
|
||||||
mockGenerator.fs.write('.eslintignore', mockEslintIgnore.join('\n'));
|
beforeEach(function () {
|
||||||
projectBuilder.clear();
|
mockGenerator = mocks.buildGenerator();
|
||||||
|
mockGenerator.fs.write('.eslintignore', mockEslintIgnore.join('\n'));
|
||||||
|
projectBuilder.clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should define init, prompt, and configure',
|
||||||
|
function () {
|
||||||
|
expect(typeof eslint.init).toBe('function');
|
||||||
|
expect(typeof eslint.prompt).toBe('function');
|
||||||
|
expect(typeof eslint.configure).toBe('function');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should define init, prompt, and configure',
|
describe('init()', function () {
|
||||||
|
it('should return a generator',
|
||||||
function () {
|
function () {
|
||||||
expect(typeof eslint.init).toBe('function');
|
var outputGenerator = eslint.init(mockGenerator);
|
||||||
expect(typeof eslint.prompt).toBe('function');
|
expect(outputGenerator).toEqual(mockGenerator);
|
||||||
expect(typeof eslint.configure).toBe('function');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('init()', function () {
|
it('should not interact with config',
|
||||||
it('should return a generator',
|
function () {
|
||||||
function () {
|
var spy = spyOn(mockGenerator.config, 'defaults');
|
||||||
var outputGenerator = eslint.init(mockGenerator);
|
eslint.init(mockGenerator);
|
||||||
expect(outputGenerator).toEqual(mockGenerator);
|
expect(spy.calls.any()).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should not interact with config',
|
describe('prompt()', function () {
|
||||||
function () {
|
it('should return a generator',
|
||||||
var spy = spyOn(mockGenerator.config, 'defaults');
|
function () {
|
||||||
eslint.init(mockGenerator);
|
var outputGenerator = eslint.prompt(mockGenerator);
|
||||||
expect(spy.calls.any()).toBeFalsy();
|
expect(outputGenerator).toEqual(mockGenerator);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('prompt()', function () {
|
it('should add eslint and eslint-config-openstack to the project',
|
||||||
it('should return a generator',
|
function () {
|
||||||
function () {
|
pkgBuilder.fromJSON('{"devDependencies":{}}');
|
||||||
var outputGenerator = eslint.prompt(mockGenerator);
|
|
||||||
expect(outputGenerator).toEqual(mockGenerator);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should add eslint and eslint-config-openstack to the project',
|
var devDeps = pkgBuilder.getValue('devDependencies');
|
||||||
function () {
|
expect(devDeps.eslint).not.toBeDefined();
|
||||||
pkgBuilder.fromJSON('{"devDependencies":{}}');
|
expect(devDeps['eslint-config-openstack']).not.toBeDefined();
|
||||||
|
|
||||||
var devDeps = pkgBuilder.getValue('devDependencies');
|
eslint.prompt(mockGenerator);
|
||||||
expect(devDeps.eslint).not.toBeDefined();
|
|
||||||
expect(devDeps['eslint-config-openstack']).not.toBeDefined();
|
|
||||||
|
|
||||||
eslint.prompt(mockGenerator);
|
devDeps = pkgBuilder.getValue('devDependencies');
|
||||||
|
expect(devDeps.eslint).toBeDefined();
|
||||||
|
expect(devDeps['eslint-config-openstack']).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
devDeps = pkgBuilder.getValue('devDependencies');
|
it('should add the lint command to the project',
|
||||||
expect(devDeps.eslint).toBeDefined();
|
function () {
|
||||||
expect(devDeps['eslint-config-openstack']).toBeDefined();
|
pkgBuilder.fromJSON('{}');
|
||||||
});
|
|
||||||
|
|
||||||
it('should add the lint command to the project',
|
var scripts = pkgBuilder.getValue('scripts');
|
||||||
function () {
|
expect(scripts).not.toBeDefined();
|
||||||
pkgBuilder.fromJSON('{}');
|
|
||||||
|
|
||||||
var scripts = pkgBuilder.getValue('scripts');
|
eslint.prompt(mockGenerator);
|
||||||
expect(scripts).not.toBeDefined();
|
|
||||||
|
|
||||||
eslint.prompt(mockGenerator);
|
var newScripts = pkgBuilder.getValue('scripts');
|
||||||
|
expect(newScripts.lint).toBeDefined();
|
||||||
|
expect(newScripts.lint).toEqual('eslint ./');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
var newScripts = pkgBuilder.getValue('scripts');
|
describe('configure()', function () {
|
||||||
expect(newScripts.lint).toBeDefined();
|
it('should return a generator',
|
||||||
expect(newScripts.lint).toEqual('eslint ./');
|
function () {
|
||||||
});
|
var outputGenerator = eslint.configure(mockGenerator);
|
||||||
});
|
expect(outputGenerator).toEqual(mockGenerator);
|
||||||
|
});
|
||||||
|
|
||||||
describe('configure()', function () {
|
it('should add .eslintrc and .eslintignore to the project files.',
|
||||||
it('should return a generator',
|
function () {
|
||||||
function () {
|
eslint.configure(mockGenerator);
|
||||||
var outputGenerator = eslint.configure(mockGenerator);
|
|
||||||
expect(outputGenerator).toEqual(mockGenerator);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should add .eslintrc and .eslintignore to the project files.',
|
var files = projectBuilder.getIncludedFiles();
|
||||||
function () {
|
expect(files.length).toBe(2);
|
||||||
eslint.configure(mockGenerator);
|
expect(files[0].to).toBe('.eslintignore');
|
||||||
|
expect(files[1].to).toBe('.eslintrc');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
describe('.eslintrc management', function () {
|
||||||
expect(files.length).toBe(2);
|
var mockEslintRc = {
|
||||||
expect(files[0].to).toBe('.eslintignore');
|
extends: 'openstack',
|
||||||
expect(files[1].to).toBe('.eslintrc');
|
plugins: ['angular']
|
||||||
});
|
};
|
||||||
});
|
|
||||||
|
|
||||||
describe('.eslintrc management', function () {
|
it('should write a .eslintrc file as valid .yaml',
|
||||||
var mockEslintRc = {
|
function () {
|
||||||
extends: 'openstack',
|
eslint.init(mockGenerator);
|
||||||
plugins: ['angular']
|
eslint.configure(mockGenerator);
|
||||||
};
|
|
||||||
|
|
||||||
it('should write a .eslintrc file as valid .yaml',
|
var files = projectBuilder.getIncludedFiles();
|
||||||
function () {
|
var eslintRcRef = files[1];
|
||||||
eslint.init(mockGenerator);
|
expect(eslintRcRef.to).toBe('.eslintrc');
|
||||||
eslint.configure(mockGenerator);
|
expect(yaml.safeLoad(eslintRcRef.content()))
|
||||||
|
.toEqual({extends: 'openstack'});
|
||||||
|
});
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
it('should echo back existing .eslintrc',
|
||||||
var eslintRcRef = files[1];
|
function () {
|
||||||
expect(eslintRcRef.to).toBe('.eslintrc');
|
var yamlContent = yaml.safeDump(mockEslintRc);
|
||||||
expect(yaml.safeLoad(eslintRcRef.content()))
|
mockGenerator.fs.write('.eslintrc', yamlContent);
|
||||||
.toEqual({extends: 'openstack'});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should echo back existing .eslintrc',
|
eslint.init(mockGenerator);
|
||||||
function () {
|
eslint.configure(mockGenerator);
|
||||||
var yamlContent = yaml.safeDump(mockEslintRc);
|
|
||||||
mockGenerator.fs.write('.eslintrc', yamlContent);
|
|
||||||
|
|
||||||
eslint.init(mockGenerator);
|
var files = projectBuilder.getIncludedFiles();
|
||||||
eslint.configure(mockGenerator);
|
var eslintRcRef = files[1];
|
||||||
|
var eslintContent = yaml.safeLoad(eslintRcRef.content());
|
||||||
|
expect(mockEslintRc).toEqual(eslintContent);
|
||||||
|
});
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
it('should convert a json .eslintrc to yaml',
|
||||||
var eslintRcRef = files[1];
|
function () {
|
||||||
var eslintContent = yaml.safeLoad(eslintRcRef.content());
|
mockGenerator.fs.write('.eslintrc', JSON.stringify(mockEslintRc));
|
||||||
expect(mockEslintRc).toEqual(eslintContent);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should convert a json .eslintrc to yaml',
|
eslint.init(mockGenerator);
|
||||||
function () {
|
eslint.configure(mockGenerator);
|
||||||
mockGenerator.fs.write('.eslintrc', JSON.stringify(mockEslintRc));
|
|
||||||
|
|
||||||
eslint.init(mockGenerator);
|
var files = projectBuilder.getIncludedFiles();
|
||||||
eslint.configure(mockGenerator);
|
var eslintRcRef = files[1];
|
||||||
|
var eslintContent = yaml.safeLoad(eslintRcRef.content());
|
||||||
|
expect(mockEslintRc).toEqual(eslintContent);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
describe('.eslintignore management', function () {
|
||||||
var eslintRcRef = files[1];
|
|
||||||
var eslintContent = yaml.safeLoad(eslintRcRef.content());
|
|
||||||
expect(mockEslintRc).toEqual(eslintContent);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.eslintignore management', function () {
|
it('should echo back existing .eslintignore',
|
||||||
|
function () {
|
||||||
it('should echo back existing .eslintignore',
|
mockGenerator.fs.write('.eslintignore', mockEslintIgnore.join('\n'));
|
||||||
function () {
|
|
||||||
mockGenerator.fs.write('.eslintignore', mockEslintIgnore.join('\n'));
|
|
||||||
|
|
||||||
eslint.init(mockGenerator);
|
|
||||||
eslint.prompt(mockGenerator);
|
|
||||||
eslint.configure(mockGenerator);
|
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
|
||||||
var ignoreRef = files[0];
|
|
||||||
var ignoreContent = ignoreRef.content().split('\n');
|
|
||||||
expect(ignoreContent.length).toBe(mockEslintIgnore.length);
|
|
||||||
|
|
||||||
ignoreContent.forEach(function (item) {
|
|
||||||
expect(mockEslintIgnore.indexOf(item)).not.toBe(-1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should include any files flagged as ignored in the project builder.',
|
|
||||||
function () {
|
|
||||||
mockGenerator.fs.write('.eslintignore', '');
|
|
||||||
projectBuilder.ignoreFile('foo/bar.json');
|
|
||||||
|
|
||||||
eslint.init(mockGenerator);
|
|
||||||
eslint.prompt(mockGenerator);
|
|
||||||
eslint.configure(mockGenerator);
|
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
|
||||||
var ignoreRef = files[0]; // There should only be one file.
|
|
||||||
var ignoreContent = ignoreRef.content().split('\n');
|
|
||||||
expect(ignoreContent.length).toBe(1);
|
|
||||||
|
|
||||||
expect(ignoreContent[0]).toBe('foo/bar.json');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should de-duplicate file paths from multiple locations.',
|
|
||||||
function () {
|
|
||||||
// include 'node_modules' from both an existing file and from the project builder.
|
|
||||||
mockGenerator.fs.write('.eslintignore', ['node_modules'].join('\n'));
|
|
||||||
projectBuilder.ignoreFile('node_modules');
|
|
||||||
|
|
||||||
eslint.init(mockGenerator);
|
|
||||||
eslint.prompt(mockGenerator);
|
|
||||||
eslint.configure(mockGenerator);
|
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
|
||||||
var ignoreRef = files[0]; // There should only be one file.
|
|
||||||
var ignoreContent = ignoreRef.content().split('\n');
|
|
||||||
expect(ignoreContent.length).toBe(1);
|
|
||||||
|
|
||||||
expect(ignoreContent[0]).toBe('node_modules');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should sort the ignored files.',
|
|
||||||
function () {
|
|
||||||
mockGenerator.fs.write('.eslintignore', mockEslintIgnore.join('\n'));
|
|
||||||
|
|
||||||
eslint.init(mockGenerator);
|
|
||||||
eslint.prompt(mockGenerator);
|
|
||||||
eslint.configure(mockGenerator);
|
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
|
||||||
var ignoreRef = files[0];
|
|
||||||
var ignoreContent = ignoreRef.content().split('\n');
|
|
||||||
expect(ignoreContent[0]).toBe('bower_components');
|
|
||||||
expect(ignoreContent[1]).toBe('dist');
|
|
||||||
expect(ignoreContent[2]).toBe('node_modules');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should remove any whitespace from the existing .eslintignore',
|
|
||||||
function () {
|
|
||||||
mockGenerator.fs.write('.eslintignore', ['1_one', '', '2_two', ''].join('\n'));
|
|
||||||
|
|
||||||
eslint.init(mockGenerator);
|
|
||||||
eslint.prompt(mockGenerator);
|
|
||||||
eslint.configure(mockGenerator);
|
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
|
||||||
var ignoreRef = files[0];
|
|
||||||
var ignoreContent = ignoreRef.content().split('\n');
|
|
||||||
expect(ignoreContent.length).toBe(2);
|
|
||||||
expect(ignoreContent[0]).toBe('1_one');
|
|
||||||
expect(ignoreContent[1]).toBe('2_two');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should delete the file if there\'s nothing to ignore', function () {
|
|
||||||
mockGenerator.fs.write('.eslintignore', '');
|
|
||||||
|
|
||||||
eslint.init(mockGenerator);
|
eslint.init(mockGenerator);
|
||||||
eslint.prompt(mockGenerator);
|
eslint.prompt(mockGenerator);
|
||||||
eslint.configure(mockGenerator);
|
eslint.configure(mockGenerator);
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
var files = projectBuilder.getIncludedFiles();
|
||||||
expect(files.length).toBe(1);
|
var ignoreRef = files[0];
|
||||||
expect(files[0].to).not.toBe('.eslintignore');
|
var ignoreContent = ignoreRef.content().split('\n');
|
||||||
|
expect(ignoreContent.length).toBe(mockEslintIgnore.length);
|
||||||
|
|
||||||
var rmFiles = projectBuilder.getExcludedFiles();
|
ignoreContent.forEach(function (item) {
|
||||||
expect(rmFiles.length).toBe(1);
|
expect(mockEslintIgnore.indexOf(item)).not.toBe(-1);
|
||||||
expect(rmFiles[0]).toBe('.eslintignore');
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should include any files flagged as ignored in the project builder.',
|
||||||
|
function () {
|
||||||
|
mockGenerator.fs.write('.eslintignore', '');
|
||||||
|
projectBuilder.ignoreFile('foo/bar.json');
|
||||||
|
|
||||||
|
eslint.init(mockGenerator);
|
||||||
|
eslint.prompt(mockGenerator);
|
||||||
|
eslint.configure(mockGenerator);
|
||||||
|
|
||||||
|
var files = projectBuilder.getIncludedFiles();
|
||||||
|
var ignoreRef = files[0]; // There should only be one file.
|
||||||
|
var ignoreContent = ignoreRef.content().split('\n');
|
||||||
|
expect(ignoreContent.length).toBe(1);
|
||||||
|
|
||||||
|
expect(ignoreContent[0]).toBe('foo/bar.json');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should de-duplicate file paths from multiple locations.',
|
||||||
|
function () {
|
||||||
|
// include 'node_modules' from both an existing file and from the project builder.
|
||||||
|
mockGenerator.fs.write('.eslintignore', ['node_modules'].join('\n'));
|
||||||
|
projectBuilder.ignoreFile('node_modules');
|
||||||
|
|
||||||
|
eslint.init(mockGenerator);
|
||||||
|
eslint.prompt(mockGenerator);
|
||||||
|
eslint.configure(mockGenerator);
|
||||||
|
|
||||||
|
var files = projectBuilder.getIncludedFiles();
|
||||||
|
var ignoreRef = files[0]; // There should only be one file.
|
||||||
|
var ignoreContent = ignoreRef.content().split('\n');
|
||||||
|
expect(ignoreContent.length).toBe(1);
|
||||||
|
|
||||||
|
expect(ignoreContent[0]).toBe('node_modules');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should sort the ignored files.',
|
||||||
|
function () {
|
||||||
|
mockGenerator.fs.write('.eslintignore', mockEslintIgnore.join('\n'));
|
||||||
|
|
||||||
|
eslint.init(mockGenerator);
|
||||||
|
eslint.prompt(mockGenerator);
|
||||||
|
eslint.configure(mockGenerator);
|
||||||
|
|
||||||
|
var files = projectBuilder.getIncludedFiles();
|
||||||
|
var ignoreRef = files[0];
|
||||||
|
var ignoreContent = ignoreRef.content().split('\n');
|
||||||
|
expect(ignoreContent[0]).toBe('bower_components');
|
||||||
|
expect(ignoreContent[1]).toBe('dist');
|
||||||
|
expect(ignoreContent[2]).toBe('node_modules');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove any whitespace from the existing .eslintignore',
|
||||||
|
function () {
|
||||||
|
mockGenerator.fs.write('.eslintignore', ['1_one', '', '2_two', ''].join('\n'));
|
||||||
|
|
||||||
|
eslint.init(mockGenerator);
|
||||||
|
eslint.prompt(mockGenerator);
|
||||||
|
eslint.configure(mockGenerator);
|
||||||
|
|
||||||
|
var files = projectBuilder.getIncludedFiles();
|
||||||
|
var ignoreRef = files[0];
|
||||||
|
var ignoreContent = ignoreRef.content().split('\n');
|
||||||
|
expect(ignoreContent.length).toBe(2);
|
||||||
|
expect(ignoreContent[0]).toBe('1_one');
|
||||||
|
expect(ignoreContent[1]).toBe('2_two');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should delete the file if there\'s nothing to ignore', function () {
|
||||||
|
mockGenerator.fs.write('.eslintignore', '');
|
||||||
|
|
||||||
|
eslint.init(mockGenerator);
|
||||||
|
eslint.prompt(mockGenerator);
|
||||||
|
eslint.configure(mockGenerator);
|
||||||
|
|
||||||
|
var files = projectBuilder.getIncludedFiles();
|
||||||
|
expect(files.length).toBe(1);
|
||||||
|
expect(files[0].to).not.toBe('.eslintignore');
|
||||||
|
|
||||||
|
var rmFiles = projectBuilder.getExcludedFiles();
|
||||||
|
expect(rmFiles.length).toBe(1);
|
||||||
|
expect(rmFiles[0]).toBe('.eslintignore');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})();
|
});
|
||||||
|
|
|
@ -14,260 +14,259 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
var libDir = '../../../../generators/app/lib';
|
|
||||||
|
|
||||||
var ini = require('ini');
|
var libDir = '../../../../generators/app/lib';
|
||||||
|
|
||||||
var gerrit = require(libDir + '/component/gerrit');
|
var ini = require('ini');
|
||||||
var projectBuilder = require(libDir + '/project_builder');
|
|
||||||
var pkgBuilder = require(libDir + '/pkg_builder');
|
|
||||||
var mocks = require('../../../helpers/mocks');
|
|
||||||
|
|
||||||
var iniFile = {
|
var gerrit = require(libDir + '/component/gerrit');
|
||||||
gerrit: {
|
var projectBuilder = require(libDir + '/project_builder');
|
||||||
host: 'review.example.org',
|
var pkgBuilder = require(libDir + '/pkg_builder');
|
||||||
port: '1000',
|
var mocks = require('../../../helpers/mocks');
|
||||||
project: 'openstack/test-project.git'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
var iniFile = {
|
||||||
* Assert that the gerrit file content matches the passed structure.
|
gerrit: {
|
||||||
*
|
host: 'review.example.org',
|
||||||
* @param {object} content The expected data structure.
|
port: '1000',
|
||||||
* @returns {void}
|
project: 'openstack/test-project.git'
|
||||||
*/
|
|
||||||
function expectGerritFileContent (content) {
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
|
||||||
|
|
||||||
// get the .gitreview file
|
|
||||||
var gitreview = null;
|
|
||||||
files.forEach(function (fileRef) {
|
|
||||||
if (fileRef.to === '.gitreview') {
|
|
||||||
gitreview = ini.parse(fileRef.content());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Test the content
|
|
||||||
expect(gitreview).toBeTruthy();
|
|
||||||
expect(gitreview).toEqual(content);
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
describe('generator-openstack:lib/component/gerrit', function () {
|
/**
|
||||||
|
* Assert that the gerrit file content matches the passed structure.
|
||||||
|
*
|
||||||
|
* @param {object} content The expected data structure.
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
function expectGerritFileContent (content) {
|
||||||
|
var files = projectBuilder.getIncludedFiles();
|
||||||
|
|
||||||
beforeEach(function () {
|
// get the .gitreview file
|
||||||
projectBuilder.clear();
|
var gitreview = null;
|
||||||
});
|
files.forEach(function (fileRef) {
|
||||||
|
if (fileRef.to === '.gitreview') {
|
||||||
afterEach(function () {
|
gitreview = ini.parse(fileRef.content());
|
||||||
pkgBuilder.fromJSON(JSON.stringify({}));
|
}
|
||||||
});
|
|
||||||
|
|
||||||
describe('api', function () {
|
|
||||||
it('should define init, prompt, and configure',
|
|
||||||
function () {
|
|
||||||
expect(typeof gerrit.init).toBe('function');
|
|
||||||
expect(typeof gerrit.prompt).toBe('function');
|
|
||||||
expect(typeof gerrit.configure).toBe('function');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('runtime', function () {
|
|
||||||
it('should not create a new file if one does not exist already.',
|
|
||||||
function () {
|
|
||||||
// No answers, non-interactive run.
|
|
||||||
var mockAnswers = {};
|
|
||||||
var generator = mocks.buildGenerator(null, mockAnswers);
|
|
||||||
generator.fs.delete('.gitreview');
|
|
||||||
|
|
||||||
gerrit.init(generator);
|
|
||||||
gerrit.prompt(generator);
|
|
||||||
gerrit.configure(generator);
|
|
||||||
|
|
||||||
expect(generator.fs.exists('.gitreview')).toBeFalsy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not delete a file if one exists.',
|
|
||||||
function () {
|
|
||||||
// No answers, non-interactive run.
|
|
||||||
var mockAnswers = {};
|
|
||||||
var generator = mocks.buildGenerator(null, mockAnswers);
|
|
||||||
generator.fs.write('.gitreview', ini.stringify(iniFile));
|
|
||||||
|
|
||||||
// Set defaults
|
|
||||||
gerrit.init(generator);
|
|
||||||
gerrit.prompt(generator);
|
|
||||||
gerrit.configure(generator);
|
|
||||||
|
|
||||||
expect(generator.fs.exists('.gitreview')).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should write default values if a new file is requested.',
|
|
||||||
function () {
|
|
||||||
// No answers, non-interactive run.
|
|
||||||
var mockAnswers = {enableGerrit: true};
|
|
||||||
var generator = mocks.buildGenerator(null, mockAnswers);
|
|
||||||
pkgBuilder.fromJSON(JSON.stringify({name: 'generator-openstack'}));
|
|
||||||
|
|
||||||
generator.fs.delete('.gitreview');
|
|
||||||
|
|
||||||
// Set defaults
|
|
||||||
gerrit.init(generator);
|
|
||||||
gerrit.prompt(generator);
|
|
||||||
gerrit.configure(generator);
|
|
||||||
|
|
||||||
expectGerritFileContent({
|
|
||||||
gerrit: {
|
|
||||||
host: 'review.openstack.org',
|
|
||||||
port: '29418',
|
|
||||||
project: 'openstack/generator-openstack.git'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should read the default project name from the package builder.',
|
|
||||||
function () {
|
|
||||||
// No answers, non-interactive run.
|
|
||||||
var mockAnswers = {enableGerrit: true};
|
|
||||||
pkgBuilder.fromJSON(JSON.stringify({name: 'foo'}));
|
|
||||||
|
|
||||||
var generator = mocks.buildGenerator(null, mockAnswers);
|
|
||||||
generator.fs.delete('.gitreview');
|
|
||||||
|
|
||||||
// Set defaults
|
|
||||||
gerrit.init(generator);
|
|
||||||
gerrit.prompt(generator);
|
|
||||||
gerrit.configure(generator);
|
|
||||||
|
|
||||||
expectGerritFileContent({
|
|
||||||
gerrit: {
|
|
||||||
host: 'review.openstack.org',
|
|
||||||
port: '29418',
|
|
||||||
project: 'openstack/foo.git'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('init()', function () {
|
|
||||||
it('should return a generator',
|
|
||||||
function () {
|
|
||||||
var generator = mocks.buildGenerator();
|
|
||||||
var outputGenerator = gerrit.init(generator);
|
|
||||||
expect(outputGenerator).toEqual(generator);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('prompt()', function () {
|
|
||||||
it('should return a promise that resolves with a generator',
|
|
||||||
function () {
|
|
||||||
var generator = mocks.buildGenerator();
|
|
||||||
var outputPromise = gerrit.prompt(generator);
|
|
||||||
outputPromise.then(function (outputGenerator) {
|
|
||||||
expect(outputGenerator).toEqual(generator);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not show a prompt if non-interactive is set',
|
|
||||||
function () {
|
|
||||||
var generator = mocks.buildGenerator(null, null,
|
|
||||||
{'non-interactive': true});
|
|
||||||
var promptSpy = spyOn(generator, 'prompt');
|
|
||||||
|
|
||||||
generator.fs.write('.gitreview', ini.stringify(iniFile));
|
|
||||||
|
|
||||||
gerrit.init(generator);
|
|
||||||
gerrit.prompt(generator);
|
|
||||||
|
|
||||||
expect(promptSpy.calls.any()).toBeFalsy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should use defaults in .gitreview if no answers provided',
|
|
||||||
function () {
|
|
||||||
var generator = mocks.buildGenerator();
|
|
||||||
|
|
||||||
generator.fs.write('.gitreview', ini.stringify(iniFile));
|
|
||||||
gerrit.init(generator);
|
|
||||||
gerrit.prompt(generator);
|
|
||||||
gerrit.configure(generator);
|
|
||||||
expectGerritFileContent(iniFile);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should configure answers if answers provided',
|
|
||||||
function () {
|
|
||||||
var config = {};
|
|
||||||
var mockAnswers = {
|
|
||||||
enableGerrit: true,
|
|
||||||
gerritHost: 'review.example.org',
|
|
||||||
gerritPort: '1000',
|
|
||||||
gerritProject: 'openstack/test.git'
|
|
||||||
};
|
|
||||||
var generator = mocks.buildGenerator(config, mockAnswers);
|
|
||||||
|
|
||||||
// Set defaults
|
|
||||||
gerrit.init(generator);
|
|
||||||
gerrit.prompt(generator);
|
|
||||||
gerrit.configure(generator);
|
|
||||||
|
|
||||||
expectGerritFileContent({
|
|
||||||
gerrit: {
|
|
||||||
host: mockAnswers.gerritHost,
|
|
||||||
port: mockAnswers.gerritPort,
|
|
||||||
project: mockAnswers.gerritProject
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('configure()', function () {
|
|
||||||
it('should return a generator',
|
|
||||||
function () {
|
|
||||||
var generator = mocks.buildGenerator();
|
|
||||||
var outputGenerator = gerrit.init(generator);
|
|
||||||
expect(outputGenerator).toEqual(generator);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create a .gitreview file if enabled',
|
|
||||||
function () {
|
|
||||||
var generator = mocks.buildGenerator(null, {enableGerrit: true});
|
|
||||||
pkgBuilder.fromJSON(JSON.stringify({name: 'generator-openstack'}));
|
|
||||||
|
|
||||||
// Make sure we don't have something left over from another test.
|
|
||||||
generator.fs.delete('.gitreview');
|
|
||||||
|
|
||||||
gerrit.init(generator);
|
|
||||||
gerrit.prompt(generator);
|
|
||||||
gerrit.configure(generator);
|
|
||||||
|
|
||||||
expectGerritFileContent({
|
|
||||||
gerrit: {
|
|
||||||
host: 'review.openstack.org',
|
|
||||||
port: '29418',
|
|
||||||
project: 'openstack/generator-openstack.git'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var excludedFiles = projectBuilder.getExcludedFiles();
|
|
||||||
expect(excludedFiles.length).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should delete a .gitreview file if disabled',
|
|
||||||
function () {
|
|
||||||
var generator = mocks.buildGenerator(null, {enableGerrit: false});
|
|
||||||
|
|
||||||
gerrit.init(generator);
|
|
||||||
gerrit.prompt(generator);
|
|
||||||
gerrit.configure(generator);
|
|
||||||
|
|
||||||
var includedFiles = projectBuilder.getIncludedFiles();
|
|
||||||
expect(includedFiles.length).toBe(0);
|
|
||||||
|
|
||||||
var excludedFiles = projectBuilder.getExcludedFiles();
|
|
||||||
expect(excludedFiles.length).toBe(1);
|
|
||||||
expect(excludedFiles[0]).toBe('.gitreview');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
})();
|
|
||||||
|
// Test the content
|
||||||
|
expect(gitreview).toBeTruthy();
|
||||||
|
expect(gitreview).toEqual(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('generator-openstack:lib/component/gerrit', function () {
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
projectBuilder.clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
pkgBuilder.fromJSON(JSON.stringify({}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('api', function () {
|
||||||
|
it('should define init, prompt, and configure',
|
||||||
|
function () {
|
||||||
|
expect(typeof gerrit.init).toBe('function');
|
||||||
|
expect(typeof gerrit.prompt).toBe('function');
|
||||||
|
expect(typeof gerrit.configure).toBe('function');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('runtime', function () {
|
||||||
|
it('should not create a new file if one does not exist already.',
|
||||||
|
function () {
|
||||||
|
// No answers, non-interactive run.
|
||||||
|
var mockAnswers = {};
|
||||||
|
var generator = mocks.buildGenerator(null, mockAnswers);
|
||||||
|
generator.fs.delete('.gitreview');
|
||||||
|
|
||||||
|
gerrit.init(generator);
|
||||||
|
gerrit.prompt(generator);
|
||||||
|
gerrit.configure(generator);
|
||||||
|
|
||||||
|
expect(generator.fs.exists('.gitreview')).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not delete a file if one exists.',
|
||||||
|
function () {
|
||||||
|
// No answers, non-interactive run.
|
||||||
|
var mockAnswers = {};
|
||||||
|
var generator = mocks.buildGenerator(null, mockAnswers);
|
||||||
|
generator.fs.write('.gitreview', ini.stringify(iniFile));
|
||||||
|
|
||||||
|
// Set defaults
|
||||||
|
gerrit.init(generator);
|
||||||
|
gerrit.prompt(generator);
|
||||||
|
gerrit.configure(generator);
|
||||||
|
|
||||||
|
expect(generator.fs.exists('.gitreview')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write default values if a new file is requested.',
|
||||||
|
function () {
|
||||||
|
// No answers, non-interactive run.
|
||||||
|
var mockAnswers = {enableGerrit: true};
|
||||||
|
var generator = mocks.buildGenerator(null, mockAnswers);
|
||||||
|
pkgBuilder.fromJSON(JSON.stringify({name: 'generator-openstack'}));
|
||||||
|
|
||||||
|
generator.fs.delete('.gitreview');
|
||||||
|
|
||||||
|
// Set defaults
|
||||||
|
gerrit.init(generator);
|
||||||
|
gerrit.prompt(generator);
|
||||||
|
gerrit.configure(generator);
|
||||||
|
|
||||||
|
expectGerritFileContent({
|
||||||
|
gerrit: {
|
||||||
|
host: 'review.openstack.org',
|
||||||
|
port: '29418',
|
||||||
|
project: 'openstack/generator-openstack.git'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read the default project name from the package builder.',
|
||||||
|
function () {
|
||||||
|
// No answers, non-interactive run.
|
||||||
|
var mockAnswers = {enableGerrit: true};
|
||||||
|
pkgBuilder.fromJSON(JSON.stringify({name: 'foo'}));
|
||||||
|
|
||||||
|
var generator = mocks.buildGenerator(null, mockAnswers);
|
||||||
|
generator.fs.delete('.gitreview');
|
||||||
|
|
||||||
|
// Set defaults
|
||||||
|
gerrit.init(generator);
|
||||||
|
gerrit.prompt(generator);
|
||||||
|
gerrit.configure(generator);
|
||||||
|
|
||||||
|
expectGerritFileContent({
|
||||||
|
gerrit: {
|
||||||
|
host: 'review.openstack.org',
|
||||||
|
port: '29418',
|
||||||
|
project: 'openstack/foo.git'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('init()', function () {
|
||||||
|
it('should return a generator',
|
||||||
|
function () {
|
||||||
|
var generator = mocks.buildGenerator();
|
||||||
|
var outputGenerator = gerrit.init(generator);
|
||||||
|
expect(outputGenerator).toEqual(generator);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('prompt()', function () {
|
||||||
|
it('should return a promise that resolves with a generator',
|
||||||
|
function () {
|
||||||
|
var generator = mocks.buildGenerator();
|
||||||
|
var outputPromise = gerrit.prompt(generator);
|
||||||
|
outputPromise.then(function (outputGenerator) {
|
||||||
|
expect(outputGenerator).toEqual(generator);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not show a prompt if non-interactive is set',
|
||||||
|
function () {
|
||||||
|
var generator = mocks.buildGenerator(null, null,
|
||||||
|
{'non-interactive': true});
|
||||||
|
var promptSpy = spyOn(generator, 'prompt');
|
||||||
|
|
||||||
|
generator.fs.write('.gitreview', ini.stringify(iniFile));
|
||||||
|
|
||||||
|
gerrit.init(generator);
|
||||||
|
gerrit.prompt(generator);
|
||||||
|
|
||||||
|
expect(promptSpy.calls.any()).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use defaults in .gitreview if no answers provided',
|
||||||
|
function () {
|
||||||
|
var generator = mocks.buildGenerator();
|
||||||
|
|
||||||
|
generator.fs.write('.gitreview', ini.stringify(iniFile));
|
||||||
|
gerrit.init(generator);
|
||||||
|
gerrit.prompt(generator);
|
||||||
|
gerrit.configure(generator);
|
||||||
|
expectGerritFileContent(iniFile);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should configure answers if answers provided',
|
||||||
|
function () {
|
||||||
|
var config = {};
|
||||||
|
var mockAnswers = {
|
||||||
|
enableGerrit: true,
|
||||||
|
gerritHost: 'review.example.org',
|
||||||
|
gerritPort: '1000',
|
||||||
|
gerritProject: 'openstack/test.git'
|
||||||
|
};
|
||||||
|
var generator = mocks.buildGenerator(config, mockAnswers);
|
||||||
|
|
||||||
|
// Set defaults
|
||||||
|
gerrit.init(generator);
|
||||||
|
gerrit.prompt(generator);
|
||||||
|
gerrit.configure(generator);
|
||||||
|
|
||||||
|
expectGerritFileContent({
|
||||||
|
gerrit: {
|
||||||
|
host: mockAnswers.gerritHost,
|
||||||
|
port: mockAnswers.gerritPort,
|
||||||
|
project: mockAnswers.gerritProject
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('configure()', function () {
|
||||||
|
it('should return a generator',
|
||||||
|
function () {
|
||||||
|
var generator = mocks.buildGenerator();
|
||||||
|
var outputGenerator = gerrit.init(generator);
|
||||||
|
expect(outputGenerator).toEqual(generator);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create a .gitreview file if enabled',
|
||||||
|
function () {
|
||||||
|
var generator = mocks.buildGenerator(null, {enableGerrit: true});
|
||||||
|
pkgBuilder.fromJSON(JSON.stringify({name: 'generator-openstack'}));
|
||||||
|
|
||||||
|
// Make sure we don't have something left over from another test.
|
||||||
|
generator.fs.delete('.gitreview');
|
||||||
|
|
||||||
|
gerrit.init(generator);
|
||||||
|
gerrit.prompt(generator);
|
||||||
|
gerrit.configure(generator);
|
||||||
|
|
||||||
|
expectGerritFileContent({
|
||||||
|
gerrit: {
|
||||||
|
host: 'review.openstack.org',
|
||||||
|
port: '29418',
|
||||||
|
project: 'openstack/generator-openstack.git'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var excludedFiles = projectBuilder.getExcludedFiles();
|
||||||
|
expect(excludedFiles.length).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should delete a .gitreview file if disabled',
|
||||||
|
function () {
|
||||||
|
var generator = mocks.buildGenerator(null, {enableGerrit: false});
|
||||||
|
|
||||||
|
gerrit.init(generator);
|
||||||
|
gerrit.prompt(generator);
|
||||||
|
gerrit.configure(generator);
|
||||||
|
|
||||||
|
var includedFiles = projectBuilder.getIncludedFiles();
|
||||||
|
expect(includedFiles.length).toBe(0);
|
||||||
|
|
||||||
|
var excludedFiles = projectBuilder.getExcludedFiles();
|
||||||
|
expect(excludedFiles.length).toBe(1);
|
||||||
|
expect(excludedFiles[0]).toBe('.gitreview');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -14,210 +14,209 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
var libDir = '../../../../generators/app/lib';
|
|
||||||
|
|
||||||
var gitignore = require(libDir + '/component/gitignore');
|
var libDir = '../../../../generators/app/lib';
|
||||||
var projectBuilder = require(libDir + '/project_builder');
|
|
||||||
var mocks = require('../../../helpers/mocks');
|
|
||||||
var mockGenerator;
|
|
||||||
|
|
||||||
describe('generator-openstack:lib/component/gitignore', function () {
|
var gitignore = require(libDir + '/component/gitignore');
|
||||||
|
var projectBuilder = require(libDir + '/project_builder');
|
||||||
|
var mocks = require('../../../helpers/mocks');
|
||||||
|
var mockGenerator;
|
||||||
|
|
||||||
beforeEach(function () {
|
describe('generator-openstack:lib/component/gitignore', function () {
|
||||||
mockGenerator = mocks.buildGenerator();
|
|
||||||
projectBuilder.clear();
|
beforeEach(function () {
|
||||||
|
mockGenerator = mocks.buildGenerator();
|
||||||
|
projectBuilder.clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should define init, prompt, and configure',
|
||||||
|
function () {
|
||||||
|
expect(typeof gitignore.init).toBe('function');
|
||||||
|
expect(typeof gitignore.prompt).toBe('function');
|
||||||
|
expect(typeof gitignore.configure).toBe('function');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should define init, prompt, and configure',
|
describe('init()', function () {
|
||||||
|
it('should return a generator',
|
||||||
function () {
|
function () {
|
||||||
expect(typeof gitignore.init).toBe('function');
|
var outputGenerator = gitignore.init(mockGenerator);
|
||||||
expect(typeof gitignore.prompt).toBe('function');
|
expect(outputGenerator).toEqual(mockGenerator);
|
||||||
expect(typeof gitignore.configure).toBe('function');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('init()', function () {
|
it('should not interact with config',
|
||||||
it('should return a generator',
|
function () {
|
||||||
function () {
|
var spy = spyOn(mockGenerator.config, 'defaults');
|
||||||
var outputGenerator = gitignore.init(mockGenerator);
|
gitignore.init(mockGenerator);
|
||||||
expect(outputGenerator).toEqual(mockGenerator);
|
expect(spy.calls.any()).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should not interact with config',
|
describe('prompt()', function () {
|
||||||
function () {
|
it('should return a generator',
|
||||||
var spy = spyOn(mockGenerator.config, 'defaults');
|
function () {
|
||||||
gitignore.init(mockGenerator);
|
var outputGenerator = gitignore.prompt(mockGenerator);
|
||||||
expect(spy.calls.any()).toBeFalsy();
|
expect(outputGenerator).toEqual(mockGenerator);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('prompt()', function () {
|
it('should do nothing',
|
||||||
it('should return a generator',
|
function () {
|
||||||
function () {
|
var spy = spyOn(mockGenerator, 'prompt');
|
||||||
var outputGenerator = gitignore.prompt(mockGenerator);
|
gitignore.init(mockGenerator);
|
||||||
expect(outputGenerator).toEqual(mockGenerator);
|
gitignore.prompt(mockGenerator);
|
||||||
});
|
expect(spy.calls.any()).toBeFalsy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should do nothing',
|
describe('configure()', function () {
|
||||||
function () {
|
it('should return a generator',
|
||||||
var spy = spyOn(mockGenerator, 'prompt');
|
function () {
|
||||||
gitignore.init(mockGenerator);
|
var outputGenerator = gitignore.configure(mockGenerator);
|
||||||
gitignore.prompt(mockGenerator);
|
expect(outputGenerator).toEqual(mockGenerator);
|
||||||
expect(spy.calls.any()).toBeFalsy();
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('configure()', function () {
|
it('should add gitignore to the project files.',
|
||||||
it('should return a generator',
|
function () {
|
||||||
function () {
|
mockGenerator.fs.write('.gitignore', ['one', 'two'].join('\n'));
|
||||||
var outputGenerator = gitignore.configure(mockGenerator);
|
gitignore.init(mockGenerator);
|
||||||
expect(outputGenerator).toEqual(mockGenerator);
|
gitignore.prompt(mockGenerator);
|
||||||
});
|
gitignore.configure(mockGenerator);
|
||||||
|
|
||||||
it('should add gitignore to the project files.',
|
var files = projectBuilder.getIncludedFiles();
|
||||||
function () {
|
expect(files.length).toBe(1);
|
||||||
mockGenerator.fs.write('.gitignore', ['one', 'two'].join('\n'));
|
expect(files[0].to).toBe('.gitignore');
|
||||||
gitignore.init(mockGenerator);
|
});
|
||||||
gitignore.prompt(mockGenerator);
|
});
|
||||||
gitignore.configure(mockGenerator);
|
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
describe('.gitignore management', function () {
|
||||||
expect(files.length).toBe(1);
|
|
||||||
expect(files[0].to).toBe('.gitignore');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.gitignore management', function () {
|
it('should echo back existing .gitignore',
|
||||||
|
function () {
|
||||||
it('should echo back existing .gitignore',
|
mockGenerator.fs.write('.gitignore', ['one', 'two'].join('\n'));
|
||||||
function () {
|
|
||||||
mockGenerator.fs.write('.gitignore', ['one', 'two'].join('\n'));
|
|
||||||
|
|
||||||
gitignore.init(mockGenerator);
|
|
||||||
gitignore.prompt(mockGenerator);
|
|
||||||
gitignore.configure(mockGenerator);
|
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
|
||||||
var ignoreRef = files[0];
|
|
||||||
var ignoreContent = ignoreRef.content().split('\n');
|
|
||||||
expect(ignoreContent.length).toBe(2);
|
|
||||||
|
|
||||||
expect(ignoreContent[0]).toEqual('one');
|
|
||||||
expect(ignoreContent[1]).toEqual('two');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should include any files flagged as ignored in the project builder.',
|
|
||||||
function () {
|
|
||||||
mockGenerator.fs.write('.gitignore', '');
|
|
||||||
projectBuilder.ignoreFile('foo/bar.json');
|
|
||||||
|
|
||||||
gitignore.init(mockGenerator);
|
|
||||||
gitignore.prompt(mockGenerator);
|
|
||||||
gitignore.configure(mockGenerator);
|
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
|
||||||
var ignoreRef = files[0]; // There should only be one file.
|
|
||||||
var ignoreContent = ignoreRef.content().split('\n');
|
|
||||||
expect(ignoreContent.length).toBe(1);
|
|
||||||
|
|
||||||
expect(ignoreContent[0]).toBe('foo/bar.json');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should de-duplicate file paths from multiple locations.',
|
|
||||||
function () {
|
|
||||||
// include 'node_modules' from both an existing file and from the project builder.
|
|
||||||
mockGenerator.fs.write('.gitignore', ['node_modules'].join('\n'));
|
|
||||||
projectBuilder.ignoreFile('node_modules');
|
|
||||||
|
|
||||||
gitignore.init(mockGenerator);
|
|
||||||
gitignore.prompt(mockGenerator);
|
|
||||||
gitignore.configure(mockGenerator);
|
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
|
||||||
var ignoreRef = files[0]; // There should only be one file.
|
|
||||||
var ignoreContent = ignoreRef.content().split('\n');
|
|
||||||
expect(ignoreContent.length).toBe(1);
|
|
||||||
|
|
||||||
expect(ignoreContent[0]).toBe('node_modules');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should sort the ignored files.',
|
|
||||||
function () {
|
|
||||||
mockGenerator.fs.write('.gitignore', ['b_line', 'a_line'].join('\n'));
|
|
||||||
|
|
||||||
gitignore.init(mockGenerator);
|
|
||||||
gitignore.prompt(mockGenerator);
|
|
||||||
gitignore.configure(mockGenerator);
|
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
|
||||||
var ignoreRef = files[0];
|
|
||||||
var ignoreContent = ignoreRef.content().split('\n');
|
|
||||||
expect(ignoreContent.length).toBe(2);
|
|
||||||
expect(ignoreContent[0]).toBe('a_line');
|
|
||||||
expect(ignoreContent[1]).toBe('b_line');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should remove any whitespace from the existing .gitignore',
|
|
||||||
function () {
|
|
||||||
mockGenerator.fs.write('.gitignore', ['1_one', '', '2_two', ''].join('\n'));
|
|
||||||
|
|
||||||
gitignore.init(mockGenerator);
|
|
||||||
gitignore.prompt(mockGenerator);
|
|
||||||
gitignore.configure(mockGenerator);
|
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
|
||||||
var ignoreRef = files[0];
|
|
||||||
var ignoreContent = ignoreRef.content().split('\n');
|
|
||||||
expect(ignoreContent.length).toBe(2);
|
|
||||||
expect(ignoreContent[0]).toBe('1_one');
|
|
||||||
expect(ignoreContent[1]).toBe('2_two');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should remove any comments from the existing .gitignore',
|
|
||||||
function () {
|
|
||||||
mockGenerator.fs.write('.gitignore', ['1_one', '# comment', ' #comment'].join('\n'));
|
|
||||||
|
|
||||||
gitignore.init(mockGenerator);
|
|
||||||
gitignore.prompt(mockGenerator);
|
|
||||||
gitignore.configure(mockGenerator);
|
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
|
||||||
var ignoreRef = files[0];
|
|
||||||
var ignoreContent = ignoreRef.content().split('\n');
|
|
||||||
expect(ignoreContent.length).toBe(1);
|
|
||||||
expect(ignoreContent[0]).toBe('1_one');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should deduplicate content',
|
|
||||||
function () {
|
|
||||||
mockGenerator.fs.write('.gitignore', ['1_one', '1_one'].join('\n'));
|
|
||||||
|
|
||||||
gitignore.init(mockGenerator);
|
|
||||||
gitignore.prompt(mockGenerator);
|
|
||||||
gitignore.configure(mockGenerator);
|
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
|
||||||
var ignoreRef = files[0];
|
|
||||||
var ignoreContent = ignoreRef.content().split('\n');
|
|
||||||
expect(ignoreContent.length).toBe(1);
|
|
||||||
expect(ignoreContent[0]).toBe('1_one');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should delete the file if there\'s nothing to ignore', function () {
|
|
||||||
mockGenerator.fs.write('.gitignore', '');
|
|
||||||
|
|
||||||
gitignore.init(mockGenerator);
|
gitignore.init(mockGenerator);
|
||||||
gitignore.prompt(mockGenerator);
|
gitignore.prompt(mockGenerator);
|
||||||
gitignore.configure(mockGenerator);
|
gitignore.configure(mockGenerator);
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
var files = projectBuilder.getIncludedFiles();
|
||||||
expect(files.length).toBe(0);
|
var ignoreRef = files[0];
|
||||||
|
var ignoreContent = ignoreRef.content().split('\n');
|
||||||
|
expect(ignoreContent.length).toBe(2);
|
||||||
|
|
||||||
var rmFiles = projectBuilder.getExcludedFiles();
|
expect(ignoreContent[0]).toEqual('one');
|
||||||
expect(rmFiles.length).toBe(1);
|
expect(ignoreContent[1]).toEqual('two');
|
||||||
expect(rmFiles[0]).toBe('.gitignore');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should include any files flagged as ignored in the project builder.',
|
||||||
|
function () {
|
||||||
|
mockGenerator.fs.write('.gitignore', '');
|
||||||
|
projectBuilder.ignoreFile('foo/bar.json');
|
||||||
|
|
||||||
|
gitignore.init(mockGenerator);
|
||||||
|
gitignore.prompt(mockGenerator);
|
||||||
|
gitignore.configure(mockGenerator);
|
||||||
|
|
||||||
|
var files = projectBuilder.getIncludedFiles();
|
||||||
|
var ignoreRef = files[0]; // There should only be one file.
|
||||||
|
var ignoreContent = ignoreRef.content().split('\n');
|
||||||
|
expect(ignoreContent.length).toBe(1);
|
||||||
|
|
||||||
|
expect(ignoreContent[0]).toBe('foo/bar.json');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should de-duplicate file paths from multiple locations.',
|
||||||
|
function () {
|
||||||
|
// include 'node_modules' from both an existing file and from the project builder.
|
||||||
|
mockGenerator.fs.write('.gitignore', ['node_modules'].join('\n'));
|
||||||
|
projectBuilder.ignoreFile('node_modules');
|
||||||
|
|
||||||
|
gitignore.init(mockGenerator);
|
||||||
|
gitignore.prompt(mockGenerator);
|
||||||
|
gitignore.configure(mockGenerator);
|
||||||
|
|
||||||
|
var files = projectBuilder.getIncludedFiles();
|
||||||
|
var ignoreRef = files[0]; // There should only be one file.
|
||||||
|
var ignoreContent = ignoreRef.content().split('\n');
|
||||||
|
expect(ignoreContent.length).toBe(1);
|
||||||
|
|
||||||
|
expect(ignoreContent[0]).toBe('node_modules');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should sort the ignored files.',
|
||||||
|
function () {
|
||||||
|
mockGenerator.fs.write('.gitignore', ['b_line', 'a_line'].join('\n'));
|
||||||
|
|
||||||
|
gitignore.init(mockGenerator);
|
||||||
|
gitignore.prompt(mockGenerator);
|
||||||
|
gitignore.configure(mockGenerator);
|
||||||
|
|
||||||
|
var files = projectBuilder.getIncludedFiles();
|
||||||
|
var ignoreRef = files[0];
|
||||||
|
var ignoreContent = ignoreRef.content().split('\n');
|
||||||
|
expect(ignoreContent.length).toBe(2);
|
||||||
|
expect(ignoreContent[0]).toBe('a_line');
|
||||||
|
expect(ignoreContent[1]).toBe('b_line');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove any whitespace from the existing .gitignore',
|
||||||
|
function () {
|
||||||
|
mockGenerator.fs.write('.gitignore', ['1_one', '', '2_two', ''].join('\n'));
|
||||||
|
|
||||||
|
gitignore.init(mockGenerator);
|
||||||
|
gitignore.prompt(mockGenerator);
|
||||||
|
gitignore.configure(mockGenerator);
|
||||||
|
|
||||||
|
var files = projectBuilder.getIncludedFiles();
|
||||||
|
var ignoreRef = files[0];
|
||||||
|
var ignoreContent = ignoreRef.content().split('\n');
|
||||||
|
expect(ignoreContent.length).toBe(2);
|
||||||
|
expect(ignoreContent[0]).toBe('1_one');
|
||||||
|
expect(ignoreContent[1]).toBe('2_two');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove any comments from the existing .gitignore',
|
||||||
|
function () {
|
||||||
|
mockGenerator.fs.write('.gitignore', ['1_one', '# comment', ' #comment'].join('\n'));
|
||||||
|
|
||||||
|
gitignore.init(mockGenerator);
|
||||||
|
gitignore.prompt(mockGenerator);
|
||||||
|
gitignore.configure(mockGenerator);
|
||||||
|
|
||||||
|
var files = projectBuilder.getIncludedFiles();
|
||||||
|
var ignoreRef = files[0];
|
||||||
|
var ignoreContent = ignoreRef.content().split('\n');
|
||||||
|
expect(ignoreContent.length).toBe(1);
|
||||||
|
expect(ignoreContent[0]).toBe('1_one');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should deduplicate content',
|
||||||
|
function () {
|
||||||
|
mockGenerator.fs.write('.gitignore', ['1_one', '1_one'].join('\n'));
|
||||||
|
|
||||||
|
gitignore.init(mockGenerator);
|
||||||
|
gitignore.prompt(mockGenerator);
|
||||||
|
gitignore.configure(mockGenerator);
|
||||||
|
|
||||||
|
var files = projectBuilder.getIncludedFiles();
|
||||||
|
var ignoreRef = files[0];
|
||||||
|
var ignoreContent = ignoreRef.content().split('\n');
|
||||||
|
expect(ignoreContent.length).toBe(1);
|
||||||
|
expect(ignoreContent[0]).toBe('1_one');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should delete the file if there\'s nothing to ignore', function () {
|
||||||
|
mockGenerator.fs.write('.gitignore', '');
|
||||||
|
|
||||||
|
gitignore.init(mockGenerator);
|
||||||
|
gitignore.prompt(mockGenerator);
|
||||||
|
gitignore.configure(mockGenerator);
|
||||||
|
|
||||||
|
var files = projectBuilder.getIncludedFiles();
|
||||||
|
expect(files.length).toBe(0);
|
||||||
|
|
||||||
|
var rmFiles = projectBuilder.getExcludedFiles();
|
||||||
|
expect(rmFiles.length).toBe(1);
|
||||||
|
expect(rmFiles[0]).toBe('.gitignore');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})();
|
});
|
||||||
|
|
|
@ -14,84 +14,83 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
var libDir = '../../../../generators/app/lib';
|
|
||||||
|
|
||||||
var license = require(libDir + '/component/license');
|
var libDir = '../../../../generators/app/lib';
|
||||||
var projectBuilder = require(libDir + '/project_builder');
|
|
||||||
var pkgBuilder = require(libDir + '/pkg_builder');
|
|
||||||
var mocks = require('../../../helpers/mocks');
|
|
||||||
var mockGenerator;
|
|
||||||
|
|
||||||
describe('generator-openstack:lib/component/license', function () {
|
var license = require(libDir + '/component/license');
|
||||||
|
var projectBuilder = require(libDir + '/project_builder');
|
||||||
|
var pkgBuilder = require(libDir + '/pkg_builder');
|
||||||
|
var mocks = require('../../../helpers/mocks');
|
||||||
|
var mockGenerator;
|
||||||
|
|
||||||
beforeEach(function () {
|
describe('generator-openstack:lib/component/license', function () {
|
||||||
mockGenerator = mocks.buildGenerator();
|
|
||||||
projectBuilder.clear();
|
beforeEach(function () {
|
||||||
|
mockGenerator = mocks.buildGenerator();
|
||||||
|
projectBuilder.clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should define init, prompt, and configure',
|
||||||
|
function () {
|
||||||
|
expect(typeof license.init).toBe('function');
|
||||||
|
expect(typeof license.prompt).toBe('function');
|
||||||
|
expect(typeof license.configure).toBe('function');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should define init, prompt, and configure',
|
describe('init()', function () {
|
||||||
|
it('should return a generator',
|
||||||
function () {
|
function () {
|
||||||
expect(typeof license.init).toBe('function');
|
var outputGenerator = license.init(mockGenerator);
|
||||||
expect(typeof license.prompt).toBe('function');
|
expect(outputGenerator).toEqual(mockGenerator);
|
||||||
expect(typeof license.configure).toBe('function');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('init()', function () {
|
it('should do nothing',
|
||||||
it('should return a generator',
|
function () {
|
||||||
function () {
|
var spy = spyOn(mockGenerator.config, 'defaults');
|
||||||
var outputGenerator = license.init(mockGenerator);
|
license.init(mockGenerator);
|
||||||
expect(outputGenerator).toEqual(mockGenerator);
|
expect(spy.calls.any()).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should do nothing',
|
|
||||||
function () {
|
|
||||||
var spy = spyOn(mockGenerator.config, 'defaults');
|
|
||||||
license.init(mockGenerator);
|
|
||||||
expect(spy.calls.any()).toBeFalsy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('prompt()', function () {
|
|
||||||
it('should return a generator',
|
|
||||||
function () {
|
|
||||||
var outputGenerator = license.prompt(mockGenerator);
|
|
||||||
expect(outputGenerator).toEqual(mockGenerator);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should do nothing',
|
|
||||||
function () {
|
|
||||||
var spy = spyOn(mockGenerator, 'prompt');
|
|
||||||
license.prompt(mockGenerator);
|
|
||||||
expect(spy.calls.any()).toBeFalsy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('configure()', function () {
|
|
||||||
it('should return a generator',
|
|
||||||
function () {
|
|
||||||
var outputGenerator = license.configure(mockGenerator);
|
|
||||||
expect(outputGenerator).toEqual(mockGenerator);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should add license to the project files.',
|
|
||||||
function () {
|
|
||||||
license.configure(mockGenerator);
|
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
|
||||||
expect(files.length).toBe(1);
|
|
||||||
expect(files[0].from).toBe('LICENSE');
|
|
||||||
expect(files[0].to).toBe('LICENSE');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should add license to the package.json files.',
|
|
||||||
function () {
|
|
||||||
license.configure(mockGenerator);
|
|
||||||
|
|
||||||
var parsedResult = JSON.parse(pkgBuilder.toJSON());
|
|
||||||
expect(parsedResult.license).toBe("Apache-2.0");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
})();
|
|
||||||
|
describe('prompt()', function () {
|
||||||
|
it('should return a generator',
|
||||||
|
function () {
|
||||||
|
var outputGenerator = license.prompt(mockGenerator);
|
||||||
|
expect(outputGenerator).toEqual(mockGenerator);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should do nothing',
|
||||||
|
function () {
|
||||||
|
var spy = spyOn(mockGenerator, 'prompt');
|
||||||
|
license.prompt(mockGenerator);
|
||||||
|
expect(spy.calls.any()).toBeFalsy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('configure()', function () {
|
||||||
|
it('should return a generator',
|
||||||
|
function () {
|
||||||
|
var outputGenerator = license.configure(mockGenerator);
|
||||||
|
expect(outputGenerator).toEqual(mockGenerator);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add license to the project files.',
|
||||||
|
function () {
|
||||||
|
license.configure(mockGenerator);
|
||||||
|
|
||||||
|
var files = projectBuilder.getIncludedFiles();
|
||||||
|
expect(files.length).toBe(1);
|
||||||
|
expect(files[0].from).toBe('LICENSE');
|
||||||
|
expect(files[0].to).toBe('LICENSE');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add license to the package.json files.',
|
||||||
|
function () {
|
||||||
|
license.configure(mockGenerator);
|
||||||
|
|
||||||
|
var parsedResult = JSON.parse(pkgBuilder.toJSON());
|
||||||
|
expect(parsedResult.license).toBe("Apache-2.0");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -14,96 +14,95 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
var libDir = '../../../../generators/app/lib';
|
|
||||||
|
|
||||||
var nsp = require(libDir + '/component/nsp');
|
var libDir = '../../../../generators/app/lib';
|
||||||
var projectBuilder = require(libDir + '/project_builder');
|
|
||||||
var pkgBuilder = require(libDir + '/pkg_builder');
|
|
||||||
var mocks = require('../../../helpers/mocks');
|
|
||||||
var mockGenerator;
|
|
||||||
|
|
||||||
describe('generator-openstack:lib/component/nsp', function () {
|
var nsp = require(libDir + '/component/nsp');
|
||||||
|
var projectBuilder = require(libDir + '/project_builder');
|
||||||
|
var pkgBuilder = require(libDir + '/pkg_builder');
|
||||||
|
var mocks = require('../../../helpers/mocks');
|
||||||
|
var mockGenerator;
|
||||||
|
|
||||||
beforeEach(function () {
|
describe('generator-openstack:lib/component/nsp', function () {
|
||||||
mockGenerator = mocks.buildGenerator();
|
|
||||||
projectBuilder.clear();
|
beforeEach(function () {
|
||||||
|
mockGenerator = mocks.buildGenerator();
|
||||||
|
projectBuilder.clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should define init, prompt, and configure',
|
||||||
|
function () {
|
||||||
|
expect(typeof nsp.init).toBe('function');
|
||||||
|
expect(typeof nsp.prompt).toBe('function');
|
||||||
|
expect(typeof nsp.configure).toBe('function');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should define init, prompt, and configure',
|
describe('init()', function () {
|
||||||
|
it('should return a generator',
|
||||||
function () {
|
function () {
|
||||||
expect(typeof nsp.init).toBe('function');
|
var outputGenerator = nsp.init(mockGenerator);
|
||||||
expect(typeof nsp.prompt).toBe('function');
|
expect(outputGenerator).toEqual(mockGenerator);
|
||||||
expect(typeof nsp.configure).toBe('function');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('init()', function () {
|
it('should do nothing',
|
||||||
it('should return a generator',
|
function () {
|
||||||
function () {
|
var spy = spyOn(mockGenerator.config, 'defaults');
|
||||||
var outputGenerator = nsp.init(mockGenerator);
|
nsp.init(mockGenerator);
|
||||||
expect(outputGenerator).toEqual(mockGenerator);
|
expect(spy.calls.any()).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should do nothing',
|
|
||||||
function () {
|
|
||||||
var spy = spyOn(mockGenerator.config, 'defaults');
|
|
||||||
nsp.init(mockGenerator);
|
|
||||||
expect(spy.calls.any()).toBeFalsy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('prompt()', function () {
|
|
||||||
it('should return a generator',
|
|
||||||
function () {
|
|
||||||
var outputGenerator = nsp.prompt(mockGenerator);
|
|
||||||
expect(outputGenerator).toEqual(mockGenerator);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should add nsp to dependencies',
|
|
||||||
function () {
|
|
||||||
pkgBuilder.fromJSON('{"devDependencies":{}}');
|
|
||||||
|
|
||||||
var devDeps = pkgBuilder.getValue('devDependencies');
|
|
||||||
expect(devDeps.nsp).not.toBeDefined();
|
|
||||||
|
|
||||||
nsp.prompt(mockGenerator);
|
|
||||||
|
|
||||||
devDeps = pkgBuilder.getValue('devDependencies');
|
|
||||||
expect(devDeps.nsp).toBeDefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should add the prepublish hook to the project',
|
|
||||||
function () {
|
|
||||||
pkgBuilder.fromJSON('{}');
|
|
||||||
|
|
||||||
var scripts = pkgBuilder.getValue('scripts');
|
|
||||||
expect(scripts).not.toBeDefined();
|
|
||||||
|
|
||||||
nsp.prompt(mockGenerator);
|
|
||||||
|
|
||||||
var newScripts = pkgBuilder.getValue('scripts');
|
|
||||||
expect(newScripts.prepublish).toBeDefined();
|
|
||||||
expect(newScripts.prepublish).toEqual('nsp check');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('configure()', function () {
|
|
||||||
it('should return a generator',
|
|
||||||
function () {
|
|
||||||
var outputGenerator = nsp.configure(mockGenerator);
|
|
||||||
expect(outputGenerator).toEqual(mockGenerator);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should add .nsprc to the project files.',
|
|
||||||
function () {
|
|
||||||
nsp.configure(mockGenerator);
|
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
|
||||||
expect(files.length).toBe(1);
|
|
||||||
expect(files[0].from).toBe('.nsprc');
|
|
||||||
expect(files[0].to).toBe('.nsprc');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
})();
|
|
||||||
|
describe('prompt()', function () {
|
||||||
|
it('should return a generator',
|
||||||
|
function () {
|
||||||
|
var outputGenerator = nsp.prompt(mockGenerator);
|
||||||
|
expect(outputGenerator).toEqual(mockGenerator);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add nsp to dependencies',
|
||||||
|
function () {
|
||||||
|
pkgBuilder.fromJSON('{"devDependencies":{}}');
|
||||||
|
|
||||||
|
var devDeps = pkgBuilder.getValue('devDependencies');
|
||||||
|
expect(devDeps.nsp).not.toBeDefined();
|
||||||
|
|
||||||
|
nsp.prompt(mockGenerator);
|
||||||
|
|
||||||
|
devDeps = pkgBuilder.getValue('devDependencies');
|
||||||
|
expect(devDeps.nsp).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add the prepublish hook to the project',
|
||||||
|
function () {
|
||||||
|
pkgBuilder.fromJSON('{}');
|
||||||
|
|
||||||
|
var scripts = pkgBuilder.getValue('scripts');
|
||||||
|
expect(scripts).not.toBeDefined();
|
||||||
|
|
||||||
|
nsp.prompt(mockGenerator);
|
||||||
|
|
||||||
|
var newScripts = pkgBuilder.getValue('scripts');
|
||||||
|
expect(newScripts.prepublish).toBeDefined();
|
||||||
|
expect(newScripts.prepublish).toEqual('nsp check');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('configure()', function () {
|
||||||
|
it('should return a generator',
|
||||||
|
function () {
|
||||||
|
var outputGenerator = nsp.configure(mockGenerator);
|
||||||
|
expect(outputGenerator).toEqual(mockGenerator);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add .nsprc to the project files.',
|
||||||
|
function () {
|
||||||
|
nsp.configure(mockGenerator);
|
||||||
|
|
||||||
|
var files = projectBuilder.getIncludedFiles();
|
||||||
|
expect(files.length).toBe(1);
|
||||||
|
expect(files[0].from).toBe('.nsprc');
|
||||||
|
expect(files[0].to).toBe('.nsprc');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -14,177 +14,176 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
var libDir = '../../../../generators/app/lib';
|
|
||||||
|
|
||||||
var pkg = require(libDir + '/component/pkg');
|
var libDir = '../../../../generators/app/lib';
|
||||||
var projectBuilder = require(libDir + '/project_builder');
|
|
||||||
var pkgBuilder = require(libDir + '/pkg_builder');
|
|
||||||
var mocks = require('../../../helpers/mocks');
|
|
||||||
var mockGenerator;
|
|
||||||
|
|
||||||
var packageFile = {};
|
var pkg = require(libDir + '/component/pkg');
|
||||||
|
var projectBuilder = require(libDir + '/project_builder');
|
||||||
|
var pkgBuilder = require(libDir + '/pkg_builder');
|
||||||
|
var mocks = require('../../../helpers/mocks');
|
||||||
|
var mockGenerator;
|
||||||
|
|
||||||
describe('generator-openstack:lib/component/pkg', function () {
|
var packageFile = {};
|
||||||
|
|
||||||
beforeEach(function () {
|
describe('generator-openstack:lib/component/pkg', function () {
|
||||||
mockGenerator = mocks.buildGenerator();
|
|
||||||
projectBuilder.clear();
|
beforeEach(function () {
|
||||||
jasmine.clock().install();
|
mockGenerator = mocks.buildGenerator();
|
||||||
|
projectBuilder.clear();
|
||||||
|
jasmine.clock().install();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
jasmine.clock().uninstall();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should define init, prompt, and configure',
|
||||||
|
function () {
|
||||||
|
expect(typeof pkg.init).toBe('function');
|
||||||
|
expect(typeof pkg.prompt).toBe('function');
|
||||||
|
expect(typeof pkg.configure).toBe('function');
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
describe('init()', function () {
|
||||||
jasmine.clock().uninstall();
|
it('should return a generator',
|
||||||
});
|
|
||||||
|
|
||||||
it('should define init, prompt, and configure',
|
|
||||||
function () {
|
function () {
|
||||||
expect(typeof pkg.init).toBe('function');
|
var outputGenerator = pkg.init(mockGenerator);
|
||||||
expect(typeof pkg.prompt).toBe('function');
|
expect(outputGenerator).toEqual(mockGenerator);
|
||||||
expect(typeof pkg.configure).toBe('function');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('init()', function () {
|
it('should read an existing package.json file into the package builder',
|
||||||
it('should return a generator',
|
function () {
|
||||||
function () {
|
mockGenerator.fs.writeJSON("package.json", {name: "foo"});
|
||||||
var outputGenerator = pkg.init(mockGenerator);
|
|
||||||
expect(outputGenerator).toEqual(mockGenerator);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should read an existing package.json file into the package builder',
|
pkg.init(mockGenerator);
|
||||||
function () {
|
var output = JSON.parse(pkgBuilder.toJSON());
|
||||||
mockGenerator.fs.writeJSON("package.json", {name: "foo"});
|
expect(output.name).toBe('foo');
|
||||||
|
});
|
||||||
|
|
||||||
pkg.init(mockGenerator);
|
it('should add several files to the ignore list.',
|
||||||
var output = JSON.parse(pkgBuilder.toJSON());
|
function () {
|
||||||
expect(output.name).toBe('foo');
|
pkg.init(mockGenerator);
|
||||||
});
|
|
||||||
|
|
||||||
it('should add several files to the ignore list.',
|
var ignoredFiles = projectBuilder.getIgnoredFiles();
|
||||||
function () {
|
expect(ignoredFiles.indexOf('node_modules')).not.toBe(-1);
|
||||||
pkg.init(mockGenerator);
|
expect(ignoredFiles.indexOf('npm-debug.log')).not.toBe(-1);
|
||||||
|
expect(ignoredFiles.indexOf('package')).not.toBe(-1);
|
||||||
var ignoredFiles = projectBuilder.getIgnoredFiles();
|
expect(ignoredFiles.indexOf('.npm')).not.toBe(-1);
|
||||||
expect(ignoredFiles.indexOf('node_modules')).not.toBe(-1);
|
});
|
||||||
expect(ignoredFiles.indexOf('npm-debug.log')).not.toBe(-1);
|
|
||||||
expect(ignoredFiles.indexOf('package')).not.toBe(-1);
|
|
||||||
expect(ignoredFiles.indexOf('.npm')).not.toBe(-1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('prompt()', function () {
|
|
||||||
|
|
||||||
it('should return a promise that resolves with a generator',
|
|
||||||
function () {
|
|
||||||
var generator = mocks.buildGenerator();
|
|
||||||
var outputPromise = pkg.prompt(generator);
|
|
||||||
outputPromise.then(function (outputGenerator) {
|
|
||||||
expect(outputGenerator).toEqual(generator);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should revert to config defaults if no answers provided',
|
|
||||||
function () {
|
|
||||||
var config = {};
|
|
||||||
var mockAnswers = {};
|
|
||||||
var generator = mocks.buildGenerator(config, mockAnswers);
|
|
||||||
|
|
||||||
// Start with a blank package file.
|
|
||||||
generator.fs.write('package.json', JSON.stringify({}));
|
|
||||||
|
|
||||||
// Set defaults
|
|
||||||
pkg.init(generator);
|
|
||||||
pkg.configure(generator);
|
|
||||||
pkg.prompt(generator);
|
|
||||||
|
|
||||||
// Call the generator
|
|
||||||
expect(pkgBuilder.getValues()).toEqual({
|
|
||||||
devDependencies: { istanbul: '^0.4.2', jasmine: '^2.4.1'},
|
|
||||||
name: generator.appname,
|
|
||||||
description: null,
|
|
||||||
version: '0.0.1',
|
|
||||||
homepage: 'http://www.openstack.org/',
|
|
||||||
author: 'OpenStack <openstack-dev@lists.openstack.org> (http://www.openstack.org/)'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not show a prompt if non-interactive is set',
|
|
||||||
function () {
|
|
||||||
var generator = mocks.buildGenerator(null, null,
|
|
||||||
{'non-interactive': true});
|
|
||||||
var promptSpy = spyOn(generator, 'prompt');
|
|
||||||
|
|
||||||
generator.fs.write('package.json', JSON.stringify(packageFile));
|
|
||||||
|
|
||||||
pkg.init(generator);
|
|
||||||
pkg.prompt(generator);
|
|
||||||
|
|
||||||
expect(promptSpy.calls.any()).toBeFalsy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should use defaults in package.json if no answers provided',
|
|
||||||
function () {
|
|
||||||
var generator = mocks.buildGenerator();
|
|
||||||
|
|
||||||
var mockPackage = {
|
|
||||||
devDependencies: { istanbul: '^0.4.2', jasmine: '^2.4.1'},
|
|
||||||
name: 'name',
|
|
||||||
description: 'description',
|
|
||||||
version: '0.0.1',
|
|
||||||
homepage: 'http://www.openstack.org/',
|
|
||||||
author: 'OpenStack <openstack-dev@lists.openstack.org> (http://www.openstack.org/)'
|
|
||||||
};
|
|
||||||
generator.fs.write('package.json', JSON.stringify(mockPackage));
|
|
||||||
|
|
||||||
pkg.init(generator);
|
|
||||||
pkg.configure(generator);
|
|
||||||
pkg.prompt(generator);
|
|
||||||
|
|
||||||
expect(pkgBuilder.getValues()).toEqual(mockPackage);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should configure answers if answers provided',
|
|
||||||
function () {
|
|
||||||
var config = {};
|
|
||||||
var mockAnswers = {
|
|
||||||
devDependencies: { istanbul: '^0.4.2', jasmine: '^2.4.1'},
|
|
||||||
name: 'name',
|
|
||||||
description: 'description',
|
|
||||||
version: '1.0.0',
|
|
||||||
homepage: 'http://example.openstack.org/',
|
|
||||||
author: 'Example Author'
|
|
||||||
};
|
|
||||||
var generator = mocks.buildGenerator(config, mockAnswers);
|
|
||||||
|
|
||||||
// Start with a blank package file.
|
|
||||||
generator.fs.write('package.json', JSON.stringify({}));
|
|
||||||
|
|
||||||
// Set defaults
|
|
||||||
pkg.init(generator);
|
|
||||||
pkg.prompt(generator);
|
|
||||||
pkg.configure(generator);
|
|
||||||
|
|
||||||
expect(pkgBuilder.getValues()).toEqual(mockAnswers);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('configure()', function () {
|
|
||||||
it('should return a generator',
|
|
||||||
function () {
|
|
||||||
var outputGenerator = pkg.configure(mockGenerator);
|
|
||||||
expect(outputGenerator).toEqual(mockGenerator);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should add package.json to the project files.',
|
|
||||||
function () {
|
|
||||||
pkg.configure(mockGenerator);
|
|
||||||
|
|
||||||
var files = projectBuilder.getIncludedFiles();
|
|
||||||
expect(files.length).toBe(1);
|
|
||||||
expect(files[0].to).toBe('package.json');
|
|
||||||
expect(files[0].content).toBe(pkgBuilder.toJSON);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
})();
|
|
||||||
|
describe('prompt()', function () {
|
||||||
|
|
||||||
|
it('should return a promise that resolves with a generator',
|
||||||
|
function () {
|
||||||
|
var generator = mocks.buildGenerator();
|
||||||
|
var outputPromise = pkg.prompt(generator);
|
||||||
|
outputPromise.then(function (outputGenerator) {
|
||||||
|
expect(outputGenerator).toEqual(generator);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should revert to config defaults if no answers provided',
|
||||||
|
function () {
|
||||||
|
var config = {};
|
||||||
|
var mockAnswers = {};
|
||||||
|
var generator = mocks.buildGenerator(config, mockAnswers);
|
||||||
|
|
||||||
|
// Start with a blank package file.
|
||||||
|
generator.fs.write('package.json', JSON.stringify({}));
|
||||||
|
|
||||||
|
// Set defaults
|
||||||
|
pkg.init(generator);
|
||||||
|
pkg.configure(generator);
|
||||||
|
pkg.prompt(generator);
|
||||||
|
|
||||||
|
// Call the generator
|
||||||
|
expect(pkgBuilder.getValues()).toEqual({
|
||||||
|
devDependencies: { istanbul: '^0.4.2', jasmine: '^2.4.1'},
|
||||||
|
name: generator.appname,
|
||||||
|
description: null,
|
||||||
|
version: '0.0.1',
|
||||||
|
homepage: 'http://www.openstack.org/',
|
||||||
|
author: 'OpenStack <openstack-dev@lists.openstack.org> (http://www.openstack.org/)'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not show a prompt if non-interactive is set',
|
||||||
|
function () {
|
||||||
|
var generator = mocks.buildGenerator(null, null,
|
||||||
|
{'non-interactive': true});
|
||||||
|
var promptSpy = spyOn(generator, 'prompt');
|
||||||
|
|
||||||
|
generator.fs.write('package.json', JSON.stringify(packageFile));
|
||||||
|
|
||||||
|
pkg.init(generator);
|
||||||
|
pkg.prompt(generator);
|
||||||
|
|
||||||
|
expect(promptSpy.calls.any()).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use defaults in package.json if no answers provided',
|
||||||
|
function () {
|
||||||
|
var generator = mocks.buildGenerator();
|
||||||
|
|
||||||
|
var mockPackage = {
|
||||||
|
devDependencies: { istanbul: '^0.4.2', jasmine: '^2.4.1'},
|
||||||
|
name: 'name',
|
||||||
|
description: 'description',
|
||||||
|
version: '0.0.1',
|
||||||
|
homepage: 'http://www.openstack.org/',
|
||||||
|
author: 'OpenStack <openstack-dev@lists.openstack.org> (http://www.openstack.org/)'
|
||||||
|
};
|
||||||
|
generator.fs.write('package.json', JSON.stringify(mockPackage));
|
||||||
|
|
||||||
|
pkg.init(generator);
|
||||||
|
pkg.configure(generator);
|
||||||
|
pkg.prompt(generator);
|
||||||
|
|
||||||
|
expect(pkgBuilder.getValues()).toEqual(mockPackage);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should configure answers if answers provided',
|
||||||
|
function () {
|
||||||
|
var config = {};
|
||||||
|
var mockAnswers = {
|
||||||
|
devDependencies: { istanbul: '^0.4.2', jasmine: '^2.4.1'},
|
||||||
|
name: 'name',
|
||||||
|
description: 'description',
|
||||||
|
version: '1.0.0',
|
||||||
|
homepage: 'http://example.openstack.org/',
|
||||||
|
author: 'Example Author'
|
||||||
|
};
|
||||||
|
var generator = mocks.buildGenerator(config, mockAnswers);
|
||||||
|
|
||||||
|
// Start with a blank package file.
|
||||||
|
generator.fs.write('package.json', JSON.stringify({}));
|
||||||
|
|
||||||
|
// Set defaults
|
||||||
|
pkg.init(generator);
|
||||||
|
pkg.prompt(generator);
|
||||||
|
pkg.configure(generator);
|
||||||
|
|
||||||
|
expect(pkgBuilder.getValues()).toEqual(mockAnswers);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('configure()', function () {
|
||||||
|
it('should return a generator',
|
||||||
|
function () {
|
||||||
|
var outputGenerator = pkg.configure(mockGenerator);
|
||||||
|
expect(outputGenerator).toEqual(mockGenerator);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add package.json to the project files.',
|
||||||
|
function () {
|
||||||
|
pkg.configure(mockGenerator);
|
||||||
|
|
||||||
|
var files = projectBuilder.getIncludedFiles();
|
||||||
|
expect(files.length).toBe(1);
|
||||||
|
expect(files[0].to).toBe('package.json');
|
||||||
|
expect(files[0].content).toBe(pkgBuilder.toJSON);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -14,169 +14,168 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
var libDir = '../../../../generators/app/lib';
|
|
||||||
|
|
||||||
var structure = require(libDir + '/component/structure');
|
var libDir = '../../../../generators/app/lib';
|
||||||
var projectBuilder = require(libDir + '/project_builder');
|
|
||||||
var mocks = require('../../../helpers/mocks');
|
|
||||||
var mockGenerator;
|
|
||||||
|
|
||||||
var expectedDefaults = {
|
var structure = require(libDir + '/component/structure');
|
||||||
engine: 'browser',
|
var projectBuilder = require(libDir + '/project_builder');
|
||||||
language: 'es5',
|
var mocks = require('../../../helpers/mocks');
|
||||||
srcDir: './src',
|
var mockGenerator;
|
||||||
distDir: './dist',
|
|
||||||
testDir: './test'
|
|
||||||
};
|
|
||||||
|
|
||||||
describe('generator-openstack:lib/component/structure', function () {
|
var expectedDefaults = {
|
||||||
|
engine: 'browser',
|
||||||
|
language: 'es5',
|
||||||
|
srcDir: './src',
|
||||||
|
distDir: './dist',
|
||||||
|
testDir: './test'
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(function () {
|
describe('generator-openstack:lib/component/structure', function () {
|
||||||
mockGenerator = mocks.buildGenerator();
|
|
||||||
jasmine.clock().install();
|
beforeEach(function () {
|
||||||
|
mockGenerator = mocks.buildGenerator();
|
||||||
|
jasmine.clock().install();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
jasmine.clock().uninstall();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should define init, prompt, and configure',
|
||||||
|
function () {
|
||||||
|
expect(typeof structure.init).toBe('function');
|
||||||
|
expect(typeof structure.prompt).toBe('function');
|
||||||
|
expect(typeof structure.configure).toBe('function');
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
describe('init()', function () {
|
||||||
jasmine.clock().uninstall();
|
it('should return a generator',
|
||||||
});
|
|
||||||
|
|
||||||
it('should define init, prompt, and configure',
|
|
||||||
function () {
|
function () {
|
||||||
expect(typeof structure.init).toBe('function');
|
var outputGenerator = structure.init(mockGenerator);
|
||||||
expect(typeof structure.prompt).toBe('function');
|
expect(outputGenerator).toEqual(mockGenerator);
|
||||||
expect(typeof structure.configure).toBe('function');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('init()', function () {
|
it('should set configuration defaults',
|
||||||
it('should return a generator',
|
function () {
|
||||||
function () {
|
var spy = spyOn(mockGenerator.config, 'defaults');
|
||||||
var outputGenerator = structure.init(mockGenerator);
|
structure.init(mockGenerator);
|
||||||
expect(outputGenerator).toEqual(mockGenerator);
|
expect(spy).toHaveBeenCalledWith(expectedDefaults);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set configuration defaults',
|
|
||||||
function () {
|
|
||||||
var spy = spyOn(mockGenerator.config, 'defaults');
|
|
||||||
structure.init(mockGenerator);
|
|
||||||
expect(spy).toHaveBeenCalledWith(expectedDefaults);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('prompt()', function () {
|
|
||||||
|
|
||||||
it('should return a promise that resolves with a generator',
|
|
||||||
function () {
|
|
||||||
var generator = mocks.buildGenerator();
|
|
||||||
var outputPromise = structure.prompt(generator);
|
|
||||||
outputPromise.then(function (outputGenerator) {
|
|
||||||
expect(outputGenerator).toEqual(generator);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should revert to config defaults if no answers provided',
|
|
||||||
function () {
|
|
||||||
var config = {};
|
|
||||||
var mockAnswers = {};
|
|
||||||
var generator = mocks.buildGenerator(config, mockAnswers);
|
|
||||||
|
|
||||||
// Call the component
|
|
||||||
structure.init(generator);
|
|
||||||
structure.prompt(generator);
|
|
||||||
structure.configure(generator);
|
|
||||||
|
|
||||||
Object.keys(expectedDefaults).forEach(function (key) {
|
|
||||||
expect(generator.config.get(key)).toEqual(expectedDefaults[key]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not show a prompt if non-interactive is set',
|
|
||||||
function () {
|
|
||||||
var generator = mocks.buildGenerator(null, null, {'non-interactive': true});
|
|
||||||
var promptSpy = spyOn(generator, 'prompt');
|
|
||||||
|
|
||||||
structure.init(generator);
|
|
||||||
structure.prompt(generator);
|
|
||||||
|
|
||||||
expect(promptSpy.calls.any()).toBeFalsy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should configure answers if answers provided',
|
|
||||||
function () {
|
|
||||||
var config = {};
|
|
||||||
var mockAnswers = {
|
|
||||||
language: 'es6',
|
|
||||||
srcDir: './dir',
|
|
||||||
distDir: './foo',
|
|
||||||
testDir: './bar'
|
|
||||||
};
|
|
||||||
var generator = mocks.buildGenerator(config, mockAnswers);
|
|
||||||
|
|
||||||
// Set defaults
|
|
||||||
structure.init(generator);
|
|
||||||
structure.prompt(generator);
|
|
||||||
structure.configure(generator);
|
|
||||||
|
|
||||||
Object.keys(mockAnswers).forEach(function (key) {
|
|
||||||
expect(generator.config.get(key)).toEqual(mockAnswers[key]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not configure the dist directory for a node project',
|
|
||||||
function () {
|
|
||||||
var config = {};
|
|
||||||
var mockAnswers = {
|
|
||||||
engine: 'node',
|
|
||||||
distDir: './foo' // This answer should never be read.
|
|
||||||
};
|
|
||||||
var generator = mocks.buildGenerator(config, mockAnswers);
|
|
||||||
|
|
||||||
// Set defaults
|
|
||||||
structure.init(generator);
|
|
||||||
structure.prompt(generator);
|
|
||||||
structure.configure(generator);
|
|
||||||
|
|
||||||
expect(generator.config.get('distDir')).not.toBe(mockAnswers.distDir);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should configure the dist directory for a browser project',
|
|
||||||
function () {
|
|
||||||
var config = {};
|
|
||||||
var mockAnswers = {
|
|
||||||
engine: 'browser',
|
|
||||||
distDir: './foo' // This answer should never be read.
|
|
||||||
};
|
|
||||||
var generator = mocks.buildGenerator(config, mockAnswers);
|
|
||||||
|
|
||||||
// Set defaults
|
|
||||||
structure.init(generator);
|
|
||||||
structure.prompt(generator);
|
|
||||||
structure.configure(generator);
|
|
||||||
|
|
||||||
expect(generator.config.get('distDir')).toBe(mockAnswers.distDir);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('configure()', function () {
|
|
||||||
it('should return a generator',
|
|
||||||
function () {
|
|
||||||
var outputGenerator = structure.configure(mockGenerator);
|
|
||||||
expect(outputGenerator).toEqual(mockGenerator);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should add the dist directory to the ignoreFile.',
|
|
||||||
function () {
|
|
||||||
var ignoreSpy = spyOn(projectBuilder, 'ignoreFile');
|
|
||||||
|
|
||||||
var generator = mocks.buildGenerator();
|
|
||||||
|
|
||||||
structure.init(generator);
|
|
||||||
structure.prompt(generator);
|
|
||||||
structure.configure(generator);
|
|
||||||
|
|
||||||
expect(ignoreSpy).toHaveBeenCalledWith('./dist');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
})();
|
|
||||||
|
describe('prompt()', function () {
|
||||||
|
|
||||||
|
it('should return a promise that resolves with a generator',
|
||||||
|
function () {
|
||||||
|
var generator = mocks.buildGenerator();
|
||||||
|
var outputPromise = structure.prompt(generator);
|
||||||
|
outputPromise.then(function (outputGenerator) {
|
||||||
|
expect(outputGenerator).toEqual(generator);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should revert to config defaults if no answers provided',
|
||||||
|
function () {
|
||||||
|
var config = {};
|
||||||
|
var mockAnswers = {};
|
||||||
|
var generator = mocks.buildGenerator(config, mockAnswers);
|
||||||
|
|
||||||
|
// Call the component
|
||||||
|
structure.init(generator);
|
||||||
|
structure.prompt(generator);
|
||||||
|
structure.configure(generator);
|
||||||
|
|
||||||
|
Object.keys(expectedDefaults).forEach(function (key) {
|
||||||
|
expect(generator.config.get(key)).toEqual(expectedDefaults[key]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not show a prompt if non-interactive is set',
|
||||||
|
function () {
|
||||||
|
var generator = mocks.buildGenerator(null, null, {'non-interactive': true});
|
||||||
|
var promptSpy = spyOn(generator, 'prompt');
|
||||||
|
|
||||||
|
structure.init(generator);
|
||||||
|
structure.prompt(generator);
|
||||||
|
|
||||||
|
expect(promptSpy.calls.any()).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should configure answers if answers provided',
|
||||||
|
function () {
|
||||||
|
var config = {};
|
||||||
|
var mockAnswers = {
|
||||||
|
language: 'es6',
|
||||||
|
srcDir: './dir',
|
||||||
|
distDir: './foo',
|
||||||
|
testDir: './bar'
|
||||||
|
};
|
||||||
|
var generator = mocks.buildGenerator(config, mockAnswers);
|
||||||
|
|
||||||
|
// Set defaults
|
||||||
|
structure.init(generator);
|
||||||
|
structure.prompt(generator);
|
||||||
|
structure.configure(generator);
|
||||||
|
|
||||||
|
Object.keys(mockAnswers).forEach(function (key) {
|
||||||
|
expect(generator.config.get(key)).toEqual(mockAnswers[key]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not configure the dist directory for a node project',
|
||||||
|
function () {
|
||||||
|
var config = {};
|
||||||
|
var mockAnswers = {
|
||||||
|
engine: 'node',
|
||||||
|
distDir: './foo' // This answer should never be read.
|
||||||
|
};
|
||||||
|
var generator = mocks.buildGenerator(config, mockAnswers);
|
||||||
|
|
||||||
|
// Set defaults
|
||||||
|
structure.init(generator);
|
||||||
|
structure.prompt(generator);
|
||||||
|
structure.configure(generator);
|
||||||
|
|
||||||
|
expect(generator.config.get('distDir')).not.toBe(mockAnswers.distDir);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should configure the dist directory for a browser project',
|
||||||
|
function () {
|
||||||
|
var config = {};
|
||||||
|
var mockAnswers = {
|
||||||
|
engine: 'browser',
|
||||||
|
distDir: './foo' // This answer should never be read.
|
||||||
|
};
|
||||||
|
var generator = mocks.buildGenerator(config, mockAnswers);
|
||||||
|
|
||||||
|
// Set defaults
|
||||||
|
structure.init(generator);
|
||||||
|
structure.prompt(generator);
|
||||||
|
structure.configure(generator);
|
||||||
|
|
||||||
|
expect(generator.config.get('distDir')).toBe(mockAnswers.distDir);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('configure()', function () {
|
||||||
|
it('should return a generator',
|
||||||
|
function () {
|
||||||
|
var outputGenerator = structure.configure(mockGenerator);
|
||||||
|
expect(outputGenerator).toEqual(mockGenerator);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add the dist directory to the ignoreFile.',
|
||||||
|
function () {
|
||||||
|
var ignoreSpy = spyOn(projectBuilder, 'ignoreFile');
|
||||||
|
|
||||||
|
var generator = mocks.buildGenerator();
|
||||||
|
|
||||||
|
structure.init(generator);
|
||||||
|
structure.prompt(generator);
|
||||||
|
structure.configure(generator);
|
||||||
|
|
||||||
|
expect(ignoreSpy).toHaveBeenCalledWith('./dist');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -14,82 +14,81 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
var builder = require('../../../generators/app/lib/global_dependencies');
|
|
||||||
var globals = require('../../../global-dependencies.json');
|
|
||||||
var semver = require('semver');
|
|
||||||
|
|
||||||
describe('lib/global_dependencies', function () {
|
var builder = require('../../../generators/app/lib/global_dependencies');
|
||||||
|
var globals = require('../../../global-dependencies.json');
|
||||||
|
var semver = require('semver');
|
||||||
|
|
||||||
describe('data', function () {
|
describe('lib/global_dependencies', function () {
|
||||||
it('should contain all dependencies from the root global-dependencies.json',
|
|
||||||
function () {
|
describe('data', function () {
|
||||||
for (var key in globals) {
|
it('should contain all dependencies from the root global-dependencies.json',
|
||||||
if (globals.hasOwnProperty(key)) {
|
function () {
|
||||||
expect(builder.contains(key)).toBe(true);
|
for (var key in globals) {
|
||||||
}
|
if (globals.hasOwnProperty(key)) {
|
||||||
|
expect(builder.contains(key)).toBe(true);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('should contain valid semver versions for all dependencies',
|
it('should contain valid semver versions for all dependencies',
|
||||||
function () {
|
function () {
|
||||||
for (var key in globals) {
|
for (var key in globals) {
|
||||||
if (globals.hasOwnProperty(key)) {
|
if (globals.hasOwnProperty(key)) {
|
||||||
var version = builder.read(key);
|
var version = builder.read(key);
|
||||||
expect(semver.validRange(version)).toBeTruthy();
|
expect(semver.validRange(version)).toBeTruthy();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('contains()', function () {
|
||||||
|
it('should return true when a dependency exists', function () {
|
||||||
|
expect(builder.contains('eslint')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('contains()', function () {
|
it('should return false when a dependency doesn\'t exist', function () {
|
||||||
it('should return true when a dependency exists', function () {
|
expect(builder.contains('notarealdependency')).toBe(false);
|
||||||
expect(builder.contains('eslint')).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false when a dependency doesn\'t exist', function () {
|
|
||||||
expect(builder.contains('notarealdependency')).toBe(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('read()', function () {
|
|
||||||
it('should return the version of a dependency', function () {
|
|
||||||
expect(builder.read('eslint')).toBe(globals.eslint);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return undefined when a dependency doesn\'t exist', function () {
|
|
||||||
expect(builder.read('notarealdependency')).toBeUndefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('synchronize()', function () {
|
|
||||||
it('should update dependencies that are out of date.', function () {
|
|
||||||
var testDeps = {
|
|
||||||
eslint: '0.0.1'
|
|
||||||
};
|
|
||||||
var newDeps = builder.synchronize(testDeps);
|
|
||||||
|
|
||||||
expect(newDeps.eslint).toBeDefined();
|
|
||||||
expect(newDeps.eslint).not.toEqual(testDeps.eslint);
|
|
||||||
expect(newDeps.eslint).toEqual(globals.eslint);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not update dependencies that are up to date.', function () {
|
|
||||||
var testDeps = {
|
|
||||||
eslint: globals.eslint
|
|
||||||
};
|
|
||||||
var newDeps = builder.synchronize(testDeps);
|
|
||||||
expect(newDeps).toEqual(testDeps);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not touch unregistered dependencies.', function () {
|
|
||||||
var testDeps = {
|
|
||||||
notarealdependency: '0.0.1'
|
|
||||||
};
|
|
||||||
var newDeps = builder.synchronize(testDeps);
|
|
||||||
expect(newDeps.notarealdependency).toEqual(testDeps.notarealdependency);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})();
|
|
||||||
|
describe('read()', function () {
|
||||||
|
it('should return the version of a dependency', function () {
|
||||||
|
expect(builder.read('eslint')).toBe(globals.eslint);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return undefined when a dependency doesn\'t exist', function () {
|
||||||
|
expect(builder.read('notarealdependency')).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('synchronize()', function () {
|
||||||
|
it('should update dependencies that are out of date.', function () {
|
||||||
|
var testDeps = {
|
||||||
|
eslint: '0.0.1'
|
||||||
|
};
|
||||||
|
var newDeps = builder.synchronize(testDeps);
|
||||||
|
|
||||||
|
expect(newDeps.eslint).toBeDefined();
|
||||||
|
expect(newDeps.eslint).not.toEqual(testDeps.eslint);
|
||||||
|
expect(newDeps.eslint).toEqual(globals.eslint);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not update dependencies that are up to date.', function () {
|
||||||
|
var testDeps = {
|
||||||
|
eslint: globals.eslint
|
||||||
|
};
|
||||||
|
var newDeps = builder.synchronize(testDeps);
|
||||||
|
expect(newDeps).toEqual(testDeps);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not touch unregistered dependencies.', function () {
|
||||||
|
var testDeps = {
|
||||||
|
notarealdependency: '0.0.1'
|
||||||
|
};
|
||||||
|
var newDeps = builder.synchronize(testDeps);
|
||||||
|
expect(newDeps.notarealdependency).toEqual(testDeps.notarealdependency);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -14,214 +14,213 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
var builder = require('../../../generators/app/lib/pkg_builder');
|
|
||||||
var dependencies = require('../../../generators/app/lib/global_dependencies');
|
|
||||||
|
|
||||||
describe('generator-openstack:lib/pkg_builder', function () {
|
var builder = require('../../../generators/app/lib/pkg_builder');
|
||||||
|
var dependencies = require('../../../generators/app/lib/global_dependencies');
|
||||||
|
|
||||||
beforeEach(function () {
|
describe('generator-openstack:lib/pkg_builder', function () {
|
||||||
builder.fromJSON("{}"); // Clear
|
|
||||||
|
beforeEach(function () {
|
||||||
|
builder.fromJSON("{}"); // Clear
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should start as an empty object',
|
||||||
|
function () {
|
||||||
|
expect(builder.toJSON()).toBe("{}");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should start as an empty object',
|
it('should honor and echo back any pre-loaded package file',
|
||||||
|
function () {
|
||||||
|
var packageString = '{"name":"foo"}';
|
||||||
|
builder.fromJSON(packageString);
|
||||||
|
|
||||||
|
var parsedResult = JSON.parse(builder.toJSON());
|
||||||
|
expect(parsedResult.name).toBe("foo");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should permit adding and overriding values.',
|
||||||
|
function () {
|
||||||
|
builder.fromJSON('{"name":"foo"}');
|
||||||
|
builder.setValues({name: "bar", lol: "cat"});
|
||||||
|
|
||||||
|
var parsedResult = JSON.parse(builder.toJSON());
|
||||||
|
expect(parsedResult.name).toBe("bar");
|
||||||
|
expect(parsedResult.lol).toBe("cat");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not add parent prototype values.',
|
||||||
|
function () {
|
||||||
|
function Thing () {
|
||||||
|
}
|
||||||
|
|
||||||
|
Thing.prototype.foo = 'bar';
|
||||||
|
|
||||||
|
var thing = new Thing();
|
||||||
|
thing.name = 'bar';
|
||||||
|
thing.lol = 'cat';
|
||||||
|
|
||||||
|
builder.fromJSON('{"name":"foo"}');
|
||||||
|
builder.setValues(thing);
|
||||||
|
|
||||||
|
var parsedResult = JSON.parse(builder.toJSON());
|
||||||
|
expect(parsedResult.name).toBe("bar");
|
||||||
|
expect(parsedResult.lol).toBe("cat");
|
||||||
|
expect(parsedResult.foo).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('toJSON()', function () {
|
||||||
|
it('should update out-of-date dependencies.',
|
||||||
function () {
|
function () {
|
||||||
expect(builder.toJSON()).toBe("{}");
|
var testPackage = {
|
||||||
|
dependencies: {
|
||||||
|
eslint: "0.0.1"
|
||||||
|
},
|
||||||
|
peerDependencies: {
|
||||||
|
eslint: "0.0.1"
|
||||||
|
},
|
||||||
|
devDependencies: {
|
||||||
|
eslint: "0.0.1"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
builder.fromJSON(JSON.stringify(testPackage));
|
||||||
|
var result = JSON.parse(builder.toJSON());
|
||||||
|
expect(result.dependencies.eslint).toBe(dependencies.read('eslint'));
|
||||||
|
expect(result.peerDependencies.eslint).toBe(dependencies.read('eslint'));
|
||||||
|
expect(result.devDependencies.eslint).toBe(dependencies.read('eslint'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should honor and echo back any pre-loaded package file',
|
it('should not error if no dependencies are declared.',
|
||||||
function () {
|
function () {
|
||||||
var packageString = '{"name":"foo"}';
|
var testPackage = {
|
||||||
builder.fromJSON(packageString);
|
dependencies: {
|
||||||
|
eslint: "0.0.1"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var parsedResult = JSON.parse(builder.toJSON());
|
builder.fromJSON(JSON.stringify(testPackage));
|
||||||
expect(parsedResult.name).toBe("foo");
|
var result = JSON.parse(builder.toJSON());
|
||||||
|
expect(result.dependencies.eslint).toBe(dependencies.read('eslint'));
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should permit adding and overriding values.',
|
describe('getValues()', function () {
|
||||||
|
it('should permit retrieving the entire package block.',
|
||||||
function () {
|
function () {
|
||||||
builder.fromJSON('{"name":"foo"}');
|
builder.fromJSON('{"name":"foo"}');
|
||||||
builder.setValues({name: "bar", lol: "cat"});
|
expect(builder.getValues()).toEqual({name: 'foo'});
|
||||||
|
|
||||||
var parsedResult = JSON.parse(builder.toJSON());
|
|
||||||
expect(parsedResult.name).toBe("bar");
|
|
||||||
expect(parsedResult.lol).toBe("cat");
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should not add parent prototype values.',
|
describe('getValue()', function () {
|
||||||
|
it('should permit retrieving values from the package.',
|
||||||
function () {
|
function () {
|
||||||
function Thing () {
|
|
||||||
}
|
|
||||||
|
|
||||||
Thing.prototype.foo = 'bar';
|
|
||||||
|
|
||||||
var thing = new Thing();
|
|
||||||
thing.name = 'bar';
|
|
||||||
thing.lol = 'cat';
|
|
||||||
|
|
||||||
builder.fromJSON('{"name":"foo"}');
|
builder.fromJSON('{"name":"foo"}');
|
||||||
builder.setValues(thing);
|
expect(builder.getValue('name')).toBe('foo');
|
||||||
|
|
||||||
var parsedResult = JSON.parse(builder.toJSON());
|
|
||||||
expect(parsedResult.name).toBe("bar");
|
|
||||||
expect(parsedResult.lol).toBe("cat");
|
|
||||||
expect(parsedResult.foo).toBeUndefined();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toJSON()', function () {
|
it('should return undefined if the value is not set.',
|
||||||
it('should update out-of-date dependencies.',
|
function () {
|
||||||
function () {
|
builder.fromJSON('{"name":"foo"}');
|
||||||
var testPackage = {
|
expect(builder.getValue('invalidname')).toBeUndefined();
|
||||||
dependencies: {
|
});
|
||||||
eslint: "0.0.1"
|
|
||||||
},
|
|
||||||
peerDependencies: {
|
|
||||||
eslint: "0.0.1"
|
|
||||||
},
|
|
||||||
devDependencies: {
|
|
||||||
eslint: "0.0.1"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
builder.fromJSON(JSON.stringify(testPackage));
|
it('should return a default if provided.',
|
||||||
var result = JSON.parse(builder.toJSON());
|
function () {
|
||||||
expect(result.dependencies.eslint).toBe(dependencies.read('eslint'));
|
builder.fromJSON('{"name":"foo"}');
|
||||||
expect(result.peerDependencies.eslint).toBe(dependencies.read('eslint'));
|
expect(builder.getValue('invalidname', 'defaultValue'))
|
||||||
expect(result.devDependencies.eslint).toBe(dependencies.read('eslint'));
|
.toBe('defaultValue');
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should not error if no dependencies are declared.',
|
describe('addDependencies()', function () {
|
||||||
function () {
|
var eslintVersion = dependencies.read('eslint');
|
||||||
var testPackage = {
|
|
||||||
dependencies: {
|
|
||||||
eslint: "0.0.1"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
builder.fromJSON(JSON.stringify(testPackage));
|
it('should be able to add to dependencies', function () {
|
||||||
var result = JSON.parse(builder.toJSON());
|
builder.fromJSON('{"dependencies":{}}');
|
||||||
expect(result.dependencies.eslint).toBe(dependencies.read('eslint'));
|
builder.addDependencies('eslint');
|
||||||
});
|
expect(builder.getValue('dependencies').eslint).toBe(eslintVersion);
|
||||||
|
|
||||||
|
builder.fromJSON('{"dependencies":{}}');
|
||||||
|
builder.addDependencies(['eslint']);
|
||||||
|
expect(builder.getValue('dependencies').eslint).toBe(eslintVersion);
|
||||||
|
|
||||||
|
builder.fromJSON('{"dependencies":{}}');
|
||||||
|
builder.addDependencies('eslint', 'dependencies');
|
||||||
|
expect(builder.getValue('dependencies').eslint).toBe(eslintVersion);
|
||||||
|
|
||||||
|
builder.fromJSON('{"dependencies":{}}');
|
||||||
|
builder.addDependencies(['eslint'], 'dependencies');
|
||||||
|
expect(builder.getValue('dependencies').eslint).toBe(eslintVersion);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getValues()', function () {
|
it('should be able to add to devDependencies', function () {
|
||||||
it('should permit retrieving the entire package block.',
|
builder.fromJSON('{"devDependencies":{}}');
|
||||||
function () {
|
builder.addDependencies('eslint', 'devDependencies');
|
||||||
builder.fromJSON('{"name":"foo"}');
|
expect(builder.getValue('devDependencies').eslint).toBe(eslintVersion);
|
||||||
expect(builder.getValues()).toEqual({name: 'foo'});
|
|
||||||
});
|
builder.fromJSON('{"devDependencies":{}}');
|
||||||
|
builder.addDependencies(['eslint'], 'devDependencies');
|
||||||
|
expect(builder.getValue('devDependencies').eslint).toBe(eslintVersion);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getValue()', function () {
|
it('should be able to add to peerDependencies', function () {
|
||||||
it('should permit retrieving values from the package.',
|
builder.fromJSON('{"peerDependencies":{}}');
|
||||||
function () {
|
builder.addDependencies('eslint', 'peerDependencies');
|
||||||
builder.fromJSON('{"name":"foo"}');
|
expect(builder.getValue('peerDependencies').eslint).toBe(eslintVersion);
|
||||||
expect(builder.getValue('name')).toBe('foo');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return undefined if the value is not set.',
|
builder.fromJSON('{"peerDependencies":{}}');
|
||||||
function () {
|
builder.addDependencies(['eslint'], 'peerDependencies');
|
||||||
builder.fromJSON('{"name":"foo"}');
|
expect(builder.getValue('peerDependencies').eslint).toBe(eslintVersion);
|
||||||
expect(builder.getValue('invalidname')).toBeUndefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return a default if provided.',
|
|
||||||
function () {
|
|
||||||
builder.fromJSON('{"name":"foo"}');
|
|
||||||
expect(builder.getValue('invalidname', 'defaultValue'))
|
|
||||||
.toBe('defaultValue');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('addDependencies()', function () {
|
it('should create dependency maps if they don\'t yet exist in the package', function () {
|
||||||
var eslintVersion = dependencies.read('eslint');
|
builder.fromJSON('{}');
|
||||||
|
builder.addDependencies('eslint');
|
||||||
it('should be able to add to dependencies', function () {
|
builder.addDependencies('eslint', 'devDependencies');
|
||||||
builder.fromJSON('{"dependencies":{}}');
|
builder.addDependencies('eslint', 'peerDependencies');
|
||||||
builder.addDependencies('eslint');
|
expect(builder.getValue('dependencies')).not.toBeUndefined();
|
||||||
expect(builder.getValue('dependencies').eslint).toBe(eslintVersion);
|
expect(builder.getValue('devDependencies')).not.toBeUndefined();
|
||||||
|
expect(builder.getValue('peerDependencies')).not.toBeUndefined();
|
||||||
builder.fromJSON('{"dependencies":{}}');
|
|
||||||
builder.addDependencies(['eslint']);
|
|
||||||
expect(builder.getValue('dependencies').eslint).toBe(eslintVersion);
|
|
||||||
|
|
||||||
builder.fromJSON('{"dependencies":{}}');
|
|
||||||
builder.addDependencies('eslint', 'dependencies');
|
|
||||||
expect(builder.getValue('dependencies').eslint).toBe(eslintVersion);
|
|
||||||
|
|
||||||
builder.fromJSON('{"dependencies":{}}');
|
|
||||||
builder.addDependencies(['eslint'], 'dependencies');
|
|
||||||
expect(builder.getValue('dependencies').eslint).toBe(eslintVersion);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be able to add to devDependencies', function () {
|
|
||||||
builder.fromJSON('{"devDependencies":{}}');
|
|
||||||
builder.addDependencies('eslint', 'devDependencies');
|
|
||||||
expect(builder.getValue('devDependencies').eslint).toBe(eslintVersion);
|
|
||||||
|
|
||||||
builder.fromJSON('{"devDependencies":{}}');
|
|
||||||
builder.addDependencies(['eslint'], 'devDependencies');
|
|
||||||
expect(builder.getValue('devDependencies').eslint).toBe(eslintVersion);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be able to add to peerDependencies', function () {
|
|
||||||
builder.fromJSON('{"peerDependencies":{}}');
|
|
||||||
builder.addDependencies('eslint', 'peerDependencies');
|
|
||||||
expect(builder.getValue('peerDependencies').eslint).toBe(eslintVersion);
|
|
||||||
|
|
||||||
builder.fromJSON('{"peerDependencies":{}}');
|
|
||||||
builder.addDependencies(['eslint'], 'peerDependencies');
|
|
||||||
expect(builder.getValue('peerDependencies').eslint).toBe(eslintVersion);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create dependency maps if they don\'t yet exist in the package', function () {
|
|
||||||
builder.fromJSON('{}');
|
|
||||||
builder.addDependencies('eslint');
|
|
||||||
builder.addDependencies('eslint', 'devDependencies');
|
|
||||||
builder.addDependencies('eslint', 'peerDependencies');
|
|
||||||
expect(builder.getValue('dependencies')).not.toBeUndefined();
|
|
||||||
expect(builder.getValue('devDependencies')).not.toBeUndefined();
|
|
||||||
expect(builder.getValue('peerDependencies')).not.toBeUndefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not modify things if an invalid section was declared', function () {
|
|
||||||
builder.fromJSON('{}');
|
|
||||||
builder.addDependencies('eslint', 'lol');
|
|
||||||
expect(builder.getValues()).toEqual({});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not override an existing dependency declaration', function () {
|
|
||||||
builder.fromJSON('{"dependencies":{"eslint":"0.0.1"}}');
|
|
||||||
builder.addDependencies(['eslint'], 'dependencies');
|
|
||||||
expect(builder.getValue('dependencies').eslint).toEqual('0.0.1');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not add a dependency that is not globally managed', function () {
|
|
||||||
builder.fromJSON('{}');
|
|
||||||
builder.addDependencies('leftpad');
|
|
||||||
expect(builder.getValues()).toEqual({dependencies: {}});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('addCommand', function () {
|
it('should not modify things if an invalid section was declared', function () {
|
||||||
it('should add a command', function () {
|
builder.fromJSON('{}');
|
||||||
builder.fromJSON('{"scripts":{}}');
|
builder.addDependencies('eslint', 'lol');
|
||||||
builder.addCommand('foo', 'bar');
|
expect(builder.getValues()).toEqual({});
|
||||||
expect(builder.getValue('scripts').foo).toBe('bar');
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('should overwrite an existing command', function () {
|
it('should not override an existing dependency declaration', function () {
|
||||||
builder.fromJSON('{"scripts":{"foo":"bar"}}');
|
builder.fromJSON('{"dependencies":{"eslint":"0.0.1"}}');
|
||||||
builder.addCommand('foo', 'lol');
|
builder.addDependencies(['eslint'], 'dependencies');
|
||||||
expect(builder.getValue('scripts').foo).toBe('lol');
|
expect(builder.getValue('dependencies').eslint).toEqual('0.0.1');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create the scripts hash if it doesn\'t exist', function () {
|
it('should not add a dependency that is not globally managed', function () {
|
||||||
builder.fromJSON('{}');
|
builder.fromJSON('{}');
|
||||||
builder.addCommand('foo', 'bar');
|
builder.addDependencies('leftpad');
|
||||||
expect(builder.getValue('scripts')).toBeDefined();
|
expect(builder.getValues()).toEqual({dependencies: {}});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})();
|
|
||||||
|
describe('addCommand', function () {
|
||||||
|
it('should add a command', function () {
|
||||||
|
builder.fromJSON('{"scripts":{}}');
|
||||||
|
builder.addCommand('foo', 'bar');
|
||||||
|
expect(builder.getValue('scripts').foo).toBe('bar');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should overwrite an existing command', function () {
|
||||||
|
builder.fromJSON('{"scripts":{"foo":"bar"}}');
|
||||||
|
builder.addCommand('foo', 'lol');
|
||||||
|
expect(builder.getValue('scripts').foo).toBe('lol');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create the scripts hash if it doesn\'t exist', function () {
|
||||||
|
builder.fromJSON('{}');
|
||||||
|
builder.addCommand('foo', 'bar');
|
||||||
|
expect(builder.getValue('scripts')).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -14,61 +14,60 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
var builder = require('../../../generators/app/lib/project_builder');
|
|
||||||
|
|
||||||
describe('generator-openstack:lib/project_builder', function () {
|
var builder = require('../../../generators/app/lib/project_builder');
|
||||||
|
|
||||||
beforeEach(function () {
|
describe('generator-openstack:lib/project_builder', function () {
|
||||||
builder.clear();
|
|
||||||
|
beforeEach(function () {
|
||||||
|
builder.clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should start with an empty list of included files',
|
||||||
|
function () {
|
||||||
|
expect(builder.getIncludedFiles().length).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should start with an empty list of included files',
|
it('should start with an empty list of excluded files',
|
||||||
function () {
|
function () {
|
||||||
expect(builder.getIncludedFiles().length).toBe(0);
|
expect(builder.getExcludedFiles().length).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should start with an empty list of excluded files',
|
it('should permit adding a file with only one path.',
|
||||||
function () {
|
function () {
|
||||||
expect(builder.getExcludedFiles().length).toBe(0);
|
var testFilePath = 'test_path.json';
|
||||||
});
|
|
||||||
|
|
||||||
it('should permit adding a file with only one path.',
|
builder.addFile(testFilePath);
|
||||||
function () {
|
var testFile = builder.getIncludedFiles()[0];
|
||||||
var testFilePath = 'test_path.json';
|
|
||||||
|
|
||||||
builder.addFile(testFilePath);
|
expect(testFile.from).toBe(testFilePath);
|
||||||
var testFile = builder.getIncludedFiles()[0];
|
expect(testFile.to).toBe(testFilePath);
|
||||||
|
});
|
||||||
|
|
||||||
expect(testFile.from).toBe(testFilePath);
|
it('should permit adding a file with a different destination path.',
|
||||||
expect(testFile.to).toBe(testFilePath);
|
function () {
|
||||||
});
|
var testFilePath = 'test_path.json';
|
||||||
|
var testFileOutput = 'test_path_output.json';
|
||||||
|
|
||||||
it('should permit adding a file with a different destination path.',
|
builder.addFile(testFilePath, testFileOutput);
|
||||||
function () {
|
var testFile = builder.getIncludedFiles()[0];
|
||||||
var testFilePath = 'test_path.json';
|
|
||||||
var testFileOutput = 'test_path_output.json';
|
|
||||||
|
|
||||||
builder.addFile(testFilePath, testFileOutput);
|
expect(testFile.from).toBe(testFilePath);
|
||||||
var testFile = builder.getIncludedFiles()[0];
|
expect(testFile.to).toBe(testFileOutput);
|
||||||
|
});
|
||||||
|
|
||||||
expect(testFile.from).toBe(testFilePath);
|
it('should permit adding a file to the exclusion list',
|
||||||
expect(testFile.to).toBe(testFileOutput);
|
function () {
|
||||||
});
|
var testFilePath = 'test_path.json';
|
||||||
|
builder.removeFile(testFilePath);
|
||||||
|
expect(builder.getExcludedFiles()[0]).toBe(testFilePath);
|
||||||
|
});
|
||||||
|
|
||||||
it('should permit adding a file to the exclusion list',
|
it('should permit adding a file to the ignore list',
|
||||||
function () {
|
function () {
|
||||||
var testFilePath = 'test_path.json';
|
var testFilePath = 'test_path.json';
|
||||||
builder.removeFile(testFilePath);
|
builder.ignoreFile(testFilePath);
|
||||||
expect(builder.getExcludedFiles()[0]).toBe(testFilePath);
|
expect(builder.getIgnoredFiles()[0]).toBe(testFilePath);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
it('should permit adding a file to the ignore list',
|
|
||||||
function () {
|
|
||||||
var testFilePath = 'test_path.json';
|
|
||||||
builder.ignoreFile(testFilePath);
|
|
||||||
expect(builder.getIgnoredFiles()[0]).toBe(testFilePath);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})();
|
|
||||||
|
|
|
@ -14,67 +14,65 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
'use strict';
|
||||||
'use strict';
|
|
||||||
|
|
||||||
function buildMockGenerator (config, mockAnswers, mockOptions) {
|
function buildMockGenerator (config, mockAnswers, mockOptions) {
|
||||||
var configDefaults = {};
|
var configDefaults = {};
|
||||||
var memFs = require('mem-fs');
|
var memFs = require('mem-fs');
|
||||||
var editor = require('mem-fs-editor');
|
var editor = require('mem-fs-editor');
|
||||||
var store = memFs.create();
|
var store = memFs.create();
|
||||||
|
|
||||||
config = config || {};
|
config = config || {};
|
||||||
mockAnswers = mockAnswers || {};
|
mockAnswers = mockAnswers || {};
|
||||||
mockOptions = mockOptions || {};
|
mockOptions = mockOptions || {};
|
||||||
|
|
||||||
return {
|
|
||||||
fs: editor.create(store),
|
|
||||||
appname: 'generator-openstack',
|
|
||||||
async: function () {
|
|
||||||
return function () {
|
|
||||||
};
|
|
||||||
},
|
|
||||||
config: {
|
|
||||||
defaults: function (values) {
|
|
||||||
Object.keys(values).forEach(function (key) {
|
|
||||||
configDefaults[key] = values[key];
|
|
||||||
});
|
|
||||||
},
|
|
||||||
get: function (value) {
|
|
||||||
return config[value] || configDefaults[value];
|
|
||||||
},
|
|
||||||
set: function (key, value) {
|
|
||||||
if (typeof key === 'object') {
|
|
||||||
Object.keys(key).forEach(function (index) {
|
|
||||||
config[index] = key[index];
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
config[key] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
prompt: function (params, callback) {
|
|
||||||
var answers = {};
|
|
||||||
params.forEach(function (param) {
|
|
||||||
|
|
||||||
if (param.when && !param.when(answers)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mockAnswers.hasOwnProperty(param.name)) {
|
|
||||||
answers[param.name] = mockAnswers[param.name];
|
|
||||||
} else {
|
|
||||||
answers[param.name] = param.default || null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return {
|
||||||
|
fs: editor.create(store),
|
||||||
|
appname: 'generator-openstack',
|
||||||
|
async: function () {
|
||||||
|
return function () {
|
||||||
|
};
|
||||||
|
},
|
||||||
|
config: {
|
||||||
|
defaults: function (values) {
|
||||||
|
Object.keys(values).forEach(function (key) {
|
||||||
|
configDefaults[key] = values[key];
|
||||||
});
|
});
|
||||||
callback(answers);
|
|
||||||
},
|
},
|
||||||
options: mockOptions
|
get: function (value) {
|
||||||
};
|
return config[value] || configDefaults[value];
|
||||||
}
|
},
|
||||||
|
set: function (key, value) {
|
||||||
|
if (typeof key === 'object') {
|
||||||
|
Object.keys(key).forEach(function (index) {
|
||||||
|
config[index] = key[index];
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
config[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
prompt: function (params, callback) {
|
||||||
|
var answers = {};
|
||||||
|
params.forEach(function (param) {
|
||||||
|
|
||||||
module.exports = {
|
if (param.when && !param.when(answers)) {
|
||||||
buildGenerator: buildMockGenerator
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mockAnswers.hasOwnProperty(param.name)) {
|
||||||
|
answers[param.name] = mockAnswers[param.name];
|
||||||
|
} else {
|
||||||
|
answers[param.name] = param.default || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
callback(answers);
|
||||||
|
},
|
||||||
|
options: mockOptions
|
||||||
};
|
};
|
||||||
})();
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
buildGenerator: buildMockGenerator
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue