123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- 'use strict';
- const helper = require('../helper');
- const DEFAULT_IGNORE = ['node_modules'];
- const SOURCEMAPS_SCHEMA = require('./options/uploadSourcemaps');
- const DEPLOYS_SCHEMA = require('./options/deploys');
- class Releases {
-
- constructor(options) {
- this.options = options || {};
- if (typeof this.options.configFile === 'string') {
- this.configFile = this.options.configFile;
- }
- delete this.options.configFile;
- }
-
- new(release, options) {
- const args = ['releases', 'new', release].concat(helper.getProjectFlagsFromOptions(options));
- return this.execute(args, null);
- }
-
- setCommits(release, options) {
- if (!options || (!options.auto && (!options.repo || !options.commit))) {
- throw new Error('options.auto, or options.repo and options.commit must be specified');
- }
- let commitFlags = [];
- if (options.auto) {
- commitFlags = ['--auto'];
- } else if (options.previousCommit) {
- commitFlags = ['--commit', `${options.repo}@${options.previousCommit}..${options.commit}`];
- } else {
- commitFlags = ['--commit', `${options.repo}@${options.commit}`];
- }
- if (options.ignoreMissing) {
- commitFlags.push('--ignore-missing');
- }
- if (options.ignoreEmpty) {
- commitFlags.push('--ignore-empty');
- }
- return this.execute(['releases', 'set-commits', release].concat(commitFlags));
- }
-
- finalize(release) {
- return this.execute(['releases', 'finalize', release], null);
- }
-
- proposeVersion() {
- return this.execute(['releases', 'propose-version'], null).then(
- version => version && version.trim()
- );
- }
-
- uploadSourceMaps(release, options) {
- if (!options || !options.include || !Array.isArray(options.include)) {
- throw new Error(
- '`options.include` must be a vaild array of paths and/or path descriptor objects.'
- );
- }
-
-
-
- const uploads = options.include.map(includeEntry => {
- let pathOptions;
- let uploadPaths;
- if (typeof includeEntry === 'object') {
- pathOptions = includeEntry;
- uploadPaths = includeEntry.paths;
- if (!Array.isArray(uploadPaths)) {
- throw new Error(
- `Path descriptor objects in \`options.include\` must contain a \`paths\` array. Got ${includeEntry}.`
- );
- }
- }
-
-
- else {
- pathOptions = {};
- uploadPaths = [includeEntry];
- }
- const newOptions = { ...options, ...pathOptions };
- if (!newOptions.ignoreFile && !newOptions.ignore) {
- newOptions.ignore = DEFAULT_IGNORE;
- }
-
- const args = ['releases']
- .concat(helper.getProjectFlagsFromOptions(options))
- .concat(['files', release, 'upload-sourcemaps']);
- return uploadPaths.map(path =>
-
- this.execute(helper.prepareCommand([...args, path], SOURCEMAPS_SCHEMA, newOptions), true)
- );
- });
-
-
-
-
-
- return Promise.all([].concat(...uploads));
- }
-
- listDeploys(release) {
- return this.execute(['releases', 'deploys', release, 'list'], null);
- }
-
- newDeploy(release, options) {
- if (!options || !options.env) {
- throw new Error('options.env must be a vaild name');
- }
- const args = ['releases', 'deploys', release, 'new'];
- return this.execute(helper.prepareCommand(args, DEPLOYS_SCHEMA, options), null);
- }
-
- execute(args, live) {
- return helper.execute(args, live, this.options.silent, this.configFile, this.options);
- }
- }
- module.exports = Releases;
|