Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring #778

Merged
merged 87 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
83ae34e
chore: repo setup
PopGoesTheWza May 20, 2020
38a1f0c
style: refactor
PopGoesTheWza May 20, 2020
c31f133
fix:proper use of NodeJS.URL
PopGoesTheWza May 20, 2020
971d63e
fix: logic error
PopGoesTheWza May 20, 2020
7a720eb
ci: make `xo` linter prerequisite for tests
PopGoesTheWza May 20, 2020
4cbc57b
chore: stricter TS build config
PopGoesTheWza May 20, 2020
8ce7f07
chore: dead code cleanup
PopGoesTheWza May 20, 2020
56ed8c2
build: fixes some TS strict checks
PopGoesTheWza May 20, 2020
9870820
chore: switch to `gts` linter
PopGoesTheWza May 21, 2020
9c300c3
refactor: rename `tests` folder into `test`
PopGoesTheWza May 21, 2020
4e01f60
style: `gts` compliant
PopGoesTheWza May 21, 2020
9c1e599
fix: `bin` path
PopGoesTheWza May 21, 2020
4c6caae
chore: tentative ts-node fix
PopGoesTheWza May 21, 2020
6618d2d
chore: drop ts-node
PopGoesTheWza May 21, 2020
943a204
test: restore ts-node usage
PopGoesTheWza May 21, 2020
a561081
test: fix path to `build`
PopGoesTheWza May 21, 2020
8637455
test: fix path
PopGoesTheWza May 21, 2020
0bd25a4
test: fix reference issue
PopGoesTheWza May 21, 2020
a940d08
test: path cleanup
PopGoesTheWza May 21, 2020
5ec1ff8
style: linted
PopGoesTheWza May 22, 2020
76b3de2
chore: tweak `quotes` rules
PopGoesTheWza May 22, 2020
60e2605
chore: test setup
PopGoesTheWza May 22, 2020
118983b
chore: fix `check` command line
PopGoesTheWza May 22, 2020
8458bb8
chore: `nyc` config
PopGoesTheWza May 22, 2020
8e9d92f
chore: fix path to `package.json`
PopGoesTheWza May 22, 2020
c2dd8a8
chore: dependencies update
PopGoesTheWza May 22, 2020
17d33b5
refactor: loosening dependencies
PopGoesTheWza May 22, 2020
910519c
chore: obsolete setting
PopGoesTheWza May 22, 2020
572cc97
chore dependencies update
PopGoesTheWza May 22, 2020
e2947ab
refactor: replace `ellipsize`
PopGoesTheWza May 22, 2020
1d271cf
fix: typing of untyped modules
PopGoesTheWza May 22, 2020
53f73d1
chore: drop unnecessary config
PopGoesTheWza May 22, 2020
cb75128
style: tweak rules
PopGoesTheWza May 22, 2020
4af7051
style: eslint|tslint comments cleanup
PopGoesTheWza May 22, 2020
c23edb4
style: better typings
PopGoesTheWza May 22, 2020
ec2788f
refactoring: commander parseAsync
PopGoesTheWza May 22, 2020
f5720f5
refactor: drop `handleError()`
PopGoesTheWza May 22, 2020
8a329e4
refactor: drop unnecessary spinner code
PopGoesTheWza May 22, 2020
1e46f5b
refactor: add `getDescriptionFrom()` to use with `logError()`
PopGoesTheWza May 23, 2020
9897fad
style: typings
PopGoesTheWza May 23, 2020
e3c9960
chore: dependencies update
PopGoesTheWza May 23, 2020
8bfd0fe
refactor: commands throw errors instead of calling logError
PopGoesTheWza May 24, 2020
3f7f359
refactor: basic error management
PopGoesTheWza May 24, 2020
5f238d2
fix: import error
PopGoesTheWza May 24, 2020
65fa629
feat: introducing ClaspError
PopGoesTheWza May 24, 2020
9c4c68b
refactor: throw ClaspError
PopGoesTheWza May 24, 2020
64e5770
refactor: setupLogs
PopGoesTheWza May 24, 2020
3e745de
refactor: writeProjectFiles
PopGoesTheWza May 24, 2020
975b75b
refactor: getOAuthSettings & getProjectSettings
PopGoesTheWza May 24, 2020
9d65bdc
refactor: authorizeWithoutLocalhost
PopGoesTheWza May 24, 2020
3645865
refactor: promises into async/await
PopGoesTheWza May 24, 2020
043989b
feat: use loudRejection
PopGoesTheWza May 24, 2020
c1625ca
test: node 10 on windows
PopGoesTheWza May 24, 2020
51bf87a
ci: restore travis
PopGoesTheWza May 24, 2020
93a7e4b
ci: disable before_script
PopGoesTheWza May 24, 2020
f5b7262
style: eslint comments cleanup
PopGoesTheWza May 24, 2020
f85467a
feat: use readPkgUp to access package.json
PopGoesTheWza May 25, 2020
ae6a8fa
fix: squash some gremlins characters
PopGoesTheWza May 25, 2020
d74c2df
style: import autocomplete
PopGoesTheWza May 25, 2020
33d568c
style comment out dead code
PopGoesTheWza May 25, 2020
df1ebb4
style: TODO cleanup
PopGoesTheWza May 25, 2020
7fa5ae2
comment out more dead code
PopGoesTheWza May 25, 2020
245701a
test: fix '-v'
PopGoesTheWza May 25, 2020
77ea3e8
ci: temporarily test node 10 / windows
PopGoesTheWza May 25, 2020
ffa73fd
ci: fix EOL on windows
PopGoesTheWza May 25, 2020
e9a061a
style: comments
PopGoesTheWza May 25, 2020
d9539de
ci: focus on windows failing test
PopGoesTheWza May 25, 2020
bc28be9
ci: debug test
PopGoesTheWza May 25, 2020
cb1101b
ci: debug windows test
PopGoesTheWza May 25, 2020
02e6ccc
ci: check error type
PopGoesTheWza May 25, 2020
873d18d
ci: force exitCode
PopGoesTheWza May 25, 2020
ebd3215
ci: restore standard tests
PopGoesTheWza May 25, 2020
1388ff9
doc: PR #781
PopGoesTheWza May 25, 2020
be822d6
fix: silly typo
PopGoesTheWza May 25, 2020
3140a41
ci: try inquirer `isTtyError`
PopGoesTheWza May 25, 2020
4798fe8
ci: revert last commit
PopGoesTheWza May 25, 2020
cbd46e4
chore: add `gts` shield
PopGoesTheWza May 25, 2020
a90bde6
chore: fix `gts` globs
PopGoesTheWza May 25, 2020
0d0b93d
fix: peadPkgUp search path
PopGoesTheWza May 26, 2020
86ae03d
ci: fix test
PopGoesTheWza May 26, 2020
dbe1d98
test: cleaner require.resolve
PopGoesTheWza May 26, 2020
803e448
chore: update dependencies
PopGoesTheWza May 26, 2020
d11d3c7
chore: update tmp dev dependency
PopGoesTheWza May 27, 2020
e43034e
docs: typos and `gts`
PopGoesTheWza Jun 2, 2020
94e5f21
chore: update dependencies
PopGoesTheWza Jun 2, 2020
b36a2b4
chore: update dependencies
PopGoesTheWza Jun 5, 2020
5556452
style: drop xo, keep gts
PopGoesTheWza Jun 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: commands throw errors instead of calling logError
  • Loading branch information
PopGoesTheWza committed May 24, 2020
commit 8bfd0fe8525df1993d306242bd7f799c65a0ff66
4 changes: 2 additions & 2 deletions src/commands/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {enableOrDisableAPI} from '../apiutils';
import {discovery, loadAPICredentials, serviceUsage} from '../auth';
import {ERROR} from '../messages';
import {URL} from '../urls';
import {checkIfOnline, getProjectId, logError} from '../utils';
import {checkIfOnline, getProjectId} from '../utils';
import {ReadonlyDeep} from 'type-fest';

interface CommandOption {
Expand Down Expand Up @@ -119,6 +119,6 @@ export default async (options: CommandOption): Promise<void> => {
if (command[subcommand]) {
command[subcommand]();
} else {
logError(ERROR.COMMAND_DNE(`apis ${subcommand}`));
throw new Error(ERROR.COMMAND_DNE(`apis ${subcommand}`));
}
};
4 changes: 2 additions & 2 deletions src/commands/clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ export default async (
options: CommandOption
): Promise<void> => {
await checkIfOnline();
if (hasProject()) logError(ERROR.FOLDER_EXISTS);
if (hasProject()) throw new Error(ERROR.FOLDER_EXISTS);
scriptId = scriptId ? extractScriptId(scriptId) : await getScriptId();
spinner.setSpinnerTitle(LOG.CLONING);
const {rootDir} = options;
await saveProject({scriptId, rootDir}, false);
const files = await fetchProject(scriptId, versionNumber);
await writeProjectFiles(files, rootDir);
await status();
if (spinner.isSpinning()) spinner.stop(true);
// if (spinner.isSpinning()) spinner.stop(true);
};

/**
Expand Down
21 changes: 11 additions & 10 deletions src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
getDefaultProjectName,
getDescriptionFrom,
getProjectSettings,
logError,
saveProject,
spinner,
} from '../utils';
Expand All @@ -33,7 +32,7 @@ interface CommandOption {
export default async (options: CommandOption): Promise<void> => {
// Handle common errors.
await checkIfOnline();
if (hasProject()) logError(ERROR.FOLDER_EXISTS);
if (hasProject()) throw new Error(ERROR.FOLDER_EXISTS);
await loadAPICredentials();

// Create defaults.
Expand Down Expand Up @@ -69,13 +68,15 @@ export default async (options: CommandOption): Promise<void> => {

// CLI Spinner
spinner.setSpinnerTitle(LOG.CREATE_PROJECT_START(title)).start();
try {
const {scriptId} = await getProjectSettings(true);
if (scriptId) logError(ERROR.NO_NESTED_PROJECTS);
} catch {
// No scriptId (because project doesn't exist)
// console.log(error);
}
// try {
// const {scriptId} = await getProjectSettings(true);
// if (scriptId) throw new Error(ERROR.NO_NESTED_PROJECTS);
// } catch {
// // No scriptId (because project doesn't exist)
// // console.log(error);
// }
const {scriptId} = await getProjectSettings(true);
if (scriptId) throw new Error(ERROR.NO_NESTED_PROJECTS);

// Create a new Apps Script project
const response = await script.projects.create({
Expand All @@ -87,7 +88,7 @@ export default async (options: CommandOption): Promise<void> => {
if (spinner.isSpinning()) spinner.stop(true);
if (response.status !== 200) {
if (parentId) console.log(response.statusText, ERROR.CREATE_WITH_PARENT);
logError(getDescriptionFrom(response.statusText) ?? ERROR.CREATE);
throw new Error(getDescriptionFrom(response.statusText) ?? ERROR.CREATE);
}

const createdScriptId = response.data.scriptId ?? '';
Expand Down
3 changes: 1 addition & 2 deletions src/commands/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import {Command} from 'commander';
import {ReadonlyDeep} from 'type-fest';

import {ERROR} from '../messages';
import {logError} from '../utils';

/**
* Displays a default message when an unknown command is typed.
* @param command {string} The command that was typed.
*/
export default async (_: ReadonlyDeep<Command>, command: string): Promise<void> => {
logError(ERROR.COMMAND_DNE(command));
throw new Error(ERROR.COMMAND_DNE(command));
};
6 changes: 3 additions & 3 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {loadAPICredentials, script} from '../auth';
import {PROJECT_MANIFEST_BASENAME} from '../constants';
import {ERROR, LOG} from '../messages';
import {checkIfOnline, getProjectSettings, logError, spinner} from '../utils';
import {checkIfOnline, getProjectSettings, spinner} from '../utils';

interface CommandOption {
readonly versionNumber?: number;
Expand Down Expand Up @@ -33,8 +33,8 @@ export default async (options: CommandOption): Promise<void> => {
description,
},
});
if (version.status !== 200) throw new Error(ERROR.ONE_DEPLOYMENT_CREATE);
if (spinner.isSpinning()) spinner.stop(true);
if (version.status !== 200) logError(ERROR.ONE_DEPLOYMENT_CREATE);
versionNumber = version.data.versionNumber ?? 0;
console.log(LOG.VERSION_CREATED(versionNumber));
}
Expand Down Expand Up @@ -66,7 +66,7 @@ export default async (options: CommandOption): Promise<void> => {
});
}

if (deployments.status !== 200) throw new Error(ERROR.DEPLOYMENT_COUNT);
if (spinner.isSpinning()) spinner.stop(true);
if (deployments.status !== 200) logError(ERROR.DEPLOYMENT_COUNT);
console.log(`- ${deployments.data.deploymentId} @${versionNumber}.`);
};
4 changes: 2 additions & 2 deletions src/commands/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {script_v1 as scriptV1} from 'googleapis';

import {loadAPICredentials, script} from '../auth';
import {LOG} from '../messages';
import {checkIfOnline, getProjectSettings, logError, spinner} from '../utils';
import {checkIfOnline, getProjectSettings, spinner} from '../utils';

/**
* Lists a script's deployments.
Expand All @@ -18,7 +18,7 @@ export default async (): Promise<void> => {
scriptId,
});
if (spinner.isSpinning()) spinner.stop(true);
if (deployments.status !== 200) logError(deployments.statusText);
if (deployments.status !== 200) throw new Error(deployments.statusText);
const deploymentsList = deployments.data.deployments ?? [];
const deploymentCount = deploymentsList.length;
const deploymentWord = deploymentCount === 1 ? 'Deployment' : 'Deployments';
Expand Down
4 changes: 2 additions & 2 deletions src/commands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {drive_v3 as driveV3} from 'googleapis';
import {drive, loadAPICredentials} from '../auth';
import {ERROR, LOG} from '../messages';
import {URL} from '../urls';
import {checkIfOnline, logError, spinner, ellipsize} from '../utils';
import {checkIfOnline, spinner, ellipsize} from '../utils';

/**
* Lists a user's Apps Script projects using Google Drive.
Expand All @@ -20,8 +20,8 @@ export default async (): Promise<void> => {
// fields: 'nextPageToken, files(id, name)',
q: 'mimeType="application/vnd.google-apps.script"',
});
if (filesList.status !== 200) throw new Error(ERROR.DRIVE);
if (spinner.isSpinning()) spinner.stop(true);
if (filesList.status !== 200) logError(ERROR.DRIVE);
const files = filesList.data.files ?? [];
if (files.length === 0) {
console.log(LOG.FINDING_SCRIPTS_DNE);
Expand Down
14 changes: 7 additions & 7 deletions src/commands/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {loadAPICredentials, script} from '../auth';
import {deploymentIdPrompt} from '../inquirer';
import {ERROR, LOG} from '../messages';
import {URL} from '../urls';
import {ellipsize, getDescriptionFrom, getProjectSettings, getWebApplicationURL, logError} from '../utils';
import {ellipsize, getDescriptionFrom, getProjectSettings, getWebApplicationURL} from '../utils';

interface CommandOption {
readonly webapp?: boolean;
Expand All @@ -23,7 +23,7 @@ interface CommandOption {
export default async (scriptId: string, options: CommandOption): Promise<void> => {
const projectSettings = await getProjectSettings();
if (!scriptId) scriptId = projectSettings.scriptId;
if (scriptId.length < 30) logError(ERROR.SCRIPT_ID_INCORRECT(scriptId));
if (scriptId.length < 30) throw new Error(ERROR.SCRIPT_ID_INCORRECT(scriptId));
// We've specified to open creds.
if (options.creds) {
const {projectId} = projectSettings;
Expand All @@ -33,7 +33,7 @@ export default async (scriptId: string, options: CommandOption): Promise<void> =
return;
}

logError(ERROR.NO_GCLOUD_PROJECT);
throw new Error(ERROR.NO_GCLOUD_PROJECT);
}

// We've specified to print addons and open the first one.
Expand All @@ -51,7 +51,7 @@ export default async (scriptId: string, options: CommandOption): Promise<void> =
return;
}

logError(ERROR.NO_PARENT_ID);
throw new Error(ERROR.NO_PARENT_ID);
}

// If we're not a web app, open the script URL.
Expand All @@ -64,9 +64,9 @@ export default async (scriptId: string, options: CommandOption): Promise<void> =
// Web app: Otherwise, open the latest deployment.
await loadAPICredentials();
const deploymentsList = await script.projects.deployments.list({scriptId});
if (deploymentsList.status !== 200) logError(getDescriptionFrom(deploymentsList.statusText));
if (deploymentsList.status !== 200) throw new Error(getDescriptionFrom(deploymentsList.statusText));
const deployments: Array<Readonly<scriptV1.Schema$Deployment>> = deploymentsList.data.deployments ?? [];
if (deployments.length === 0) logError(ERROR.SCRIPT_ID_INCORRECT(scriptId));
if (deployments.length === 0) throw new Error(ERROR.SCRIPT_ID_INCORRECT(scriptId));
// Order deployments by update time.
const choices = deployments
.slice()
Expand Down Expand Up @@ -100,6 +100,6 @@ export default async (scriptId: string, options: CommandOption): Promise<void> =
if (target) {
await open(target, {wait: false});
} else {
logError(`Could not open deployment: ${JSON.stringify(deployment)}`);
throw new Error(`Could not open deployment: ${JSON.stringify(deployment)}`);
}
};
2 changes: 1 addition & 1 deletion src/commands/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export default async (options: CommandOption): Promise<void> => {
spinner.setSpinnerTitle(LOG.PULLING);
const files = await fetchProject(scriptId, options.versionNumber);
await writeProjectFiles(files, rootDir);
if (spinner.isSpinning()) spinner.stop(true);
// if (spinner.isSpinning()) spinner.stop(true);
}
};
2 changes: 1 addition & 1 deletion src/commands/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default async (options: CommandOption): Promise<void> => {

spinner.setSpinnerTitle(LOG.PUSHING).start();
await pushFiles();
if (spinner.isSpinning()) spinner.stop(true);
// if (spinner.isSpinning()) spinner.stop(true);
}
};

Expand Down
9 changes: 5 additions & 4 deletions src/commands/setting.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable new-cap */
import {ProjectSettings} from '../dotfile';
import {ERROR} from '../messages';
import {getProjectSettings, logError, saveProject} from '../utils';
import {getProjectSettings, saveProject} from '../utils';

/**
* Gets or sets a setting in .clasp.json
Expand Down Expand Up @@ -30,7 +30,7 @@ export default async (settingKey?: keyof ProjectSettings, settingValue?: string)
// Which interfers with storing the value
process.stdout.write(keyValue);
} else {
logError(ERROR.UNKNOWN_KEY(settingKey));
throw new Error(ERROR.UNKNOWN_KEY(settingKey));
}
} else {
try {
Expand All @@ -50,14 +50,15 @@ export default async (settingKey?: keyof ProjectSettings, settingValue?: string)
currentSettings.fileExtension = settingValue;
break;
default:
logError(ERROR.UNKNOWN_KEY(settingKey));
throw new Error(ERROR.UNKNOWN_KEY(settingKey));
}
// filePushOrder doesn't work since it requires an array.
// const filePushOrder = settingKey === 'filePushOrder' ? settingValue : currentSettings.filePushOrder;
await saveProject(currentSettings, true);
console.log(`Updated "${settingKey}": "${currentValue}" → "${settingValue}"`);
} catch (error) {
logError('Unable to update .clasp.json');
if (error instanceof Error) throw error;
throw new Error('Unable to update .clasp.json');
}
}
};
16 changes: 8 additions & 8 deletions src/commands/undeploy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable new-cap */
import {loadAPICredentials, script} from '../auth';
import {ERROR, LOG} from '../messages';
import {checkIfOnline, getDescriptionFrom, getProjectSettings, logError, spinner} from '../utils';
import {checkIfOnline, getDescriptionFrom, getProjectSettings, spinner} from '../utils';

interface CommandOption {
readonly all?: boolean;
Expand All @@ -19,18 +19,18 @@ export default async (deploymentId: string | undefined, options: CommandOption):

if (options.all) {
const deploymentsList = await script.projects.deployments.list({scriptId});
if (deploymentsList.status !== 200) logError(getDescriptionFrom(deploymentsList.statusText));
if (deploymentsList.status !== 200) throw new Error(getDescriptionFrom(deploymentsList.statusText));

const deployments = deploymentsList.data.deployments ?? [];
if (deployments.length === 0) logError(ERROR.SCRIPT_ID_INCORRECT(scriptId));
if (deployments.length === 0) throw new Error(ERROR.SCRIPT_ID_INCORRECT(scriptId));

deployments.shift(); // @HEAD (Read-only deployments) may not be deleted.
for (const deployment of deployments) {
const id = deployment.deploymentId ?? '';
spinner.setSpinnerTitle(LOG.UNDEPLOYMENT_START(id)).start();
const result = await script.projects.deployments.delete({scriptId, deploymentId: id});

if (result.status !== 200) logError(ERROR.READ_ONLY_DELETE);
if (result.status !== 200) throw new Error(ERROR.READ_ONLY_DELETE);

if (spinner.isSpinning()) spinner.stop(true);
console.log(LOG.UNDEPLOYMENT_FINISH(id));
Expand All @@ -41,13 +41,13 @@ export default async (deploymentId: string | undefined, options: CommandOption):

if (!deploymentId) {
const deploymentsList = await script.projects.deployments.list({scriptId});
if (deploymentsList.status !== 200) logError(getDescriptionFrom(deploymentsList.statusText));
if (deploymentsList.status !== 200) throw new Error(getDescriptionFrom(deploymentsList.statusText));

const deployments = deploymentsList.data.deployments ?? [];
if (deployments.length === 0) logError(ERROR.SCRIPT_ID_INCORRECT(scriptId));
if (deployments.length === 0) throw new Error(ERROR.SCRIPT_ID_INCORRECT(scriptId));

// @HEAD (Read-only deployments) may not be deleted.
if (deployments.length <= 1) logError(ERROR.SCRIPT_ID_INCORRECT(scriptId));
if (deployments.length <= 1) throw new Error(ERROR.SCRIPT_ID_INCORRECT(scriptId));

deploymentId = deployments[deployments.length - 1].deploymentId ?? '';
}
Expand All @@ -60,6 +60,6 @@ export default async (deploymentId: string | undefined, options: CommandOption):
if (spinner.isSpinning()) spinner.stop(true);
console.log(LOG.UNDEPLOYMENT_FINISH(deploymentId));
} else {
logError(ERROR.READ_ONLY_DELETE);
throw new Error(ERROR.READ_ONLY_DELETE);
}
};
6 changes: 3 additions & 3 deletions src/commands/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {loadAPICredentials, script} from '../auth';
import {descriptionPrompt} from '../inquirer';
import {LOG} from '../messages';
import {checkIfOnline, getDescriptionFrom, getProjectSettings, logError, spinner} from '../utils';
import {checkIfOnline, getDescriptionFrom, getProjectSettings, spinner} from '../utils';

/**
* Creates a new version of an Apps Script project.
Expand All @@ -23,10 +23,10 @@ export default async (description?: string): Promise<void> => {
description,
},
});
if (spinner.isSpinning()) spinner.stop(true);
if (versions.status === 200) {
if (spinner.isSpinning()) spinner.stop(true);
console.log(LOG.VERSION_CREATED(versions.data.versionNumber ?? -1));
} else {
logError(getDescriptionFrom(versions.statusText));
throw new Error(getDescriptionFrom(versions.statusText));
}
};
6 changes: 3 additions & 3 deletions src/commands/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {script_v1 as scriptV1} from 'googleapis';

import {loadAPICredentials, script} from '../auth';
import {LOG} from '../messages';
import {checkIfOnline, getDescriptionFrom, getProjectSettings, logError, spinner} from '../utils';
import {checkIfOnline, getDescriptionFrom, getProjectSettings, spinner} from '../utils';

/**
* Lists versions of an Apps Script project.
Expand Down Expand Up @@ -42,9 +42,9 @@ export default async (): Promise<void> => {
console.log(LOG.VERSION_DESCRIPTION(version));
});
} else {
logError(LOG.DEPLOYMENT_DNE);
throw new Error(LOG.DEPLOYMENT_DNE);
}
} else {
logError(getDescriptionFrom(response.statusText));
throw new Error(getDescriptionFrom(response.statusText));
}
};