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

fix: remove online check #936

Merged
merged 2 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {ReadonlyDeep} from 'type-fest';
import {ClaspError} from './clasp-error.js';
import {DOTFILE} from './dotfile.js';
import {ERROR, LOG} from './messages.js';
import {checkIfOnlineOrDie, getOAuthSettings} from './utils.js';
import {getOAuthSettings} from './utils.js';
import type {ClaspToken} from './dotfile';
import type {ClaspCredentials} from './utils';

Expand Down Expand Up @@ -291,7 +291,6 @@ const setOauthClientCredentials = async (rc: ClaspToken) => {

// Set credentials and refresh them.
try {
await checkIfOnlineOrDie();
if (rc.isLocalCreds) {
const {clientId, clientSecret, redirectUri} = rc.oauth2ClientSettings;
localOAuth2Client = new OAuth2Client({clientId, clientSecret, redirectUri});
Expand Down
3 changes: 1 addition & 2 deletions src/commands/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {discovery, loadAPICredentials, serviceUsage} from '../auth.js';
import {ClaspError} from '../clasp-error.js';
import {ERROR} from '../messages.js';
import {URL} from '../urls.js';
import {checkIfOnlineOrDie, getProjectId} from '../utils.js';
import {getProjectId} from '../utils.js';

type DirectoryItem = Unpacked<discoveryV1.Schema$DirectoryList['items']>;
type PublicAdvancedService = ReadonlyDeep<Required<NonNullable<DirectoryItem>>>;
Expand Down Expand Up @@ -38,7 +38,6 @@ export default async (options: CommandOption): Promise<void> => {
disable: async () => enableOrDisableAPI(serviceName, false),
enable: async () => enableOrDisableAPI(serviceName, true),
list: async () => {
await checkIfOnlineOrDie();
/**
* List currently enabled APIs.
*/
Expand Down
3 changes: 1 addition & 2 deletions src/commands/clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {fetchProject, hasProject, writeProjectFiles} from '../files.js';
import {ScriptIdPrompt, scriptIdPrompt} from '../inquirer.js';
import {ERROR, LOG} from '../messages.js';
import {extractScriptId} from '../urls.js';
import {checkIfOnlineOrDie, saveProject, spinner} from '../utils.js';
import {saveProject, spinner} from '../utils.js';
import status from './status.js';
import {Conf} from '../conf.js';

Expand All @@ -32,7 +32,6 @@ export default async (
if (options.rootDir) {
config.projectRootDirectory = options.rootDir;
}
await checkIfOnlineOrDie();
if (hasProject()) {
throw new ClaspError(ERROR.FOLDER_EXISTS());
}
Expand Down
10 changes: 1 addition & 9 deletions src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@ import {fetchProject, hasProject, writeProjectFiles} from '../files.js';
import {scriptTypePrompt} from '../inquirer.js';
import {manifestExists} from '../manifest.js';
import {ERROR, LOG} from '../messages.js';
import {
checkIfOnlineOrDie,
getDefaultProjectName,
getProjectSettings,
saveProject,
spinner,
stopSpinner,
} from '../utils.js';
import {getDefaultProjectName, getProjectSettings, saveProject, spinner, stopSpinner} from '../utils.js';
import {Conf} from '../conf.js';

const config = Conf.get();
Expand All @@ -39,7 +32,6 @@ export default async (options: CommandOption): Promise<void> => {
}

// Handle common errors.
await checkIfOnlineOrDie();
if (hasProject()) {
throw new ClaspError(ERROR.FOLDER_EXISTS());
}
Expand Down
3 changes: 1 addition & 2 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.js';
import {ClaspError} from '../clasp-error.js';
import {PROJECT_MANIFEST_BASENAME as manifestFileName} from '../constants.js';
import {ERROR, LOG} from '../messages.js';
import {checkIfOnlineOrDie, getProjectSettings, spinner, stopSpinner} from '../utils.js';
import {getProjectSettings, spinner, stopSpinner} from '../utils.js';

interface CommandOption {
readonly versionNumber?: number;
Expand All @@ -17,7 +17,6 @@ interface CommandOption {
* @param options.deploymentId {string} The deployment ID to redeploy.
*/
export default async (options: CommandOption): Promise<void> => {
await checkIfOnlineOrDie();
await loadAPICredentials();
const {scriptId} = await getProjectSettings();
if (!scriptId) {
Expand Down
3 changes: 1 addition & 2 deletions src/commands/deployments.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {loadAPICredentials, script} from '../auth.js';
import {ClaspError} from '../clasp-error.js';
import {LOG} from '../messages.js';
import {checkIfOnlineOrDie, getProjectSettings, spinner, stopSpinner} from '../utils.js';
import {getProjectSettings, spinner, stopSpinner} from '../utils.js';

/**
* Lists a script's deployments.
*/
export default async (): Promise<void> => {
await checkIfOnlineOrDie();
await loadAPICredentials();
const {scriptId} = await getProjectSettings();
if (scriptId) {
Expand Down
3 changes: 1 addition & 2 deletions src/commands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {drive, loadAPICredentials} from '../auth.js';
import {ClaspError} from '../clasp-error.js';
import {ERROR, LOG} from '../messages.js';
import {URL} from '../urls.js';
import {checkIfOnlineOrDie, ellipsize, spinner, stopSpinner} from '../utils.js';
import {ellipsize, spinner, stopSpinner} from '../utils.js';

interface CommandOption {
readonly noShorten: boolean;
Expand All @@ -13,7 +13,6 @@ interface CommandOption {
* @param options.noShorten {boolean}
*/
export default async (options: CommandOption): Promise<void> => {
await checkIfOnlineOrDie();
await loadAPICredentials();

spinner.start(LOG.FINDING_SCRIPTS);
Expand Down
4 changes: 1 addition & 3 deletions src/commands/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {authorize, defaultScopes, getLoggedInEmail, scopeWebAppDeploy} from '../
import {FS_OPTIONS} from '../constants.js';
import {readManifest} from '../manifest.js';
import {ERROR, LOG} from '../messages.js';
import {checkIfOnlineOrDie, hasOauthClientSettings, safeIsOnline} from '../utils.js';
import {hasOauthClientSettings, safeIsOnline} from '../utils.js';
import type {ClaspCredentials} from '../utils.js';

const {readJsonSync} = fs;
Expand Down Expand Up @@ -49,8 +49,6 @@ export default async (options: CommandOption): Promise<void> => {
}

console.log(LOG.LOGIN(isLocalLogin));
await checkIfOnlineOrDie();

// Localhost check
const useLocalhost = Boolean(options.localhost);

Expand Down
10 changes: 1 addition & 9 deletions src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@ import {DOTFILE, ProjectSettings} from '../dotfile.js';
import {projectIdPrompt} from '../inquirer.js';
import {ERROR, LOG} from '../messages.js';
import {URL} from '../urls.js';
import {
checkIfOnlineOrDie,
getErrorMessage,
getProjectSettings,
isValidProjectId,
spinner,
stopSpinner,
} from '../utils.js';
import {getErrorMessage, getProjectSettings, isValidProjectId, spinner, stopSpinner} from '../utils.js';

interface CommandOption {
readonly json?: boolean;
Expand All @@ -35,7 +28,6 @@ interface CommandOption {
* @param options.simplified {boolean} If true, the command will remove timestamps from the logs.
*/
export default async (options: CommandOption): Promise<void> => {
await checkIfOnlineOrDie();
// Get project settings.
const projectSettings = await getProjectSettings();
let projectId = options.setup ? await setupLogs(projectSettings) : projectSettings.projectId;
Expand Down
3 changes: 1 addition & 2 deletions src/commands/pull.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {fetchProject, writeProjectFiles} from '../files.js';
import {LOG} from '../messages.js';
import {checkIfOnlineOrDie, getProjectSettings, spinner, stopSpinner} from '../utils.js';
import {getProjectSettings, spinner, stopSpinner} from '../utils.js';

interface CommandOption {
readonly versionNumber?: number;
Expand All @@ -12,7 +12,6 @@ interface CommandOption {
* If not provided, the project's HEAD version is returned.
*/
export default async (options: CommandOption): Promise<void> => {
await checkIfOnlineOrDie();
const {scriptId, rootDir} = await getProjectSettings();
if (scriptId) {
spinner.start(LOG.PULLING);
Expand Down
3 changes: 1 addition & 2 deletions src/commands/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {fetchProject, pushFiles} from '../files.js';
import {overwritePrompt} from '../inquirer.js';
import {isValidManifest} from '../manifest.js';
import {LOG} from '../messages.js';
import {checkIfOnlineOrDie, getProjectSettings, spinner} from '../utils.js';
import {getProjectSettings, spinner} from '../utils.js';

import type {ProjectSettings} from '../dotfile';

Expand All @@ -34,7 +34,6 @@ interface CommandOption {
* @param options.watch {boolean} If true, runs `clasp push` when any local file changes. Exit with ^C.
*/
export default async (options: CommandOption): Promise<void> => {
await checkIfOnlineOrDie();
await loadAPICredentials();
await isValidManifest();
const projectSettings = await getProjectSettings();
Expand Down
3 changes: 1 addition & 2 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {ClaspError} from '../clasp-error.js';
import {addScopeToManifest, isValidRunManifest} from '../manifest.js';
import {ERROR} from '../messages.js';
import {URL} from '../urls.js';
import {checkIfOnlineOrDie, getProjectSettings, parseJsonOrDie, spinner, stopSpinner} from '../utils.js';
import {getProjectSettings, parseJsonOrDie, spinner, stopSpinner} from '../utils.js';

interface CommandOption {
readonly nondev: boolean;
Expand All @@ -23,7 +23,6 @@ interface CommandOption {
* @requires `clasp login --creds` to be run beforehand.
*/
export default async (functionName: string, options: CommandOption): Promise<void> => {
await checkIfOnlineOrDie();
await loadAPICredentials();
const {scriptId} = await getProjectSettings();
const devMode = !options.nondev; // Defaults to true
Expand Down
3 changes: 1 addition & 2 deletions src/commands/status.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {getAllProjectFiles, getOrderedProjectFiles, logFileList, splitProjectFiles} from '../files.js';
import {LOG} from '../messages.js';
import {checkIfOnlineOrDie, getProjectSettings} from '../utils.js';
import {getProjectSettings} from '../utils.js';

interface CommandOption {
readonly json?: boolean;
Expand All @@ -11,7 +11,6 @@ interface CommandOption {
* @param options.json {boolean} Displays the status in json format.
*/
export default async ({json}: CommandOption = {json: false}): Promise<void> => {
await checkIfOnlineOrDie();
const {filePushOrder, scriptId, rootDir} = await getProjectSettings();
if (scriptId) {
const [toPush, toIgnore] = splitProjectFiles(await getAllProjectFiles(rootDir));
Expand Down
3 changes: 1 addition & 2 deletions src/commands/undeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import pMap from 'p-map';
import {loadAPICredentials, script} from '../auth.js';
import {ClaspError} from '../clasp-error.js';
import {ERROR, LOG} from '../messages.js';
import {checkIfOnlineOrDie, getProjectSettings, spinner, stopSpinner} from '../utils.js';
import {getProjectSettings, spinner, stopSpinner} from '../utils.js';

interface CommandOption {
readonly all?: boolean;
Expand All @@ -15,7 +15,6 @@ interface CommandOption {
* @param deploymentId {string} The deployment's ID
*/
export default async (deploymentId: string | undefined, options: CommandOption): Promise<void> => {
await checkIfOnlineOrDie();
await loadAPICredentials();
const {scriptId} = await getProjectSettings();
if (scriptId) {
Expand Down
3 changes: 1 addition & 2 deletions src/commands/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import {loadAPICredentials, script} from '../auth.js';
import {ClaspError} from '../clasp-error.js';
import {descriptionPrompt} from '../inquirer.js';
import {LOG} from '../messages.js';
import {checkIfOnlineOrDie, getProjectSettings, spinner, stopSpinner} from '../utils.js';
import {getProjectSettings, spinner, stopSpinner} from '../utils.js';

/**
* Creates a new version of an Apps Script project.
*/
export default async (description?: string): Promise<void> => {
await checkIfOnlineOrDie();
await loadAPICredentials();

const {scriptId} = await getProjectSettings();
Expand Down
3 changes: 1 addition & 2 deletions src/commands/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import {script_v1 as scriptV1} from 'googleapis';
import {loadAPICredentials, script} from '../auth.js';
import {ClaspError} from '../clasp-error.js';
import {LOG} from '../messages.js';
import {checkIfOnlineOrDie, getProjectSettings, spinner, stopSpinner} from '../utils.js';
import {getProjectSettings, spinner, stopSpinner} from '../utils.js';

/**
* Lists versions of an Apps Script project.
*/
export default async (): Promise<void> => {
await checkIfOnlineOrDie();
await loadAPICredentials();

spinner.start('Grabbing versions…');
Expand Down
10 changes: 1 addition & 9 deletions src/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@ import {Conf} from './conf.js';
import {FS_OPTIONS, PROJECT_MANIFEST_FILENAME} from './constants.js';
import {DOTFILE} from './dotfile.js';
import {ERROR, LOG} from './messages.js';
import {
checkIfOnlineOrDie,
getApiFileType,
getErrorMessage,
getProjectSettings,
spinner,
stopSpinner,
} from './utils.js';
import {getApiFileType, getErrorMessage, getProjectSettings, spinner, stopSpinner} from './utils.js';

import type {TranspileOptions} from 'typescript';

Expand Down Expand Up @@ -300,7 +293,6 @@ export const fetchProject = async (
versionNumber?: number,
silent = false
): Promise<AppsScriptFile[]> => {
await checkIfOnlineOrDie();
await loadAPICredentials();
spinner.start();
let response;
Expand Down