diff --git a/index.ts b/index.ts index 6e7c0390..5e54803b 100755 --- a/index.ts +++ b/index.ts @@ -27,7 +27,6 @@ import { google } from 'googleapis'; import * as mkdirp from 'mkdirp'; const open = require('open'); const path = require('path'); -import * as pluralize from 'pluralize'; const commander = require('commander'); const readMultipleFiles = require('read-multiple-files'); import * as recursive from 'recursive-readdir'; @@ -40,7 +39,7 @@ import { DOT, PROJECT_NAME, PROJECT_MANIFEST_BASENAME, ClaspSettings, saveProjectId, manifestExists } from './src/utils.js'; import { oauth2Client, getAPICredentials, authorizeWithLocalhost, authorizeWithoutLocalhost } from './src/auth.js'; - +import { LOG } from './src/commands.js'; // An Apps Script API File interface AppsScriptFile { name: string; @@ -62,43 +61,6 @@ const script = google.script({ auth: oauth2Client, }); -// Log messages (some logs take required params) -export const LOG = { - AUTH_CODE: 'Enter the code from that page here: ', - AUTH_PAGE_SUCCESSFUL: `Logged in! You may close this page.`, // HTML Redirect Page - AUTH_SUCCESSFUL: `Saved the credentials to ${DOT.RC.PATH}. You may close the page.`, - AUTHORIZE: (authUrl: string) => `🔑 Authorize ${PROJECT_NAME} by visiting this url:\n${authUrl}\n`, - CLONE_SUCCESS: (fileNum: number) => `Cloned ${fileNum} ${pluralize('files', fileNum)}.`, - CLONING: 'Cloning files...', - CREATE_PROJECT_FINISH: (scriptId: string) => `Created new script: ${getScriptURL(scriptId)}`, - CREATE_PROJECT_START: (title: string) => `Creating new script: ${title}...`, - DEPLOYMENT_CREATE: 'Creating deployment...', - DEPLOYMENT_DNE: 'No deployed versions of script.', - DEPLOYMENT_LIST: (scriptId: string) => `Listing deployments for ${scriptId}...`, - DEPLOYMENT_START: (scriptId: string) => `Deploying project ${scriptId}...`, - FILES_TO_PUSH: 'Files to push were:', - FINDING_SCRIPTS: 'Finding your scripts...', - FINDING_SCRIPTS_DNE: 'No script files found.', - OPEN_PROJECT: (scriptId: string) => `Opening script: ${scriptId}`, - PULLING: 'Pulling files...', - STATUS_PUSH: 'The following files will be pushed by clasp push:', - STATUS_IGNORE: 'Untracked files:', - PUSH_SUCCESS: (numFiles: number) => `Pushed ${numFiles} ${pluralize('files', numFiles)}.`, - PUSH_FAILURE: 'Push failed. Errors:', - PUSHING: 'Pushing files...', - REDEPLOY_END: 'Updated deployment.', - REDEPLOY_START: 'Updating deployment...', - RENAME_FILE: (oldName: string, newName: string) => `Renamed file: ${oldName} -> ${newName}`, - UNDEPLOYMENT_FINISH: (deploymentId: string) => `Undeployed ${deploymentId}.`, - UNDEPLOYMENT_START: (deploymentId: string) => `Undeploy ${deploymentId}...`, - UNTITLED_SCRIPT_TITLE: 'Untitled Script', - VERSION_CREATE: 'Creating a new version...', - VERSION_CREATED: (versionNumber: string) => `Created version ${versionNumber}.`, - VERSION_DESCRIPTION: ({ versionNumber, description }: any) => `${versionNumber} - ` + - (description || '(no description)'), - VERSION_NUM: (numVersions: number) => `~ ${numVersions} ${pluralize('Version', numVersions)} ~`, -}; - /** * Requests authorization to manage Apps Script projects. * @param {boolean} useLocalhost True if a local HTTP server should be run diff --git a/src/auth.ts b/src/auth.ts index 4b1d2c17..5306182f 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -4,8 +4,7 @@ import * as http from 'http'; import * as url from 'url'; const open = require('open'); const readline = require('readline'); -//Just for now, until it moves into /src/commands.ts -import { LOG } from '../index.js'; +import { LOG } from './commands.js'; // API settings // @see https://developers.google.com/oauthplayground/ diff --git a/src/commands.ts b/src/commands.ts new file mode 100644 index 00000000..3074a308 --- /dev/null +++ b/src/commands.ts @@ -0,0 +1,39 @@ +import { DOT, PROJECT_NAME, getScriptURL } from './utils.js'; +import * as pluralize from 'pluralize'; + +// Log messages (some logs take required params) +export const LOG = { + AUTH_CODE: 'Enter the code from that page here: ', + AUTH_PAGE_SUCCESSFUL: `Logged in! You may close this page.`, // HTML Redirect Page + AUTH_SUCCESSFUL: `Saved the credentials to ${DOT.RC.PATH}. You may close the page.`, + AUTHORIZE: (authUrl: string) => `🔑 Authorize ${PROJECT_NAME} by visiting this url:\n${authUrl}\n`, + CLONE_SUCCESS: (fileNum: number) => `Cloned ${fileNum} ${pluralize('files', fileNum)}.`, + CLONING: 'Cloning files...', + CREATE_PROJECT_FINISH: (scriptId: string) => `Created new script: ${getScriptURL(scriptId)}`, + CREATE_PROJECT_START: (title: string) => `Creating new script: ${title}...`, + DEPLOYMENT_CREATE: 'Creating deployment...', + DEPLOYMENT_DNE: 'No deployed versions of script.', + DEPLOYMENT_LIST: (scriptId: string) => `Listing deployments for ${scriptId}...`, + DEPLOYMENT_START: (scriptId: string) => `Deploying project ${scriptId}...`, + FILES_TO_PUSH: 'Files to push were:', + FINDING_SCRIPTS: 'Finding your scripts...', + FINDING_SCRIPTS_DNE: 'No script files found.', + OPEN_PROJECT: (scriptId: string) => `Opening script: ${scriptId}`, + PULLING: 'Pulling files...', + STATUS_PUSH: 'The following files will be pushed by clasp push:', + STATUS_IGNORE: 'Untracked files:', + PUSH_SUCCESS: (numFiles: number) => `Pushed ${numFiles} ${pluralize('files', numFiles)}.`, + PUSH_FAILURE: 'Push failed. Errors:', + PUSHING: 'Pushing files...', + REDEPLOY_END: 'Updated deployment.', + REDEPLOY_START: 'Updating deployment...', + RENAME_FILE: (oldName: string, newName: string) => `Renamed file: ${oldName} -> ${newName}`, + UNDEPLOYMENT_FINISH: (deploymentId: string) => `Undeployed ${deploymentId}.`, + UNDEPLOYMENT_START: (deploymentId: string) => `Undeploy ${deploymentId}...`, + UNTITLED_SCRIPT_TITLE: 'Untitled Script', + VERSION_CREATE: 'Creating a new version...', + VERSION_CREATED: (versionNumber: string) => `Created version ${versionNumber}.`, + VERSION_DESCRIPTION: ({ versionNumber, description }: any) => `${versionNumber} - ` + + (description || '(no description)'), + VERSION_NUM: (numVersions: number) => `~ ${numVersions} ${pluralize('Version', numVersions)} ~`, + }; \ No newline at end of file