chore(package): re-init package with commitizen and standard-release

This commit is contained in:
Pavel Pertsev
2018-05-16 12:54:46 +03:00
parent cb4e7a5643
commit eaf2328575
10640 changed files with 609660 additions and 117 deletions

198
node_modules/commitizen/dist/commitizen/adapter.js generated vendored Normal file
View File

@@ -0,0 +1,198 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.resolveAdapterPath = exports.generateNpmInstallAdapterCommand = exports.getPrompter = exports.getNpmInstallStringMappings = exports.getNearestProjectRootDirectory = exports.getNearestNodeModulesDirectory = exports.addPathToAdapterConfig = undefined;
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _fs = require('fs');
var _fs2 = _interopRequireDefault(_fs);
var _findNodeModules = require('find-node-modules');
var _findNodeModules2 = _interopRequireDefault(_findNodeModules);
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _detectIndent = require('detect-indent');
var _detectIndent2 = _interopRequireDefault(_detectIndent);
var _shelljs = require('shelljs');
var _shelljs2 = _interopRequireDefault(_shelljs);
var _util = require('../common/util');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.addPathToAdapterConfig = addPathToAdapterConfig;
exports.getNearestNodeModulesDirectory = getNearestNodeModulesDirectory;
exports.getNearestProjectRootDirectory = getNearestProjectRootDirectory;
exports.getNpmInstallStringMappings = getNpmInstallStringMappings;
exports.getPrompter = getPrompter;
exports.generateNpmInstallAdapterCommand = generateNpmInstallAdapterCommand;
exports.resolveAdapterPath = resolveAdapterPath;
/**
* ADAPTER
*
* Adapter is generally responsible for actually installing adapters to an
* end user's project. It does not perform checks to determine if there is
* a previous commitizen adapter installed or if the proper fields were
* provided. It defers that responsibility to init.
*/
/**
* Modifies the package.json, sets config.commitizen.path to the path of the adapter
* Must be passed an absolute path to the cli's root
*/
function addPathToAdapterConfig(sh, cliPath, repoPath, adapterNpmName) {
var commitizenAdapterConfig = {
config: {
commitizen: {
path: './node_modules/' + adapterNpmName
}
}
};
var packageJsonPath = _path2.default.join(getNearestProjectRootDirectory(), 'package.json');
var packageJsonString = _fs2.default.readFileSync(packageJsonPath, 'utf-8');
// tries to detect the indentation and falls back to a default if it can't
var indent = (0, _detectIndent2.default)(packageJsonString).indent || ' ';
var packageJsonContent = JSON.parse(packageJsonString);
var newPackageJsonContent = '';
if (_lodash2.default.get(packageJsonContent, 'config.commitizen.path') !== adapterNpmName) {
newPackageJsonContent = _lodash2.default.merge(packageJsonContent, commitizenAdapterConfig);
}
_fs2.default.writeFileSync(packageJsonPath, JSON.stringify(newPackageJsonContent, null, indent) + '\n');
}
/**
* Generates an npm install command given a map of strings and a package name
*/
function generateNpmInstallAdapterCommand(stringMappings, adapterNpmName) {
// Start with an initial npm install command
var installAdapterCommand = 'npm install ' + adapterNpmName;
// Append the neccesary arguments to it based on user preferences
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = stringMappings.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _step$value = _slicedToArray(_step.value, 2),
key = _step$value[0],
value = _step$value[1];
if (value) {
installAdapterCommand = installAdapterCommand + ' ' + value;
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return installAdapterCommand;
}
/**
* Gets the nearest npm_modules directory
*/
function getNearestNodeModulesDirectory(options) {
// Get the nearest node_modules directories to the current working directory
var nodeModulesDirectories = (0, _findNodeModules2.default)(options);
// Make sure we find a node_modules folder
/* istanbul ignore else */
if (nodeModulesDirectories && nodeModulesDirectories.length > 0) {
return nodeModulesDirectories[0];
} else {
console.error('Error: Could not locate node_modules in your project\'s root directory. Did you forget to npm init or npm install?');
}
}
/**
* Gets the nearest project root directory
*/
function getNearestProjectRootDirectory(options) {
return _path2.default.join(process.cwd(), getNearestNodeModulesDirectory(options), '/../');
}
/**
* Gets a map of arguments where the value is the corresponding npm strings
*/
function getNpmInstallStringMappings(save, saveDev, saveExact, force) {
return new Map().set('save', save && !saveDev ? '--save' : undefined).set('saveDev', saveDev ? '--save-dev' : undefined).set('saveExact', saveExact ? '--save-exact' : undefined).set('force', force ? '--force' : undefined);
}
/**
* Gets the prompter from an adapter given an adapter path
*/
function getPrompter(adapterPath) {
// Resolve the adapter path
var resolvedAdapterPath = resolveAdapterPath(adapterPath);
// Load the adapter
var adapter = require(resolvedAdapterPath);
/* istanbul ignore next */
if (adapter && adapter.prompter && (0, _util.isFunction)(adapter.prompter)) {
return adapter.prompter;
} else if (adapter && adapter.default && adapter.default.prompter && (0, _util.isFunction)(adapter.default.prompter)) {
return adapter.default.prompter;
} else {
throw "Could not find prompter method in the provided adapter module: " + adapterPath;
}
}
/**
* Given a resolvable module name or path, which can be a directory or file, will
* return a located adapter path or will throw.
*/
function resolveAdapterPath(inboundAdapterPath) {
// Check if inboundAdapterPath is a path or node module name
var parsed = _path2.default.parse(inboundAdapterPath);
var isPath = parsed.dir.length > 0 && parsed.dir.charAt(0) !== "@";
// Resolve from the root of the git repo if inboundAdapterPath is a path
var absoluteAdapterPath = isPath ? _path2.default.resolve(getGitRootPath(), inboundAdapterPath) : inboundAdapterPath;
try {
// try to resolve the given path
return require.resolve(absoluteAdapterPath);
} catch (error) {
error.message = "Could not resolve " + absoluteAdapterPath + ". " + error.message;
throw error;
}
}
function getGitRootPath() {
return _shelljs2.default.exec('git rev-parse --show-toplevel').stdout.trim();
}

57
node_modules/commitizen/dist/commitizen/cache.js generated vendored Normal file
View File

@@ -0,0 +1,57 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.setCacheValueSync = exports.readCacheSync = exports.getCacheValueSync = undefined;
var _fs = require('fs');
var _fs2 = _interopRequireDefault(_fs);
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
exports.getCacheValueSync = getCacheValueSync;
exports.readCacheSync = readCacheSync;
exports.setCacheValueSync = setCacheValueSync;
/**
* Reads the entire cache
*/
function readCacheSync(cachePath) {
return JSON.parse(_fs2.default.readFileSync(cachePath, 'utf8'));
}
/**
* Sets a cache value and writes the file to disk
*/
function setCacheValueSync(cachePath, key, value) {
var originalCache;
try {
originalCache = readCacheSync(cachePath);
} catch (e) {
originalCache = {};
}
var newCache = _lodash2.default.assign(originalCache, _defineProperty({}, key, value));
_fs2.default.writeFileSync(cachePath, JSON.stringify(newCache, null, ' '));
return newCache;
}
/**
* Gets a single value from the cache given a key
*/
function getCacheValueSync(cachePath, repoPath) {
try {
var cache = readCacheSync(cachePath);
return cache[repoPath];
} catch (e) {
return;
}
}

93
node_modules/commitizen/dist/commitizen/commit.js generated vendored Normal file
View File

@@ -0,0 +1,93 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _dedent = require('dedent');
var _dedent2 = _interopRequireDefault(_dedent);
var _cachedir = require('cachedir');
var _cachedir2 = _interopRequireDefault(_cachedir);
var _fsExtra = require('fs-extra');
var _git = require('../git');
var _cache = require('./cache');
var cache = _interopRequireWildcard(_cache);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = commit;
/**
* Takes all of the final inputs needed in order to make dispatch a git commit
*/
function dispatchGitCommit(sh, repoPath, template, options, overrideOptions, done) {
// Commit the user input -- side effect that we'll test
(0, _git.commit)(sh, repoPath, template, _extends({}, options, overrideOptions), function (error) {
done(error, template);
});
}
/**
* Asynchronously commits files using commitizen
*/
function commit(sh, inquirer, repoPath, prompter, options, done) {
var cacheDirectory = (0, _cachedir2.default)('commitizen');
var cachePath = _path2.default.join(cacheDirectory, 'commitizen.json');
(0, _fsExtra.ensureDir)(cacheDirectory, function (error) {
if (error) {
console.error("Couldn't create commitizen cache directory: ", error);
// TODO: properly handle error?
} else {
if (options.retryLastCommit) {
console.log('Retrying last commit attempt.');
// We want to use the last commit instead of the current commit,
// so lets override some options using the values from cache.
var _cache$getCacheValueS = cache.getCacheValueSync(cachePath, repoPath),
retryOptions = _cache$getCacheValueS.options,
retryOverrideOptions = _cache$getCacheValueS.overrideOptions,
retryTemplate = _cache$getCacheValueS.template;
dispatchGitCommit(sh, repoPath, retryTemplate, retryOptions, retryOverrideOptions, done);
} else {
// Get user input -- side effect that is hard to test
prompter(inquirer, function (error, template, overrideOptions) {
// Allow adapters to error out
// (error: Error?, template: String, overrideOptions: Object)
if (!(error instanceof Error)) {
overrideOptions = template;
template = error;
error = null;
}
if (error) {
return done(error);
}
// We don't want to add retries to the cache, only actual commands
cache.setCacheValueSync(cachePath, repoPath, { template: template, options: options, overrideOptions: overrideOptions });
dispatchGitCommit(sh, repoPath, template, options, overrideOptions, done);
});
}
}
});
}

View File

@@ -0,0 +1,18 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.load = undefined;
var _configLoader = require('../configLoader');
exports.load = load;
// Configuration sources in priority order.
var configs = ['package.json', '.czrc', '.cz.json'];
function load(config, cwd) {
return (0, _configLoader.loader)(configs, config, cwd);
}

152
node_modules/commitizen/dist/commitizen/init.js generated vendored Normal file
View File

@@ -0,0 +1,152 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _configLoader = require('./configLoader');
var configLoader = _interopRequireWildcard(_configLoader);
var _util = require('../common/util');
var _adapter = require('./adapter');
var adapter = _interopRequireWildcard(_adapter);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var addPathToAdapterConfig = adapter.addPathToAdapterConfig,
generateNpmInstallAdapterCommand = adapter.generateNpmInstallAdapterCommand,
getNpmInstallStringMappings = adapter.getNpmInstallStringMappings;
exports.default = init;
var CLI_PATH = _path2.default.normalize(__dirname + '/../../');
/**
* CZ INIT
*
* Init is generally responsible for initializing an adapter in
* a user's project. The goal is to be able to run
* `commitizen init` and be prompted for certain fields which
* will help you install the proper adapter for your project.
*
* Init does not actually create the adapter (it defers to adapter
* for this). Instead, it is specifically designed to help gather
* and validate the information needed to install the adapter
* properly without interfering with a previous adapter config.
*/
/**
* The defaults for init
*/
var defaultInitOptions = {
save: false,
saveDev: true,
saveExact: false,
force: false
};
/**
* Runs npm install for the adapter then modifies the config.commitizen as needed
*/
function init(sh, repoPath, adapterNpmName) {
var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : defaultInitOptions,
_ref$save = _ref.save,
save = _ref$save === undefined ? false : _ref$save,
_ref$saveDev = _ref.saveDev,
saveDev = _ref$saveDev === undefined ? true : _ref$saveDev,
_ref$saveExact = _ref.saveExact,
saveExact = _ref$saveExact === undefined ? false : _ref$saveExact,
_ref$force = _ref.force,
force = _ref$force === undefined ? false : _ref$force;
// Don't let things move forward if required args are missing
checkRequiredArguments(sh, repoPath, adapterNpmName);
// Move to the correct directory so we can run commands
sh.cd(repoPath);
// Load the current adapter config
var adapterConfig = loadAdapterConfig();
// Get the npm string mappings based on the arguments provided
var stringMappings = getNpmInstallStringMappings(save, saveDev, saveExact, force);
// Generate a string that represents the npm install command
var installAdapterCommand = generateNpmInstallAdapterCommand(stringMappings, adapterNpmName);
// Check for previously installed adapters
if (adapterConfig && adapterConfig.path && adapterConfig.path.length > 0) {
// console.log(`
// Previous adapter detected!
// `);
if (!force) {
// console.log(`
// Previous adapter detected!
// `);
throw 'A previous adapter is already configured. Use --force to override';
} else {
// Override it
try {
(0, _util.executeShellCommand)(sh, repoPath, installAdapterCommand);
addPathToAdapterConfig(sh, CLI_PATH, repoPath, adapterNpmName);
} catch (e) {
console.error(e);
}
}
} else {
// console.log(`
// No previous adapter was detected
// `);
try {
(0, _util.executeShellCommand)(sh, repoPath, installAdapterCommand);
addPathToAdapterConfig(sh, CLI_PATH, repoPath, adapterNpmName);
} catch (e) {
console.error(e);
}
}
}
/**
* Checks to make sure that the required arguments are passed
* Throws an exception if any are not.
*/
function checkRequiredArguments(sh, path, adapterNpmName) {
if (!sh) {
throw "You must pass an instance of shelljs when running init.";
}
if (!path) {
throw "Path is required when running init.";
}
if (!adapterNpmName) {
throw "The adapter's npm name is required when running init.";
}
}
/**
* CONFIG
* Loads and returns the adapter config at key config.commitizen, if it exists
*/
function loadAdapterConfig() {
var config = configLoader.load();
if (config) {
return config;
} else {
return;
}
}

27
node_modules/commitizen/dist/commitizen/staging.js generated vendored Normal file
View File

@@ -0,0 +1,27 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isClean = undefined;
var _child_process = require('child_process');
exports.isClean = isClean;
/**
* Asynchrounously determines if the staging area is clean
*/
function isClean(repoPath, done) {
(0, _child_process.exec)('git diff --cached --name-only', {
maxBuffer: Infinity,
cwd: repoPath || process.cwd()
}, function (error, stdout) {
if (error) {
return done(error);
}
var output = stdout || '';
done(null, output.trim().length === 0);
});
}