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:
|
||||
node: true
|
||||
jasmine: true
|
||||
rules:
|
||||
strict: ["error", "global"]
|
||||
|
|
|
@ -14,118 +14,116 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
var yeoman = require('yeoman-generator');
|
||||
var projectBuilder = require('./lib/project_builder');
|
||||
var Q = require('q');
|
||||
var yeoman = require('yeoman-generator');
|
||||
var projectBuilder = require('./lib/project_builder');
|
||||
var Q = require('q');
|
||||
|
||||
var pkg = require('./lib/component/pkg');
|
||||
var gerrit = require('./lib/component/gerrit');
|
||||
var editorconfig = require('./lib/component/editorconfig');
|
||||
var license = require('./lib/component/license');
|
||||
var structure = require('./lib/component/structure');
|
||||
var eslint = require('./lib/component/eslint');
|
||||
var gitignore = require('./lib/component/gitignore');
|
||||
var nsp = require('./lib/component/nsp');
|
||||
var pkg = require('./lib/component/pkg');
|
||||
var gerrit = require('./lib/component/gerrit');
|
||||
var editorconfig = require('./lib/component/editorconfig');
|
||||
var license = require('./lib/component/license');
|
||||
var structure = require('./lib/component/structure');
|
||||
var eslint = require('./lib/component/eslint');
|
||||
var gitignore = require('./lib/component/gitignore');
|
||||
var nsp = require('./lib/component/nsp');
|
||||
|
||||
module.exports = yeoman.Base.extend({
|
||||
module.exports = yeoman.Base.extend({
|
||||
|
||||
constructor: function () {
|
||||
yeoman.Base.apply(this, arguments);
|
||||
constructor: function () {
|
||||
yeoman.Base.apply(this, arguments);
|
||||
|
||||
// Add support for a `--non-interactive` flag
|
||||
this.option('non-interactive');
|
||||
// Add support for a `--non-interactive` flag
|
||||
this.option('non-interactive');
|
||||
|
||||
// If non-interactive is set, force-override all files.
|
||||
this.conflicter.force = this.options['non-interactive'];
|
||||
},
|
||||
// If non-interactive is set, force-override all files.
|
||||
this.conflicter.force = this.options['non-interactive'];
|
||||
},
|
||||
|
||||
initializing: function () {
|
||||
var done = this.async();
|
||||
initializing: function () {
|
||||
var done = this.async();
|
||||
|
||||
// Initialize components.
|
||||
Q(this)
|
||||
.then(pkg.init) // Package.json
|
||||
.then(gerrit.init) // Gerrit
|
||||
.then(editorconfig.init) // Editorconfig
|
||||
.then(license.init) // Licensing
|
||||
.then(structure.init) // Project Structure
|
||||
.then(eslint.init) // Linting
|
||||
.then(gitignore.init) // Gitignore
|
||||
.then(nsp.init) // NSP
|
||||
.then(function () {
|
||||
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
|
||||
);
|
||||
}
|
||||
// Initialize components.
|
||||
Q(this)
|
||||
.then(pkg.init) // Package.json
|
||||
.then(gerrit.init) // Gerrit
|
||||
.then(editorconfig.init) // Editorconfig
|
||||
.then(license.init) // Licensing
|
||||
.then(structure.init) // Project Structure
|
||||
.then(eslint.init) // Linting
|
||||
.then(gitignore.init) // Gitignore
|
||||
.then(nsp.init) // NSP
|
||||
.then(function () {
|
||||
done();
|
||||
});
|
||||
},
|
||||
|
||||
// Delete all files explicitly excluded in the project builder.
|
||||
excluded.forEach(function (path) {
|
||||
self.fs.delete(self.destinationPath(path));
|
||||
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();
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
install: function () {
|
||||
this.npmInstall();
|
||||
}
|
||||
});
|
||||
})();
|
||||
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.
|
||||
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
|
||||
* under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
var projectBuilder = require('../project_builder');
|
||||
|
||||
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.
|
||||
*
|
||||
* @param {generator} generator The currently active generator.
|
||||
* @returns {generator} The passed generator, for promise chaining.
|
||||
*/
|
||||
function noop (generator) {
|
||||
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 configureEC (generator) {
|
||||
projectBuilder.addFile('.editorconfig');
|
||||
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 configureEC (generator) {
|
||||
projectBuilder.addFile('.editorconfig');
|
||||
return generator;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: noop,
|
||||
prompt: noop,
|
||||
configure: configureEC
|
||||
};
|
||||
})();
|
||||
module.exports = {
|
||||
init: noop,
|
||||
prompt: noop,
|
||||
configure: configureEC
|
||||
};
|
||||
|
|
|
@ -14,115 +14,113 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
var pkgBuilder = require('../pkg_builder');
|
||||
var projectBuilder = require('../project_builder');
|
||||
var yaml = require('js-yaml');
|
||||
var pkgBuilder = require('../pkg_builder');
|
||||
var projectBuilder = require('../project_builder');
|
||||
var yaml = require('js-yaml');
|
||||
|
||||
var excludedPaths = [];
|
||||
var ignoreFile = '.eslintignore';
|
||||
var rcFile = '.eslintrc';
|
||||
var eslintrc = {extends: 'openstack'};
|
||||
var excludedPaths = [];
|
||||
var ignoreFile = '.eslintignore';
|
||||
var rcFile = '.eslintrc';
|
||||
var eslintrc = {extends: 'openstack'};
|
||||
|
||||
/**
|
||||
* This method configures the package builder with all options necessary to support eslint.
|
||||
*
|
||||
* @param {generator} generator The currently active generator.
|
||||
* @returns {generator} The passed generator, for promise chaining.
|
||||
*/
|
||||
function promptEslint (generator) {
|
||||
// At this time, we don't actually need to prompt the user.
|
||||
/**
|
||||
* This method configures the package builder with all options necessary to support eslint.
|
||||
*
|
||||
* @param {generator} generator The currently active generator.
|
||||
* @returns {generator} The passed generator, for promise chaining.
|
||||
*/
|
||||
function promptEslint (generator) {
|
||||
// At this time, we don't actually need to prompt the user.
|
||||
|
||||
// Add the dependencies.
|
||||
pkgBuilder.addDependencies(['eslint', 'eslint-config-openstack'], 'devDependencies');
|
||||
pkgBuilder.addCommand('lint', 'eslint ./');
|
||||
// Add the dependencies.
|
||||
pkgBuilder.addDependencies(['eslint', 'eslint-config-openstack'], 'devDependencies');
|
||||
pkgBuilder.addCommand('lint', 'eslint ./');
|
||||
|
||||
return generator;
|
||||
}
|
||||
return generator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the existing .eslintrc and .eslintignore files, and populate our initial configuration
|
||||
* with them.
|
||||
*
|
||||
* @param {generator} generator The currently active generator.
|
||||
* @returns {generator} The passed generator, for promise chaining.
|
||||
*/
|
||||
function initializeEslint (generator) {
|
||||
var fs = generator.fs;
|
||||
/**
|
||||
* Read the existing .eslintrc and .eslintignore files, and populate our initial configuration
|
||||
* with them.
|
||||
*
|
||||
* @param {generator} generator The currently active generator.
|
||||
* @returns {generator} The passed generator, for promise chaining.
|
||||
*/
|
||||
function initializeEslint (generator) {
|
||||
var fs = generator.fs;
|
||||
|
||||
// Re-initialize excluded paths.
|
||||
excludedPaths = [];
|
||||
// Re-initialize excluded paths.
|
||||
excludedPaths = [];
|
||||
|
||||
// Read .eslintignore.
|
||||
if (fs.exists(ignoreFile)) {
|
||||
var paths = fs.read(ignoreFile)
|
||||
.split('\n')
|
||||
.filter(function (item) {
|
||||
// Remove empty lines.
|
||||
return item.length > 0;
|
||||
});
|
||||
|
||||
paths.forEach(function (item) {
|
||||
excludedPaths.push(item);
|
||||
// Read .eslintignore.
|
||||
if (fs.exists(ignoreFile)) {
|
||||
var paths = fs.read(ignoreFile)
|
||||
.split('\n')
|
||||
.filter(function (item) {
|
||||
// Remove empty lines.
|
||||
return item.length > 0;
|
||||
});
|
||||
}
|
||||
|
||||
// Read .eslintrc
|
||||
if (fs.exists(rcFile)) {
|
||||
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);
|
||||
}
|
||||
paths.forEach(function (item) {
|
||||
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);
|
||||
// Read .eslintrc
|
||||
if (fs.exists(rcFile)) {
|
||||
eslintrc = yaml.safeLoad(fs.read(rcFile));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: initializeEslint,
|
||||
prompt: promptEslint,
|
||||
configure: configureEslint
|
||||
};
|
||||
})();
|
||||
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');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
var projectBuilder = require('../project_builder');
|
||||
var pkgBuilder = require('../pkg_builder');
|
||||
var ini = require('ini');
|
||||
var Q = require('q');
|
||||
var projectBuilder = require('../project_builder');
|
||||
var pkgBuilder = require('../pkg_builder');
|
||||
var ini = require('ini');
|
||||
var Q = require('q');
|
||||
|
||||
var gerritFile = '.gitreview';
|
||||
var iniContent;
|
||||
var gerritFileExists = false;
|
||||
var gerritFile = '.gitreview';
|
||||
var iniContent;
|
||||
var gerritFileExists = false;
|
||||
|
||||
/**
|
||||
* Internal helper method. Returns true if gerrit has been enabled.
|
||||
*
|
||||
* @param {String} answers The collection of answers.
|
||||
* @returns {Function} True if enableGerrit is set, otherwise false.
|
||||
*/
|
||||
var gerritEnabled = function(answers) {
|
||||
return !!answers.enableGerrit;
|
||||
/**
|
||||
* Internal helper method. Returns true if gerrit has been enabled.
|
||||
*
|
||||
* @param {String} answers The collection of answers.
|
||||
* @returns {Function} True if enableGerrit is set, otherwise false.
|
||||
*/
|
||||
var gerritEnabled = function(answers) {
|
||||
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
|
||||
* 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
|
||||
* 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.fs.exists(gerritFile)) {
|
||||
gerritFileExists = true;
|
||||
iniContent = ini.parse(generator.fs.read(gerritFile));
|
||||
} else {
|
||||
// Create project name from package name if gerrit file does not exist
|
||||
var projectName = pkgBuilder.getValue("name");
|
||||
iniContent.gerrit.project = 'openstack/' + projectName + '.git';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
var deferred = Q.defer();
|
||||
|
||||
// Read the existing file and populate it as defaults.
|
||||
if (generator.fs.exists(gerritFile)) {
|
||||
gerritFileExists = true;
|
||||
iniContent = ini.parse(generator.fs.read(gerritFile));
|
||||
} else {
|
||||
// Create project name from package name if gerrit file does not exist
|
||||
var projectName = pkgBuilder.getValue("name");
|
||||
iniContent.gerrit.project = 'openstack/' + projectName + '.git';
|
||||
}
|
||||
if (!generator.options['non-interactive']) {
|
||||
// Go through the prompts.
|
||||
generator.prompt(
|
||||
[{
|
||||
type: 'confirm',
|
||||
name: 'enableGerrit',
|
||||
message: 'Gerrit- Enable:',
|
||||
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();
|
||||
|
||||
if (!generator.options['non-interactive']) {
|
||||
// Go through the prompts.
|
||||
generator.prompt(
|
||||
[{
|
||||
type: 'confirm',
|
||||
name: 'enableGerrit',
|
||||
message: 'Gerrit- Enable:',
|
||||
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;
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
return generator;
|
||||
}
|
||||
function buildGerritFile () {
|
||||
return ini.stringify(iniContent);
|
||||
}
|
||||
|
||||
function buildGerritFile () {
|
||||
return ini.stringify(iniContent);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: initializeGerrit,
|
||||
prompt: promptUserOptions,
|
||||
configure: configureGerrit
|
||||
};
|
||||
})
|
||||
();
|
||||
module.exports = {
|
||||
init: initializeGerrit,
|
||||
prompt: promptUserOptions,
|
||||
configure: configureGerrit
|
||||
};
|
||||
|
|
|
@ -14,92 +14,90 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
var projectBuilder = require('../project_builder');
|
||||
var projectBuilder = require('../project_builder');
|
||||
|
||||
var excludedPaths = {};
|
||||
var filePath = '.gitignore';
|
||||
var excludedPaths = {};
|
||||
var filePath = '.gitignore';
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param {generator} generator The currently active generator.
|
||||
* @returns {generator} The passed generator, for promise chaining.
|
||||
*/
|
||||
function noop (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;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
return generator;
|
||||
}
|
||||
|
||||
// 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.
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 generator;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 Object.keys(excludedPaths).sort().join('\n');
|
||||
}
|
||||
|
||||
return generator;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
};
|
||||
})();
|
||||
module.exports = {
|
||||
init: initGitignore,
|
||||
prompt: noop,
|
||||
configure: configureGitIgnore
|
||||
};
|
||||
|
|
|
@ -14,38 +14,36 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
var projectBuilder = require('../project_builder');
|
||||
var pkgBuilder = require('../pkg_builder');
|
||||
var projectBuilder = require('../project_builder');
|
||||
var pkgBuilder = require('../pkg_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.
|
||||
*
|
||||
* @param {generator} generator The currently active generator.
|
||||
* @returns {generator} The passed generator, for promise chaining.
|
||||
*/
|
||||
function noop (generator) {
|
||||
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 configureLicense (generator) {
|
||||
projectBuilder.addFile('LICENSE');
|
||||
pkgBuilder.setValues({license: 'Apache-2.0'});
|
||||
/**
|
||||
* Configure the project by adding required files.
|
||||
*
|
||||
* @param {generator} generator The currently active generator.
|
||||
* @returns {generator} The passed generator, for promise chaining.
|
||||
*/
|
||||
function configureLicense (generator) {
|
||||
projectBuilder.addFile('LICENSE');
|
||||
pkgBuilder.setValues({license: 'Apache-2.0'});
|
||||
|
||||
return generator;
|
||||
}
|
||||
return generator;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: noop,
|
||||
prompt: noop,
|
||||
configure: configureLicense
|
||||
};
|
||||
})();
|
||||
module.exports = {
|
||||
init: noop,
|
||||
prompt: noop,
|
||||
configure: configureLicense
|
||||
};
|
||||
|
|
|
@ -19,53 +19,52 @@
|
|||
* Its job is to identify known vulnerabilities by scanning the projects
|
||||
* source and dependencies.
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var projectBuilder = require('../project_builder');
|
||||
var pkgBuilder = require('../pkg_builder');
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
var projectBuilder = require('../project_builder');
|
||||
var pkgBuilder = require('../pkg_builder');
|
||||
|
||||
/**
|
||||
* This method configures the package builder with all options necessary
|
||||
* 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.
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
// Add the dependencies.
|
||||
pkgBuilder.addDependencies(['nsp'], 'devDependencies');
|
||||
pkgBuilder.addCommand('prepublish', 'nsp check');
|
||||
/**
|
||||
* This method configures the package builder with all options necessary
|
||||
* 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');
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
return generator;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: noop,
|
||||
prompt: promptNsp,
|
||||
configure: configureNsp
|
||||
};
|
||||
})();
|
||||
/**
|
||||
* 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,
|
||||
prompt: promptNsp,
|
||||
configure: configureNsp
|
||||
};
|
||||
|
|
|
@ -14,110 +14,108 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
var Q = require('q');
|
||||
var hyphenize = require('hyphenize');
|
||||
var pkgBuilder = require('../pkg_builder');
|
||||
var projectBuilder = require('../project_builder');
|
||||
var Q = require('q');
|
||||
var hyphenize = require('hyphenize');
|
||||
var pkgBuilder = require('../pkg_builder');
|
||||
var projectBuilder = require('../project_builder');
|
||||
|
||||
var packagePath = 'package.json';
|
||||
var packagePath = 'package.json';
|
||||
|
||||
/**
|
||||
* Iterate over needed package components, ensuring that required
|
||||
* parameters are set.
|
||||
*
|
||||
* @param {generator} generator The currently active generator.
|
||||
* @returns {generator} The passed generator, for promise chaining.
|
||||
*/
|
||||
function promptPackage (generator) {
|
||||
var deferred = Q.defer();
|
||||
/**
|
||||
* Iterate over needed package components, ensuring that required
|
||||
* parameters are set.
|
||||
*
|
||||
* @param {generator} generator The currently active generator.
|
||||
* @returns {generator} The passed generator, for promise chaining.
|
||||
*/
|
||||
function promptPackage (generator) {
|
||||
var deferred = Q.defer();
|
||||
|
||||
if (!generator.options['non-interactive']) {
|
||||
generator.prompt(
|
||||
[{
|
||||
type: 'input',
|
||||
name: 'name',
|
||||
message: 'Project- Name:',
|
||||
default: pkgBuilder.getValue('name', hyphenize(generator.appname))
|
||||
}, {
|
||||
type: 'input',
|
||||
name: 'description',
|
||||
message: 'Project- Description:',
|
||||
default: pkgBuilder.getValue('description')
|
||||
}, {
|
||||
type: 'input',
|
||||
name: 'version',
|
||||
message: 'Project- Version:',
|
||||
default: pkgBuilder.getValue('version', '0.0.1')
|
||||
}, {
|
||||
type: 'input',
|
||||
name: 'homepage',
|
||||
message: 'Project- Homepage:',
|
||||
default: pkgBuilder.getValue('homepage', 'http://www.openstack.org/')
|
||||
}, {
|
||||
type: 'input',
|
||||
name: 'author',
|
||||
message: 'Project- Author:',
|
||||
default: pkgBuilder.getValue('author',
|
||||
'OpenStack <openstack-dev@lists.openstack.org> (http://www.openstack.org/)')
|
||||
}],
|
||||
function (answers) {
|
||||
pkgBuilder.setValues(answers);
|
||||
deferred.resolve(generator);
|
||||
});
|
||||
} else {
|
||||
deferred.resolve(generator);
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
if (!generator.options['non-interactive']) {
|
||||
generator.prompt(
|
||||
[{
|
||||
type: 'input',
|
||||
name: 'name',
|
||||
message: 'Project- Name:',
|
||||
default: pkgBuilder.getValue('name', hyphenize(generator.appname))
|
||||
}, {
|
||||
type: 'input',
|
||||
name: 'description',
|
||||
message: 'Project- Description:',
|
||||
default: pkgBuilder.getValue('description')
|
||||
}, {
|
||||
type: 'input',
|
||||
name: 'version',
|
||||
message: 'Project- Version:',
|
||||
default: pkgBuilder.getValue('version', '0.0.1')
|
||||
}, {
|
||||
type: 'input',
|
||||
name: 'homepage',
|
||||
message: 'Project- Homepage:',
|
||||
default: pkgBuilder.getValue('homepage', 'http://www.openstack.org/')
|
||||
}, {
|
||||
type: 'input',
|
||||
name: 'author',
|
||||
message: 'Project- Author:',
|
||||
default: pkgBuilder.getValue('author',
|
||||
'OpenStack <openstack-dev@lists.openstack.org> (http://www.openstack.org/)')
|
||||
}],
|
||||
function (answers) {
|
||||
pkgBuilder.setValues(answers);
|
||||
deferred.resolve(generator);
|
||||
});
|
||||
} else {
|
||||
deferred.resolve(generator);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
// Read package.json
|
||||
if (fs.exists(packagePath)) {
|
||||
pkgBuilder.fromJSON(fs.read(packagePath));
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
|
||||
// Add files that should be ignored overall.
|
||||
projectBuilder.ignoreFile('node_modules');
|
||||
// NPM execution failures.
|
||||
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;
|
||||
// Read package.json
|
||||
if (fs.exists(packagePath)) {
|
||||
pkgBuilder.fromJSON(fs.read(packagePath));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
// Add files that should be ignored overall.
|
||||
projectBuilder.ignoreFile('node_modules');
|
||||
// NPM execution failures.
|
||||
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');
|
||||
|
||||
module.exports = {
|
||||
init: initializePackage,
|
||||
prompt: promptPackage,
|
||||
configure: configurePkg
|
||||
};
|
||||
})();
|
||||
var devDeps = ['istanbul', 'jasmine'];
|
||||
|
||||
pkgBuilder.addDependencies(devDeps, 'devDependencies');
|
||||
|
||||
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,
|
||||
* and/or configuration files.
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var Q = require('q');
|
||||
var projectBuilder = require('../project_builder');
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Initialize the component by setting configuration defaults. These, or previously set
|
||||
* 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) {
|
||||
var Q = require('q');
|
||||
var projectBuilder = require('../project_builder');
|
||||
|
||||
// Set our defaults:
|
||||
generator.config.defaults({
|
||||
engine: 'browser',
|
||||
language: 'es5',
|
||||
srcDir: './src',
|
||||
distDir: './dist',
|
||||
testDir: './test'
|
||||
});
|
||||
/**
|
||||
* Initialize the component by setting configuration defaults. These, or previously set
|
||||
* 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) {
|
||||
|
||||
return generator;
|
||||
}
|
||||
// Set our defaults:
|
||||
generator.config.defaults({
|
||||
engine: 'browser',
|
||||
language: 'es5',
|
||||
srcDir: './src',
|
||||
distDir: './dist',
|
||||
testDir: './test'
|
||||
});
|
||||
|
||||
/**
|
||||
* 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();
|
||||
return generator;
|
||||
}
|
||||
|
||||
// We default to a node.js project.
|
||||
if (!generator.options['non-interactive']) {
|
||||
// Go through the prompts.
|
||||
generator.prompt(
|
||||
[{
|
||||
type: 'list',
|
||||
name: 'engine',
|
||||
message: 'Structure- Runtime Engine:',
|
||||
choices: [
|
||||
{
|
||||
name: 'Browser',
|
||||
value: 'browser'
|
||||
},
|
||||
{
|
||||
name: 'Node.js',
|
||||
value: 'node'
|
||||
}
|
||||
],
|
||||
default: generator.config.get('engine')
|
||||
}, {
|
||||
type: 'list',
|
||||
name: 'language',
|
||||
message: 'Structure- Language:',
|
||||
choices: [
|
||||
{
|
||||
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';
|
||||
/**
|
||||
* 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']) {
|
||||
// Go through the prompts.
|
||||
generator.prompt(
|
||||
[{
|
||||
type: 'list',
|
||||
name: 'engine',
|
||||
message: 'Structure- Runtime Engine:',
|
||||
choices: [
|
||||
{
|
||||
name: 'Browser',
|
||||
value: 'browser'
|
||||
},
|
||||
{
|
||||
name: 'Node.js',
|
||||
value: 'node'
|
||||
}
|
||||
}],
|
||||
function (answers) {
|
||||
generator.config.set(answers);
|
||||
deferred.resolve(generator);
|
||||
});
|
||||
} else {
|
||||
deferred.resolve(generator);
|
||||
}
|
||||
return deferred.promise;
|
||||
],
|
||||
default: generator.config.get('engine')
|
||||
}, {
|
||||
type: 'list',
|
||||
name: 'language',
|
||||
message: 'Structure- Language:',
|
||||
choices: [
|
||||
{
|
||||
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.
|
||||
*
|
||||
* @param {generator} generator The currently active generator.
|
||||
* @returns {generator} The passed generator, for promise chaining.
|
||||
*/
|
||||
function configure (generator) {
|
||||
projectBuilder.ignoreFile(generator.config.get('distDir'));
|
||||
return generator;
|
||||
}
|
||||
/**
|
||||
* Add any output directories to the ignore files.
|
||||
*
|
||||
* @param {generator} generator The currently active generator.
|
||||
* @returns {generator} The passed generator, for promise chaining.
|
||||
*/
|
||||
function configure (generator) {
|
||||
projectBuilder.ignoreFile(generator.config.get('distDir'));
|
||||
return generator;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: initialize,
|
||||
prompt: prompt,
|
||||
configure: configure
|
||||
};
|
||||
})();
|
||||
module.exports = {
|
||||
init: initialize,
|
||||
prompt: prompt,
|
||||
configure: configure
|
||||
};
|
||||
|
|
|
@ -13,57 +13,55 @@
|
|||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Access to the global-dependencies.json file.
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var globalDependencies = require('../../../global-dependencies.json');
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
var globalDependencies = require('../../../global-dependencies.json');
|
||||
|
||||
/**
|
||||
* Return the current acceptable version of the dependencies, or null.
|
||||
*
|
||||
* @param {String} name The dependency name.
|
||||
* @returns {String|undefined} The version, or undefined.
|
||||
*/
|
||||
function getVersion (name) {
|
||||
return globalDependencies[name] || undefined;
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a list of dependencies, updates this list of dependencies to the versions that are
|
||||
* currently set in global-dependencies.
|
||||
*
|
||||
* @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 the current acceptable version of the dependencies, or null.
|
||||
*
|
||||
* @param {String} name The dependency name.
|
||||
* @returns {String|undefined} The version, or undefined.
|
||||
*/
|
||||
function getVersion (name) {
|
||||
return globalDependencies[name] || undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a list of dependencies, updates this list of dependencies to the versions that are
|
||||
* currently set in global-dependencies.
|
||||
*
|
||||
* @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 = {
|
||||
contains: containsDependency,
|
||||
read: getVersion,
|
||||
synchronize: synchronizeDependencies
|
||||
};
|
||||
})();
|
||||
module.exports = {
|
||||
contains: containsDependency,
|
||||
read: getVersion,
|
||||
synchronize: synchronizeDependencies
|
||||
};
|
||||
|
|
|
@ -14,153 +14,151 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
var dependencies = require('./global_dependencies');
|
||||
var pkgContent = {};
|
||||
var dependencies = require('./global_dependencies');
|
||||
var pkgContent = {};
|
||||
|
||||
/**
|
||||
* Convert a package.json formatted list of dependencies and update them to the versions
|
||||
* listed in our global dependencies.
|
||||
*
|
||||
* @param {{}} dependencyMap The map of dependencies.
|
||||
* @returns {{}} A clone of the map, updated with current common versions.
|
||||
*/
|
||||
function synchronizeDependencies (dependencyMap) {
|
||||
if (!dependencyMap) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Cloning not necessary, handled in dependencies.synchronize();
|
||||
return dependencies.synchronize(dependencyMap);
|
||||
/**
|
||||
* Convert a package.json formatted list of dependencies and update them to the versions
|
||||
* listed in our global dependencies.
|
||||
*
|
||||
* @param {{}} dependencyMap The map of dependencies.
|
||||
* @returns {{}} A clone of the map, updated with current common versions.
|
||||
*/
|
||||
function synchronizeDependencies (dependencyMap) {
|
||||
if (!dependencyMap) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize this builder from a JSON string.
|
||||
*
|
||||
* @param {String} pkgString The package string content.
|
||||
* @returns {void}
|
||||
*/
|
||||
function readPackage (pkgString) {
|
||||
pkgContent = JSON.parse(pkgString);
|
||||
// Cloning not necessary, handled in dependencies.synchronize();
|
||||
return dependencies.synchronize(dependencyMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize this builder from a JSON string.
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
// Default the array.
|
||||
if (!Array.isArray(libraryNames)) {
|
||||
libraryNames = [libraryNames];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
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;
|
||||
}
|
||||
});
|
||||
// Make sure the property exists.
|
||||
if (!pkgContent.hasOwnProperty(type)) {
|
||||
pkgContent[type] = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* 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];
|
||||
}
|
||||
// Add the dependency
|
||||
libraryNames.forEach(function (library) {
|
||||
var version = dependencies.read(library);
|
||||
if (version && !pkgContent[type].hasOwnProperty(library)) {
|
||||
pkgContent[type][library] = version;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @returns {{}} A cloned map of the values.
|
||||
*/
|
||||
function getValues () {
|
||||
return JSON.parse(JSON.stringify(pkgContent));
|
||||
/**
|
||||
* Get the values of the current package.
|
||||
*
|
||||
* @returns {{}} A cloned map of the values.
|
||||
*/
|
||||
function getValues () {
|
||||
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 = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
// Save/Override the command.
|
||||
pkgContent.scripts[name] = command;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
pkgContent.scripts[name] = command;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fromJSON: readPackage,
|
||||
toJSON: writePackage,
|
||||
setValues: setValues,
|
||||
getValues: getValues,
|
||||
getValue: getValue,
|
||||
addDependencies: addDependencies,
|
||||
addCommand: addCommand
|
||||
};
|
||||
})();
|
||||
module.exports = {
|
||||
fromJSON: readPackage,
|
||||
toJSON: writePackage,
|
||||
setValues: setValues,
|
||||
getValues: getValues,
|
||||
getValue: getValue,
|
||||
addDependencies: addDependencies,
|
||||
addCommand: addCommand
|
||||
};
|
||||
|
|
|
@ -14,105 +14,103 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
var includedFiles = [];
|
||||
var excludedFiles = [];
|
||||
var ignoredFiles = [];
|
||||
var includedFiles = [];
|
||||
var excludedFiles = [];
|
||||
var ignoredFiles = [];
|
||||
|
||||
/**
|
||||
* Ensure that a file is removed, or not present, in the project.
|
||||
*
|
||||
* @param {String} destinationPath Path to the file, relative to output root.
|
||||
* @returns {void}
|
||||
*/
|
||||
function removeFile (destinationPath) {
|
||||
excludedFiles.push(destinationPath);
|
||||
}
|
||||
/**
|
||||
* Ensure that a file is removed, or not present, in the project.
|
||||
*
|
||||
* @param {String} destinationPath Path to the file, relative to output root.
|
||||
* @returns {void}
|
||||
*/
|
||||
function removeFile (destinationPath) {
|
||||
excludedFiles.push(destinationPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag a file path as 'ignored'.
|
||||
*
|
||||
* 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
|
||||
* behavior accordingly. For example, eslint could use this to generate .eslintignore
|
||||
*
|
||||
* @param {String} destinationPath Path to the file, relative to output root.
|
||||
* @returns {void}
|
||||
*/
|
||||
function ignoreFile (destinationPath) {
|
||||
ignoredFiles.push(destinationPath);
|
||||
}
|
||||
/**
|
||||
* Flag a file path as 'ignored'.
|
||||
*
|
||||
* 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
|
||||
* behavior accordingly. For example, eslint could use this to generate .eslintignore
|
||||
*
|
||||
* @param {String} destinationPath Path to the file, relative to output root.
|
||||
* @returns {void}
|
||||
*/
|
||||
function ignoreFile (destinationPath) {
|
||||
ignoredFiles.push(destinationPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a file to the project.
|
||||
*
|
||||
* @param {String} sourcePath Path to the file, relative to ./templates/
|
||||
* @param {String} destinationPath Destination path relative to output root.
|
||||
* @returns {void}
|
||||
*/
|
||||
function addFile (sourcePath, destinationPath) {
|
||||
includedFiles.push({from: sourcePath, to: destinationPath || sourcePath});
|
||||
}
|
||||
/**
|
||||
* Add a file to the project.
|
||||
*
|
||||
* @param {String} sourcePath Path to the file, relative to ./templates/
|
||||
* @param {String} destinationPath Destination path relative to output root.
|
||||
* @returns {void}
|
||||
*/
|
||||
function addFile (sourcePath, destinationPath) {
|
||||
includedFiles.push({from: sourcePath, to: destinationPath || sourcePath});
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a file to the project.
|
||||
*
|
||||
* @param {String} destinationPath The destination for the file.
|
||||
* @param {String|Function} content A string of content, or method that returns one.
|
||||
* @returns {void}
|
||||
*/
|
||||
function writeFile (destinationPath, content) {
|
||||
includedFiles.push({to: destinationPath, content: content});
|
||||
}
|
||||
/**
|
||||
* Write a file to the project.
|
||||
*
|
||||
* @param {String} destinationPath The destination for the file.
|
||||
* @param {String|Function} content A string of content, or method that returns one.
|
||||
* @returns {void}
|
||||
*/
|
||||
function writeFile (destinationPath, content) {
|
||||
includedFiles.push({to: destinationPath, content: content});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all files that are to be included.
|
||||
*
|
||||
* @returns {Array} A list of all file mappings: {from:, to:}
|
||||
*/
|
||||
function getIncludedFiles () {
|
||||
return includedFiles;
|
||||
}
|
||||
/**
|
||||
* Get a list of all files that are to be included.
|
||||
*
|
||||
* @returns {Array} A list of all file mappings: {from:, to:}
|
||||
*/
|
||||
function getIncludedFiles () {
|
||||
return includedFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all file paths that should be excluded.
|
||||
*
|
||||
* @returns {Array} A list of file paths.
|
||||
*/
|
||||
function getExcludedFiles () {
|
||||
return excludedFiles;
|
||||
}
|
||||
/**
|
||||
* Get a list of all file paths that should be excluded.
|
||||
*
|
||||
* @returns {Array} A list of file paths.
|
||||
*/
|
||||
function getExcludedFiles () {
|
||||
return excludedFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all file paths that should be ignored.
|
||||
*
|
||||
* @returns {Array} A list of file paths.
|
||||
*/
|
||||
function getIgnoredFiles () {
|
||||
return ignoredFiles;
|
||||
}
|
||||
/**
|
||||
* Get a list of all file paths that should be ignored.
|
||||
*
|
||||
* @returns {Array} A list of file paths.
|
||||
*/
|
||||
function getIgnoredFiles () {
|
||||
return ignoredFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the current configuration.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
function clearAll () {
|
||||
includedFiles = [];
|
||||
excludedFiles = [];
|
||||
ignoredFiles = [];
|
||||
}
|
||||
/**
|
||||
* Clear the current configuration.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
function clearAll () {
|
||||
includedFiles = [];
|
||||
excludedFiles = [];
|
||||
ignoredFiles = [];
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
addFile: addFile,
|
||||
writeFile: writeFile,
|
||||
removeFile: removeFile,
|
||||
ignoreFile: ignoreFile,
|
||||
getIncludedFiles: getIncludedFiles,
|
||||
getIgnoredFiles: getIgnoredFiles,
|
||||
getExcludedFiles: getExcludedFiles,
|
||||
clear: clearAll
|
||||
};
|
||||
})();
|
||||
module.exports = {
|
||||
addFile: addFile,
|
||||
writeFile: writeFile,
|
||||
removeFile: removeFile,
|
||||
ignoreFile: ignoreFile,
|
||||
getIncludedFiles: getIncludedFiles,
|
||||
getIgnoredFiles: getIgnoredFiles,
|
||||
getExcludedFiles: getExcludedFiles,
|
||||
clear: clearAll
|
||||
};
|
||||
|
|
|
@ -14,100 +14,99 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
var path = require('path');
|
||||
var assert = require('yeoman-assert');
|
||||
var helpers = require('yeoman-test');
|
||||
'use strict';
|
||||
|
||||
var generator = path.join(__dirname, '../../generators/app');
|
||||
var modules = ['gerrit', 'license', 'editorconfig'];
|
||||
var projectBuilder = require('../../generators/app/lib/project_builder');
|
||||
var path = require('path');
|
||||
var assert = require('yeoman-assert');
|
||||
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 () {
|
||||
projectBuilder.clear();
|
||||
});
|
||||
describe('generator-openstack:app', function () {
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
beforeEach(function () {
|
||||
projectBuilder.clear();
|
||||
});
|
||||
})();
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
var libDir = '../../../../generators/app/lib';
|
||||
'use strict';
|
||||
|
||||
var editorconfig = require(libDir + '/component/editorconfig');
|
||||
var projectBuilder = require(libDir + '/project_builder');
|
||||
var mocks = require('../../../helpers/mocks');
|
||||
var mockGenerator;
|
||||
var libDir = '../../../../generators/app/lib';
|
||||
|
||||
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 () {
|
||||
mockGenerator = mocks.buildGenerator();
|
||||
projectBuilder.clear();
|
||||
describe('generator-openstack:lib/component/editorconfig', function () {
|
||||
|
||||
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 () {
|
||||
expect(typeof editorconfig.init).toBe('function');
|
||||
expect(typeof editorconfig.prompt).toBe('function');
|
||||
expect(typeof editorconfig.configure).toBe('function');
|
||||
var outputGenerator = editorconfig.init(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
|
||||
describe('init()', function () {
|
||||
it('should return a generator',
|
||||
function () {
|
||||
var outputGenerator = editorconfig.init(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,251 +14,250 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
var libDir = '../../../../generators/app/lib';
|
||||
var mockGenerator;
|
||||
var mockEslintIgnore = ['node_modules', 'bower_components', 'dist'];
|
||||
'use strict';
|
||||
|
||||
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');
|
||||
var libDir = '../../../../generators/app/lib';
|
||||
var mockGenerator;
|
||||
var mockEslintIgnore = ['node_modules', 'bower_components', 'dist'];
|
||||
|
||||
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 () {
|
||||
mockGenerator = mocks.buildGenerator();
|
||||
mockGenerator.fs.write('.eslintignore', mockEslintIgnore.join('\n'));
|
||||
projectBuilder.clear();
|
||||
describe('generator-openstack:lib/component/eslint', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
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 () {
|
||||
expect(typeof eslint.init).toBe('function');
|
||||
expect(typeof eslint.prompt).toBe('function');
|
||||
expect(typeof eslint.configure).toBe('function');
|
||||
var outputGenerator = eslint.init(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
|
||||
describe('init()', function () {
|
||||
it('should return a generator',
|
||||
function () {
|
||||
var outputGenerator = eslint.init(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
it('should not interact with config',
|
||||
function () {
|
||||
var spy = spyOn(mockGenerator.config, 'defaults');
|
||||
eslint.init(mockGenerator);
|
||||
expect(spy.calls.any()).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not interact with config',
|
||||
function () {
|
||||
var spy = spyOn(mockGenerator.config, 'defaults');
|
||||
eslint.init(mockGenerator);
|
||||
expect(spy.calls.any()).toBeFalsy();
|
||||
});
|
||||
});
|
||||
describe('prompt()', function () {
|
||||
it('should return a generator',
|
||||
function () {
|
||||
var outputGenerator = eslint.prompt(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
|
||||
describe('prompt()', function () {
|
||||
it('should return a generator',
|
||||
function () {
|
||||
var outputGenerator = eslint.prompt(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
it('should add eslint and eslint-config-openstack to the project',
|
||||
function () {
|
||||
pkgBuilder.fromJSON('{"devDependencies":{}}');
|
||||
|
||||
it('should add eslint and eslint-config-openstack to the project',
|
||||
function () {
|
||||
pkgBuilder.fromJSON('{"devDependencies":{}}');
|
||||
var devDeps = pkgBuilder.getValue('devDependencies');
|
||||
expect(devDeps.eslint).not.toBeDefined();
|
||||
expect(devDeps['eslint-config-openstack']).not.toBeDefined();
|
||||
|
||||
var devDeps = pkgBuilder.getValue('devDependencies');
|
||||
expect(devDeps.eslint).not.toBeDefined();
|
||||
expect(devDeps['eslint-config-openstack']).not.toBeDefined();
|
||||
eslint.prompt(mockGenerator);
|
||||
|
||||
eslint.prompt(mockGenerator);
|
||||
devDeps = pkgBuilder.getValue('devDependencies');
|
||||
expect(devDeps.eslint).toBeDefined();
|
||||
expect(devDeps['eslint-config-openstack']).toBeDefined();
|
||||
});
|
||||
|
||||
devDeps = pkgBuilder.getValue('devDependencies');
|
||||
expect(devDeps.eslint).toBeDefined();
|
||||
expect(devDeps['eslint-config-openstack']).toBeDefined();
|
||||
});
|
||||
it('should add the lint command to the project',
|
||||
function () {
|
||||
pkgBuilder.fromJSON('{}');
|
||||
|
||||
it('should add the lint command to the project',
|
||||
function () {
|
||||
pkgBuilder.fromJSON('{}');
|
||||
var scripts = pkgBuilder.getValue('scripts');
|
||||
expect(scripts).not.toBeDefined();
|
||||
|
||||
var scripts = pkgBuilder.getValue('scripts');
|
||||
expect(scripts).not.toBeDefined();
|
||||
eslint.prompt(mockGenerator);
|
||||
|
||||
eslint.prompt(mockGenerator);
|
||||
var newScripts = pkgBuilder.getValue('scripts');
|
||||
expect(newScripts.lint).toBeDefined();
|
||||
expect(newScripts.lint).toEqual('eslint ./');
|
||||
});
|
||||
});
|
||||
|
||||
var newScripts = pkgBuilder.getValue('scripts');
|
||||
expect(newScripts.lint).toBeDefined();
|
||||
expect(newScripts.lint).toEqual('eslint ./');
|
||||
});
|
||||
});
|
||||
describe('configure()', function () {
|
||||
it('should return a generator',
|
||||
function () {
|
||||
var outputGenerator = eslint.configure(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
|
||||
describe('configure()', function () {
|
||||
it('should return a generator',
|
||||
function () {
|
||||
var outputGenerator = eslint.configure(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
it('should add .eslintrc and .eslintignore to the project files.',
|
||||
function () {
|
||||
eslint.configure(mockGenerator);
|
||||
|
||||
it('should add .eslintrc and .eslintignore to the project files.',
|
||||
function () {
|
||||
eslint.configure(mockGenerator);
|
||||
var files = projectBuilder.getIncludedFiles();
|
||||
expect(files.length).toBe(2);
|
||||
expect(files[0].to).toBe('.eslintignore');
|
||||
expect(files[1].to).toBe('.eslintrc');
|
||||
});
|
||||
});
|
||||
|
||||
var files = projectBuilder.getIncludedFiles();
|
||||
expect(files.length).toBe(2);
|
||||
expect(files[0].to).toBe('.eslintignore');
|
||||
expect(files[1].to).toBe('.eslintrc');
|
||||
});
|
||||
});
|
||||
describe('.eslintrc management', function () {
|
||||
var mockEslintRc = {
|
||||
extends: 'openstack',
|
||||
plugins: ['angular']
|
||||
};
|
||||
|
||||
describe('.eslintrc management', function () {
|
||||
var mockEslintRc = {
|
||||
extends: 'openstack',
|
||||
plugins: ['angular']
|
||||
};
|
||||
it('should write a .eslintrc file as valid .yaml',
|
||||
function () {
|
||||
eslint.init(mockGenerator);
|
||||
eslint.configure(mockGenerator);
|
||||
|
||||
it('should write a .eslintrc file as valid .yaml',
|
||||
function () {
|
||||
eslint.init(mockGenerator);
|
||||
eslint.configure(mockGenerator);
|
||||
var files = projectBuilder.getIncludedFiles();
|
||||
var eslintRcRef = files[1];
|
||||
expect(eslintRcRef.to).toBe('.eslintrc');
|
||||
expect(yaml.safeLoad(eslintRcRef.content()))
|
||||
.toEqual({extends: 'openstack'});
|
||||
});
|
||||
|
||||
var files = projectBuilder.getIncludedFiles();
|
||||
var eslintRcRef = files[1];
|
||||
expect(eslintRcRef.to).toBe('.eslintrc');
|
||||
expect(yaml.safeLoad(eslintRcRef.content()))
|
||||
.toEqual({extends: 'openstack'});
|
||||
});
|
||||
it('should echo back existing .eslintrc',
|
||||
function () {
|
||||
var yamlContent = yaml.safeDump(mockEslintRc);
|
||||
mockGenerator.fs.write('.eslintrc', yamlContent);
|
||||
|
||||
it('should echo back existing .eslintrc',
|
||||
function () {
|
||||
var yamlContent = yaml.safeDump(mockEslintRc);
|
||||
mockGenerator.fs.write('.eslintrc', yamlContent);
|
||||
eslint.init(mockGenerator);
|
||||
eslint.configure(mockGenerator);
|
||||
|
||||
eslint.init(mockGenerator);
|
||||
eslint.configure(mockGenerator);
|
||||
var files = projectBuilder.getIncludedFiles();
|
||||
var eslintRcRef = files[1];
|
||||
var eslintContent = yaml.safeLoad(eslintRcRef.content());
|
||||
expect(mockEslintRc).toEqual(eslintContent);
|
||||
});
|
||||
|
||||
var files = projectBuilder.getIncludedFiles();
|
||||
var eslintRcRef = files[1];
|
||||
var eslintContent = yaml.safeLoad(eslintRcRef.content());
|
||||
expect(mockEslintRc).toEqual(eslintContent);
|
||||
});
|
||||
it('should convert a json .eslintrc to yaml',
|
||||
function () {
|
||||
mockGenerator.fs.write('.eslintrc', JSON.stringify(mockEslintRc));
|
||||
|
||||
it('should convert a json .eslintrc to yaml',
|
||||
function () {
|
||||
mockGenerator.fs.write('.eslintrc', JSON.stringify(mockEslintRc));
|
||||
eslint.init(mockGenerator);
|
||||
eslint.configure(mockGenerator);
|
||||
|
||||
eslint.init(mockGenerator);
|
||||
eslint.configure(mockGenerator);
|
||||
var files = projectBuilder.getIncludedFiles();
|
||||
var eslintRcRef = files[1];
|
||||
var eslintContent = yaml.safeLoad(eslintRcRef.content());
|
||||
expect(mockEslintRc).toEqual(eslintContent);
|
||||
});
|
||||
});
|
||||
|
||||
var files = projectBuilder.getIncludedFiles();
|
||||
var eslintRcRef = files[1];
|
||||
var eslintContent = yaml.safeLoad(eslintRcRef.content());
|
||||
expect(mockEslintRc).toEqual(eslintContent);
|
||||
});
|
||||
});
|
||||
describe('.eslintignore management', function () {
|
||||
|
||||
describe('.eslintignore management', function () {
|
||||
|
||||
it('should echo back existing .eslintignore',
|
||||
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', '');
|
||||
it('should echo back existing .eslintignore',
|
||||
function () {
|
||||
mockGenerator.fs.write('.eslintignore', mockEslintIgnore.join('\n'));
|
||||
|
||||
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 ignoreRef = files[0];
|
||||
var ignoreContent = ignoreRef.content().split('\n');
|
||||
expect(ignoreContent.length).toBe(mockEslintIgnore.length);
|
||||
|
||||
var rmFiles = projectBuilder.getExcludedFiles();
|
||||
expect(rmFiles.length).toBe(1);
|
||||
expect(rmFiles[0]).toBe('.eslintignore');
|
||||
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.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.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
var libDir = '../../../../generators/app/lib';
|
||||
'use strict';
|
||||
|
||||
var ini = require('ini');
|
||||
var libDir = '../../../../generators/app/lib';
|
||||
|
||||
var gerrit = require(libDir + '/component/gerrit');
|
||||
var projectBuilder = require(libDir + '/project_builder');
|
||||
var pkgBuilder = require(libDir + '/pkg_builder');
|
||||
var mocks = require('../../../helpers/mocks');
|
||||
var ini = require('ini');
|
||||
|
||||
var iniFile = {
|
||||
gerrit: {
|
||||
host: 'review.example.org',
|
||||
port: '1000',
|
||||
project: 'openstack/test-project.git'
|
||||
}
|
||||
};
|
||||
var gerrit = require(libDir + '/component/gerrit');
|
||||
var projectBuilder = require(libDir + '/project_builder');
|
||||
var pkgBuilder = require(libDir + '/pkg_builder');
|
||||
var mocks = require('../../../helpers/mocks');
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
// 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);
|
||||
var iniFile = {
|
||||
gerrit: {
|
||||
host: 'review.example.org',
|
||||
port: '1000',
|
||||
project: 'openstack/test-project.git'
|
||||
}
|
||||
};
|
||||
|
||||
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 () {
|
||||
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');
|
||||
});
|
||||
});
|
||||
// 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 () {
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
var libDir = '../../../../generators/app/lib';
|
||||
'use strict';
|
||||
|
||||
var gitignore = require(libDir + '/component/gitignore');
|
||||
var projectBuilder = require(libDir + '/project_builder');
|
||||
var mocks = require('../../../helpers/mocks');
|
||||
var mockGenerator;
|
||||
var libDir = '../../../../generators/app/lib';
|
||||
|
||||
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 () {
|
||||
mockGenerator = mocks.buildGenerator();
|
||||
projectBuilder.clear();
|
||||
describe('generator-openstack:lib/component/gitignore', function () {
|
||||
|
||||
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 () {
|
||||
expect(typeof gitignore.init).toBe('function');
|
||||
expect(typeof gitignore.prompt).toBe('function');
|
||||
expect(typeof gitignore.configure).toBe('function');
|
||||
var outputGenerator = gitignore.init(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
|
||||
describe('init()', function () {
|
||||
it('should return a generator',
|
||||
function () {
|
||||
var outputGenerator = gitignore.init(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
it('should not interact with config',
|
||||
function () {
|
||||
var spy = spyOn(mockGenerator.config, 'defaults');
|
||||
gitignore.init(mockGenerator);
|
||||
expect(spy.calls.any()).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not interact with config',
|
||||
function () {
|
||||
var spy = spyOn(mockGenerator.config, 'defaults');
|
||||
gitignore.init(mockGenerator);
|
||||
expect(spy.calls.any()).toBeFalsy();
|
||||
});
|
||||
});
|
||||
describe('prompt()', function () {
|
||||
it('should return a generator',
|
||||
function () {
|
||||
var outputGenerator = gitignore.prompt(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
|
||||
describe('prompt()', function () {
|
||||
it('should return a generator',
|
||||
function () {
|
||||
var outputGenerator = gitignore.prompt(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
it('should do nothing',
|
||||
function () {
|
||||
var spy = spyOn(mockGenerator, 'prompt');
|
||||
gitignore.init(mockGenerator);
|
||||
gitignore.prompt(mockGenerator);
|
||||
expect(spy.calls.any()).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
it('should do nothing',
|
||||
function () {
|
||||
var spy = spyOn(mockGenerator, 'prompt');
|
||||
gitignore.init(mockGenerator);
|
||||
gitignore.prompt(mockGenerator);
|
||||
expect(spy.calls.any()).toBeFalsy();
|
||||
});
|
||||
});
|
||||
describe('configure()', function () {
|
||||
it('should return a generator',
|
||||
function () {
|
||||
var outputGenerator = gitignore.configure(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
|
||||
describe('configure()', function () {
|
||||
it('should return a generator',
|
||||
function () {
|
||||
var outputGenerator = gitignore.configure(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
it('should add gitignore to the project files.',
|
||||
function () {
|
||||
mockGenerator.fs.write('.gitignore', ['one', 'two'].join('\n'));
|
||||
gitignore.init(mockGenerator);
|
||||
gitignore.prompt(mockGenerator);
|
||||
gitignore.configure(mockGenerator);
|
||||
|
||||
it('should add gitignore to the project files.',
|
||||
function () {
|
||||
mockGenerator.fs.write('.gitignore', ['one', 'two'].join('\n'));
|
||||
gitignore.init(mockGenerator);
|
||||
gitignore.prompt(mockGenerator);
|
||||
gitignore.configure(mockGenerator);
|
||||
var files = projectBuilder.getIncludedFiles();
|
||||
expect(files.length).toBe(1);
|
||||
expect(files[0].to).toBe('.gitignore');
|
||||
});
|
||||
});
|
||||
|
||||
var files = projectBuilder.getIncludedFiles();
|
||||
expect(files.length).toBe(1);
|
||||
expect(files[0].to).toBe('.gitignore');
|
||||
});
|
||||
});
|
||||
describe('.gitignore management', function () {
|
||||
|
||||
describe('.gitignore management', function () {
|
||||
|
||||
it('should echo back existing .gitignore',
|
||||
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', '');
|
||||
it('should echo back existing .gitignore',
|
||||
function () {
|
||||
mockGenerator.fs.write('.gitignore', ['one', 'two'].join('\n'));
|
||||
|
||||
gitignore.init(mockGenerator);
|
||||
gitignore.prompt(mockGenerator);
|
||||
gitignore.configure(mockGenerator);
|
||||
|
||||
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(rmFiles.length).toBe(1);
|
||||
expect(rmFiles[0]).toBe('.gitignore');
|
||||
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.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.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
var libDir = '../../../../generators/app/lib';
|
||||
'use strict';
|
||||
|
||||
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;
|
||||
var libDir = '../../../../generators/app/lib';
|
||||
|
||||
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 () {
|
||||
mockGenerator = mocks.buildGenerator();
|
||||
projectBuilder.clear();
|
||||
describe('generator-openstack:lib/component/license', function () {
|
||||
|
||||
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 () {
|
||||
expect(typeof license.init).toBe('function');
|
||||
expect(typeof license.prompt).toBe('function');
|
||||
expect(typeof license.configure).toBe('function');
|
||||
var outputGenerator = license.init(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
|
||||
describe('init()', function () {
|
||||
it('should return a generator',
|
||||
function () {
|
||||
var outputGenerator = license.init(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
|
||||
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");
|
||||
});
|
||||
});
|
||||
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");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,96 +14,95 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
var libDir = '../../../../generators/app/lib';
|
||||
'use strict';
|
||||
|
||||
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;
|
||||
var libDir = '../../../../generators/app/lib';
|
||||
|
||||
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 () {
|
||||
mockGenerator = mocks.buildGenerator();
|
||||
projectBuilder.clear();
|
||||
describe('generator-openstack:lib/component/nsp', function () {
|
||||
|
||||
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 () {
|
||||
expect(typeof nsp.init).toBe('function');
|
||||
expect(typeof nsp.prompt).toBe('function');
|
||||
expect(typeof nsp.configure).toBe('function');
|
||||
var outputGenerator = nsp.init(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
|
||||
describe('init()', function () {
|
||||
it('should return a generator',
|
||||
function () {
|
||||
var outputGenerator = nsp.init(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,177 +14,176 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
var libDir = '../../../../generators/app/lib';
|
||||
'use strict';
|
||||
|
||||
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;
|
||||
var libDir = '../../../../generators/app/lib';
|
||||
|
||||
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 () {
|
||||
mockGenerator = mocks.buildGenerator();
|
||||
projectBuilder.clear();
|
||||
jasmine.clock().install();
|
||||
describe('generator-openstack:lib/component/pkg', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
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 () {
|
||||
jasmine.clock().uninstall();
|
||||
});
|
||||
|
||||
it('should define init, prompt, and configure',
|
||||
describe('init()', function () {
|
||||
it('should return a generator',
|
||||
function () {
|
||||
expect(typeof pkg.init).toBe('function');
|
||||
expect(typeof pkg.prompt).toBe('function');
|
||||
expect(typeof pkg.configure).toBe('function');
|
||||
var outputGenerator = pkg.init(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
|
||||
describe('init()', function () {
|
||||
it('should return a generator',
|
||||
function () {
|
||||
var outputGenerator = pkg.init(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
it('should read an existing package.json file into the package builder',
|
||||
function () {
|
||||
mockGenerator.fs.writeJSON("package.json", {name: "foo"});
|
||||
|
||||
it('should read an existing package.json file into the package builder',
|
||||
function () {
|
||||
mockGenerator.fs.writeJSON("package.json", {name: "foo"});
|
||||
pkg.init(mockGenerator);
|
||||
var output = JSON.parse(pkgBuilder.toJSON());
|
||||
expect(output.name).toBe('foo');
|
||||
});
|
||||
|
||||
pkg.init(mockGenerator);
|
||||
var output = JSON.parse(pkgBuilder.toJSON());
|
||||
expect(output.name).toBe('foo');
|
||||
});
|
||||
it('should add several files to the ignore list.',
|
||||
function () {
|
||||
pkg.init(mockGenerator);
|
||||
|
||||
it('should add several files to the ignore list.',
|
||||
function () {
|
||||
pkg.init(mockGenerator);
|
||||
|
||||
var ignoredFiles = projectBuilder.getIgnoredFiles();
|
||||
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);
|
||||
});
|
||||
});
|
||||
var ignoredFiles = projectBuilder.getIgnoredFiles();
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,169 +14,168 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
var libDir = '../../../../generators/app/lib';
|
||||
'use strict';
|
||||
|
||||
var structure = require(libDir + '/component/structure');
|
||||
var projectBuilder = require(libDir + '/project_builder');
|
||||
var mocks = require('../../../helpers/mocks');
|
||||
var mockGenerator;
|
||||
var libDir = '../../../../generators/app/lib';
|
||||
|
||||
var expectedDefaults = {
|
||||
engine: 'browser',
|
||||
language: 'es5',
|
||||
srcDir: './src',
|
||||
distDir: './dist',
|
||||
testDir: './test'
|
||||
};
|
||||
var structure = require(libDir + '/component/structure');
|
||||
var projectBuilder = require(libDir + '/project_builder');
|
||||
var mocks = require('../../../helpers/mocks');
|
||||
var mockGenerator;
|
||||
|
||||
describe('generator-openstack:lib/component/structure', function () {
|
||||
var expectedDefaults = {
|
||||
engine: 'browser',
|
||||
language: 'es5',
|
||||
srcDir: './src',
|
||||
distDir: './dist',
|
||||
testDir: './test'
|
||||
};
|
||||
|
||||
beforeEach(function () {
|
||||
mockGenerator = mocks.buildGenerator();
|
||||
jasmine.clock().install();
|
||||
describe('generator-openstack:lib/component/structure', function () {
|
||||
|
||||
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 () {
|
||||
jasmine.clock().uninstall();
|
||||
});
|
||||
|
||||
it('should define init, prompt, and configure',
|
||||
describe('init()', function () {
|
||||
it('should return a generator',
|
||||
function () {
|
||||
expect(typeof structure.init).toBe('function');
|
||||
expect(typeof structure.prompt).toBe('function');
|
||||
expect(typeof structure.configure).toBe('function');
|
||||
var outputGenerator = structure.init(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
|
||||
describe('init()', function () {
|
||||
it('should return a generator',
|
||||
function () {
|
||||
var outputGenerator = structure.init(mockGenerator);
|
||||
expect(outputGenerator).toEqual(mockGenerator);
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,82 +14,81 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
var builder = require('../../../generators/app/lib/global_dependencies');
|
||||
var globals = require('../../../global-dependencies.json');
|
||||
var semver = require('semver');
|
||||
'use strict';
|
||||
|
||||
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 () {
|
||||
it('should contain all dependencies from the root global-dependencies.json',
|
||||
function () {
|
||||
for (var key in globals) {
|
||||
if (globals.hasOwnProperty(key)) {
|
||||
expect(builder.contains(key)).toBe(true);
|
||||
}
|
||||
describe('lib/global_dependencies', function () {
|
||||
|
||||
describe('data', function () {
|
||||
it('should contain all dependencies from the root global-dependencies.json',
|
||||
function () {
|
||||
for (var key in globals) {
|
||||
if (globals.hasOwnProperty(key)) {
|
||||
expect(builder.contains(key)).toBe(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('should contain valid semver versions for all dependencies',
|
||||
function () {
|
||||
for (var key in globals) {
|
||||
if (globals.hasOwnProperty(key)) {
|
||||
var version = builder.read(key);
|
||||
expect(semver.validRange(version)).toBeTruthy();
|
||||
}
|
||||
it('should contain valid semver versions for all dependencies',
|
||||
function () {
|
||||
for (var key in globals) {
|
||||
if (globals.hasOwnProperty(key)) {
|
||||
var version = builder.read(key);
|
||||
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 true when a dependency exists', function () {
|
||||
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);
|
||||
});
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,214 +14,213 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
var builder = require('../../../generators/app/lib/pkg_builder');
|
||||
var dependencies = require('../../../generators/app/lib/global_dependencies');
|
||||
'use strict';
|
||||
|
||||
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 () {
|
||||
builder.fromJSON("{}"); // Clear
|
||||
describe('generator-openstack:lib/pkg_builder', function () {
|
||||
|
||||
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 () {
|
||||
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 () {
|
||||
var packageString = '{"name":"foo"}';
|
||||
builder.fromJSON(packageString);
|
||||
var testPackage = {
|
||||
dependencies: {
|
||||
eslint: "0.0.1"
|
||||
}
|
||||
};
|
||||
|
||||
var parsedResult = JSON.parse(builder.toJSON());
|
||||
expect(parsedResult.name).toBe("foo");
|
||||
builder.fromJSON(JSON.stringify(testPackage));
|
||||
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 () {
|
||||
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");
|
||||
expect(builder.getValues()).toEqual({name: 'foo'});
|
||||
});
|
||||
});
|
||||
|
||||
it('should not add parent prototype values.',
|
||||
describe('getValue()', function () {
|
||||
it('should permit retrieving values from the package.',
|
||||
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();
|
||||
expect(builder.getValue('name')).toBe('foo');
|
||||
});
|
||||
|
||||
describe('toJSON()', function () {
|
||||
it('should update out-of-date dependencies.',
|
||||
function () {
|
||||
var testPackage = {
|
||||
dependencies: {
|
||||
eslint: "0.0.1"
|
||||
},
|
||||
peerDependencies: {
|
||||
eslint: "0.0.1"
|
||||
},
|
||||
devDependencies: {
|
||||
eslint: "0.0.1"
|
||||
}
|
||||
};
|
||||
it('should return undefined if the value is not set.',
|
||||
function () {
|
||||
builder.fromJSON('{"name":"foo"}');
|
||||
expect(builder.getValue('invalidname')).toBeUndefined();
|
||||
});
|
||||
|
||||
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 return a default if provided.',
|
||||
function () {
|
||||
builder.fromJSON('{"name":"foo"}');
|
||||
expect(builder.getValue('invalidname', 'defaultValue'))
|
||||
.toBe('defaultValue');
|
||||
});
|
||||
});
|
||||
|
||||
it('should not error if no dependencies are declared.',
|
||||
function () {
|
||||
var testPackage = {
|
||||
dependencies: {
|
||||
eslint: "0.0.1"
|
||||
}
|
||||
};
|
||||
describe('addDependencies()', function () {
|
||||
var eslintVersion = dependencies.read('eslint');
|
||||
|
||||
builder.fromJSON(JSON.stringify(testPackage));
|
||||
var result = JSON.parse(builder.toJSON());
|
||||
expect(result.dependencies.eslint).toBe(dependencies.read('eslint'));
|
||||
});
|
||||
it('should be able to add to dependencies', function () {
|
||||
builder.fromJSON('{"dependencies":{}}');
|
||||
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 permit retrieving the entire package block.',
|
||||
function () {
|
||||
builder.fromJSON('{"name":"foo"}');
|
||||
expect(builder.getValues()).toEqual({name: 'foo'});
|
||||
});
|
||||
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);
|
||||
});
|
||||
|
||||
describe('getValue()', function () {
|
||||
it('should permit retrieving values from the package.',
|
||||
function () {
|
||||
builder.fromJSON('{"name":"foo"}');
|
||||
expect(builder.getValue('name')).toBe('foo');
|
||||
});
|
||||
it('should be able to add to peerDependencies', function () {
|
||||
builder.fromJSON('{"peerDependencies":{}}');
|
||||
builder.addDependencies('eslint', 'peerDependencies');
|
||||
expect(builder.getValue('peerDependencies').eslint).toBe(eslintVersion);
|
||||
|
||||
it('should return undefined if the value is not set.',
|
||||
function () {
|
||||
builder.fromJSON('{"name":"foo"}');
|
||||
expect(builder.getValue('invalidname')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return a default if provided.',
|
||||
function () {
|
||||
builder.fromJSON('{"name":"foo"}');
|
||||
expect(builder.getValue('invalidname', 'defaultValue'))
|
||||
.toBe('defaultValue');
|
||||
});
|
||||
builder.fromJSON('{"peerDependencies":{}}');
|
||||
builder.addDependencies(['eslint'], 'peerDependencies');
|
||||
expect(builder.getValue('peerDependencies').eslint).toBe(eslintVersion);
|
||||
});
|
||||
|
||||
describe('addDependencies()', function () {
|
||||
var eslintVersion = dependencies.read('eslint');
|
||||
|
||||
it('should be able to add to dependencies', function () {
|
||||
builder.fromJSON('{"dependencies":{}}');
|
||||
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);
|
||||
});
|
||||
|
||||
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: {}});
|
||||
});
|
||||
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();
|
||||
});
|
||||
|
||||
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 not modify things if an invalid section was declared', function () {
|
||||
builder.fromJSON('{}');
|
||||
builder.addDependencies('eslint', 'lol');
|
||||
expect(builder.getValues()).toEqual({});
|
||||
});
|
||||
|
||||
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 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 create the scripts hash if it doesn\'t exist', function () {
|
||||
builder.fromJSON('{}');
|
||||
builder.addCommand('foo', 'bar');
|
||||
expect(builder.getValue('scripts')).toBeDefined();
|
||||
});
|
||||
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 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.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
var builder = require('../../../generators/app/lib/project_builder');
|
||||
'use strict';
|
||||
|
||||
describe('generator-openstack:lib/project_builder', function () {
|
||||
var builder = require('../../../generators/app/lib/project_builder');
|
||||
|
||||
beforeEach(function () {
|
||||
builder.clear();
|
||||
describe('generator-openstack:lib/project_builder', function () {
|
||||
|
||||
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',
|
||||
function () {
|
||||
expect(builder.getIncludedFiles().length).toBe(0);
|
||||
});
|
||||
it('should start with an empty list of excluded files',
|
||||
function () {
|
||||
expect(builder.getExcludedFiles().length).toBe(0);
|
||||
});
|
||||
|
||||
it('should start with an empty list of excluded files',
|
||||
function () {
|
||||
expect(builder.getExcludedFiles().length).toBe(0);
|
||||
});
|
||||
it('should permit adding a file with only one path.',
|
||||
function () {
|
||||
var testFilePath = 'test_path.json';
|
||||
|
||||
it('should permit adding a file with only one path.',
|
||||
function () {
|
||||
var testFilePath = 'test_path.json';
|
||||
builder.addFile(testFilePath);
|
||||
var testFile = builder.getIncludedFiles()[0];
|
||||
|
||||
builder.addFile(testFilePath);
|
||||
var testFile = builder.getIncludedFiles()[0];
|
||||
expect(testFile.from).toBe(testFilePath);
|
||||
expect(testFile.to).toBe(testFilePath);
|
||||
});
|
||||
|
||||
expect(testFile.from).toBe(testFilePath);
|
||||
expect(testFile.to).toBe(testFilePath);
|
||||
});
|
||||
it('should permit adding a file with a different destination path.',
|
||||
function () {
|
||||
var testFilePath = 'test_path.json';
|
||||
var testFileOutput = 'test_path_output.json';
|
||||
|
||||
it('should permit adding a file with a different destination path.',
|
||||
function () {
|
||||
var testFilePath = 'test_path.json';
|
||||
var testFileOutput = 'test_path_output.json';
|
||||
builder.addFile(testFilePath, testFileOutput);
|
||||
var testFile = builder.getIncludedFiles()[0];
|
||||
|
||||
builder.addFile(testFilePath, testFileOutput);
|
||||
var testFile = builder.getIncludedFiles()[0];
|
||||
expect(testFile.from).toBe(testFilePath);
|
||||
expect(testFile.to).toBe(testFileOutput);
|
||||
});
|
||||
|
||||
expect(testFile.from).toBe(testFilePath);
|
||||
expect(testFile.to).toBe(testFileOutput);
|
||||
});
|
||||
it('should permit adding a file to the exclusion list',
|
||||
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',
|
||||
function () {
|
||||
var testFilePath = 'test_path.json';
|
||||
builder.removeFile(testFilePath);
|
||||
expect(builder.getExcludedFiles()[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);
|
||||
});
|
||||
});
|
||||
})();
|
||||
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.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
function buildMockGenerator (config, mockAnswers, mockOptions) {
|
||||
var configDefaults = {};
|
||||
var memFs = require('mem-fs');
|
||||
var editor = require('mem-fs-editor');
|
||||
var store = memFs.create();
|
||||
function buildMockGenerator (config, mockAnswers, mockOptions) {
|
||||
var configDefaults = {};
|
||||
var memFs = require('mem-fs');
|
||||
var editor = require('mem-fs-editor');
|
||||
var store = memFs.create();
|
||||
|
||||
config = config || {};
|
||||
mockAnswers = mockAnswers || {};
|
||||
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;
|
||||
}
|
||||
config = config || {};
|
||||
mockAnswers = mockAnswers || {};
|
||||
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];
|
||||
});
|
||||
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 = {
|
||||
buildGenerator: buildMockGenerator
|
||||
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;
|
||||
}
|
||||
|
||||
});
|
||||
callback(answers);
|
||||
},
|
||||
options: mockOptions
|
||||
};
|
||||
})();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
buildGenerator: buildMockGenerator
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue