@google/clasp 2.4.2 → 3.0.0-alpha1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +253 -196
- package/build/src/auth/auth.js +176 -0
- package/build/src/auth/auth_code_flow.js +36 -0
- package/build/src/auth/credential_store.js +1 -0
- package/build/src/auth/file_credential_store.js +82 -0
- package/build/src/auth/localhost_auth_code_flow.js +62 -0
- package/build/src/auth/serverless_auth_code_flow.js +32 -0
- package/build/src/commands/clone-script.js +71 -0
- package/build/src/commands/create-deployment.js +33 -0
- package/build/src/commands/create-script.js +75 -0
- package/build/src/commands/create-version.js +31 -0
- package/build/src/commands/delete-deployment.js +71 -0
- package/build/src/commands/disable-api.js +19 -0
- package/build/src/commands/enable-api.js +31 -0
- package/build/src/commands/list-apis.js +23 -0
- package/build/src/commands/list-deployments.js +30 -0
- package/build/src/commands/list-scripts.js +28 -0
- package/build/src/commands/list-versions.js +29 -0
- package/build/src/commands/login.js +54 -53
- package/build/src/commands/logout.js +15 -15
- package/build/src/commands/open-apis.js +11 -0
- package/build/src/commands/open-container.js +15 -0
- package/build/src/commands/open-credentials.js +11 -0
- package/build/src/commands/open-logs.js +11 -0
- package/build/src/commands/open-script.js +18 -0
- package/build/src/commands/open-webapp.js +56 -0
- package/build/src/commands/program.js +108 -0
- package/build/src/commands/pull.js +19 -18
- package/build/src/commands/push.js +64 -74
- package/build/src/commands/run-function.js +61 -0
- package/build/src/commands/setup-logs.js +12 -0
- package/build/src/commands/show-authorized-user.js +18 -0
- package/build/src/commands/show-file-status.js +34 -0
- package/build/src/commands/tail-logs.js +92 -0
- package/build/src/commands/utils.js +82 -0
- package/build/src/constants.js +0 -3
- package/build/src/{apis.js → core/apis.js} +90 -92
- package/build/src/core/clasp.js +171 -0
- package/build/src/core/files.js +359 -0
- package/build/src/core/functions.js +51 -0
- package/build/src/core/logs.js +41 -0
- package/build/src/core/manifest.js +1 -0
- package/build/src/core/project.js +313 -0
- package/build/src/core/services.js +179 -0
- package/build/src/core/utils.js +121 -0
- package/build/src/index.js +16 -354
- package/build/src/intl.js +34 -0
- package/docs/README.md +1 -4
- package/docs/config-files.md +4 -5
- package/docs/run.md +26 -7
- package/package.json +87 -51
- package/CHANGELOG.md +0 -66
- package/build/src/apis.d.ts +0 -34
- package/build/src/apis.js.map +0 -1
- package/build/src/apiutils.d.ts +0 -16
- package/build/src/apiutils.js +0 -81
- package/build/src/apiutils.js.map +0 -1
- package/build/src/auth.d.ts +0 -34
- package/build/src/auth.js +0 -295
- package/build/src/auth.js.map +0 -1
- package/build/src/clasp-error.d.ts +0 -3
- package/build/src/clasp-error.js +0 -10
- package/build/src/clasp-error.js.map +0 -1
- package/build/src/commands/apis.d.ts +0 -10
- package/build/src/commands/apis.js +0 -91
- package/build/src/commands/apis.js.map +0 -1
- package/build/src/commands/clone.d.ts +0 -13
- package/build/src/commands/clone.js +0 -59
- package/build/src/commands/clone.js.map +0 -1
- package/build/src/commands/create.d.ts +0 -16
- package/build/src/commands/create.js +0 -81
- package/build/src/commands/create.js.map +0 -1
- package/build/src/commands/default.d.ts +0 -8
- package/build/src/commands/default.js +0 -10
- package/build/src/commands/default.js.map +0 -1
- package/build/src/commands/deploy.d.ts +0 -13
- package/build/src/commands/deploy.js +0 -51
- package/build/src/commands/deploy.js.map +0 -1
- package/build/src/commands/deployments.d.ts +0 -5
- package/build/src/commands/deployments.js +0 -29
- package/build/src/commands/deployments.js.map +0 -1
- package/build/src/commands/list.d.ts +0 -9
- package/build/src/commands/list.js +0 -34
- package/build/src/commands/list.js.map +0 -1
- package/build/src/commands/login.d.ts +0 -14
- package/build/src/commands/login.js.map +0 -1
- package/build/src/commands/logout.d.ts +0 -5
- package/build/src/commands/logout.js.map +0 -1
- package/build/src/commands/logs.d.ts +0 -17
- package/build/src/commands/logs.js +0 -181
- package/build/src/commands/logs.js.map +0 -1
- package/build/src/commands/open.d.ts +0 -15
- package/build/src/commands/open.js +0 -89
- package/build/src/commands/open.js.map +0 -1
- package/build/src/commands/pull.d.ts +0 -10
- package/build/src/commands/pull.js.map +0 -1
- package/build/src/commands/push.d.ts +0 -11
- package/build/src/commands/push.js.map +0 -1
- package/build/src/commands/run.d.ts +0 -14
- package/build/src/commands/run.js +0 -130
- package/build/src/commands/run.js.map +0 -1
- package/build/src/commands/setting.d.ts +0 -8
- package/build/src/commands/setting.js +0 -53
- package/build/src/commands/setting.js.map +0 -1
- package/build/src/commands/status.d.ts +0 -9
- package/build/src/commands/status.js +0 -25
- package/build/src/commands/status.js.map +0 -1
- package/build/src/commands/undeploy.d.ts +0 -9
- package/build/src/commands/undeploy.js +0 -55
- package/build/src/commands/undeploy.js.map +0 -1
- package/build/src/commands/version.d.ts +0 -5
- package/build/src/commands/version.js +0 -22
- package/build/src/commands/version.js.map +0 -1
- package/build/src/commands/versions.d.ts +0 -5
- package/build/src/commands/versions.js +0 -41
- package/build/src/commands/versions.js.map +0 -1
- package/build/src/conf.d.ts +0 -40
- package/build/src/conf.js +0 -100
- package/build/src/conf.js.map +0 -1
- package/build/src/constants.d.ts +0 -6
- package/build/src/constants.js.map +0 -1
- package/build/src/dotfile.d.ts +0 -50
- package/build/src/dotfile.js +0 -71
- package/build/src/dotfile.js.map +0 -1
- package/build/src/files.d.ts +0 -70
- package/build/src/files.js +0 -318
- package/build/src/files.js.map +0 -1
- package/build/src/index.d.ts +0 -18
- package/build/src/index.js.map +0 -1
- package/build/src/inquirer.d.ts +0 -82
- package/build/src/inquirer.js +0 -111
- package/build/src/inquirer.js.map +0 -1
- package/build/src/manifest.d.ts +0 -123
- package/build/src/manifest.js +0 -142
- package/build/src/manifest.js.map +0 -1
- package/build/src/messages.d.ts +0 -110
- package/build/src/messages.js +0 -161
- package/build/src/messages.js.map +0 -1
- package/build/src/urls.d.ts +0 -21
- package/build/src/urls.js +0 -33
- package/build/src/urls.js.map +0 -1
- package/build/src/utils.d.ts +0 -102
- package/build/src/utils.js +0 -232
- package/build/src/utils.js.map +0 -1
- package/docs/develop.md +0 -81
- package/docs/esmodules.md +0 -81
- package/docs/running-locally.md +0 -31
- package/docs/settings.md +0 -56
- package/docs/typescript.md +0 -354
package/build/src/auth.js
DELETED
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
import { OAuth2Client } from 'google-auth-library';
|
|
2
|
-
import { google } from 'googleapis';
|
|
3
|
-
import { createServer } from 'http';
|
|
4
|
-
import open from 'open';
|
|
5
|
-
import readline from 'readline';
|
|
6
|
-
import enableDestroy from 'server-destroy';
|
|
7
|
-
import { ClaspError } from './clasp-error.js';
|
|
8
|
-
import { DOTFILE } from './dotfile.js';
|
|
9
|
-
import { ERROR, LOG } from './messages.js';
|
|
10
|
-
import { getOAuthSettings } from './utils.js';
|
|
11
|
-
/**
|
|
12
|
-
* Authentication with Google's APIs.
|
|
13
|
-
*/
|
|
14
|
-
// Auth is complicated. Consider yourself warned.
|
|
15
|
-
// GLOBAL: clasp login will store this (~/.clasprc.json):
|
|
16
|
-
// {
|
|
17
|
-
// "access_token": "XXX",
|
|
18
|
-
// "refresh_token": "1/k4rt_hgxbeGdaRag2TSVgnXgUrWcXwerPpvlzGG1peHVfzI58EZH0P25c7ykiRYd",
|
|
19
|
-
// "scope": "https://www.googleapis.com/auth/script.projects https://www.googleapis.com/auth/script ...",
|
|
20
|
-
// "token_type": "Bearer",
|
|
21
|
-
// "expiry_date": 1539130731398
|
|
22
|
-
// }
|
|
23
|
-
// LOCAL: clasp login will store this (./.clasprc.json):
|
|
24
|
-
// {
|
|
25
|
-
// "token": {
|
|
26
|
-
// "access_token": "XXX",
|
|
27
|
-
// "refresh_token": "1/k4rw_hgxbeGdaRag2TSVgnXgUrWcXwerPpvlzGG1peHVfzI58EZH0P25c7ykiRYd",
|
|
28
|
-
// "scope": "https://www.googleapis.com/auth/script.projects https://www.googleapis.com/auth/script ...",
|
|
29
|
-
// "token_type": "Bearer",
|
|
30
|
-
// "expiry_date": 1539130731398
|
|
31
|
-
// },
|
|
32
|
-
// // Settings
|
|
33
|
-
// "oauth2ClientSettings": {
|
|
34
|
-
// "clientId": "807925367021-infvb16rd7lasqi22q2npeahkeodfrq5.apps.googleusercontent.com",
|
|
35
|
-
// "clientSecret": "9dbdeOCRHUyriewCoDrLHtPg",
|
|
36
|
-
// "redirectUri": "http://localhost"
|
|
37
|
-
// },
|
|
38
|
-
// "isLocalCreds": true
|
|
39
|
-
// }
|
|
40
|
-
// API settings
|
|
41
|
-
// @see https://developers.google.com/oauthplayground/
|
|
42
|
-
const REDIRECT_URI_OOB = 'urn:ietf:wg:oauth:2.0:oob';
|
|
43
|
-
const globalOauth2ClientSettings = {
|
|
44
|
-
clientId: '1072944905499-vm2v2i5dvn0a0d2o4ca36i1vge8cvbn0.apps.googleusercontent.com',
|
|
45
|
-
clientSecret: 'v6V3fKV_zWU7iw1DrpO1rknX',
|
|
46
|
-
redirectUri: 'http://localhost',
|
|
47
|
-
};
|
|
48
|
-
const globalOAuth2Client = new OAuth2Client(globalOauth2ClientSettings);
|
|
49
|
-
let localOAuth2Client; // Must be set up after authorize.
|
|
50
|
-
// *Global* Google API clients
|
|
51
|
-
export const discovery = google.discovery({ version: 'v1' });
|
|
52
|
-
export const drive = google.drive({ version: 'v3', auth: globalOAuth2Client });
|
|
53
|
-
export const logger = google.logging({ version: 'v2', auth: globalOAuth2Client });
|
|
54
|
-
export const script = google.script({ version: 'v1', auth: globalOAuth2Client });
|
|
55
|
-
export const serviceUsage = google.serviceusage({ version: 'v1', auth: globalOAuth2Client });
|
|
56
|
-
/**
|
|
57
|
-
* Gets the local OAuth client for the Google Apps Script API.
|
|
58
|
-
* Only the Apps Script API needs to use local credential for the Execution API (script.run).
|
|
59
|
-
* @see https://developers.google.com/apps-script/api/how-tos/execute
|
|
60
|
-
*/
|
|
61
|
-
export const getLocalScript = async () => google.script({ version: 'v1', auth: localOAuth2Client });
|
|
62
|
-
export const scopeWebAppDeploy = 'https://www.googleapis.com/auth/script.webapp.deploy'; // Scope needed for script.run
|
|
63
|
-
export const defaultScopes = [
|
|
64
|
-
// Default to clasp scopes
|
|
65
|
-
'https://www.googleapis.com/auth/script.deployments',
|
|
66
|
-
'https://www.googleapis.com/auth/script.projects',
|
|
67
|
-
scopeWebAppDeploy,
|
|
68
|
-
'https://www.googleapis.com/auth/drive.metadata.readonly',
|
|
69
|
-
'https://www.googleapis.com/auth/drive.file',
|
|
70
|
-
'https://www.googleapis.com/auth/service.management',
|
|
71
|
-
'https://www.googleapis.com/auth/logging.read',
|
|
72
|
-
'https://www.googleapis.com/auth/userinfo.email',
|
|
73
|
-
'https://www.googleapis.com/auth/userinfo.profile',
|
|
74
|
-
// Extra scope since service.management doesn't work alone
|
|
75
|
-
'https://www.googleapis.com/auth/cloud-platform',
|
|
76
|
-
];
|
|
77
|
-
/**
|
|
78
|
-
* Requests authorization to manage Apps Script projects.
|
|
79
|
-
* @param {boolean} useLocalhost Uses a local HTTP server if true. Manual entry o.w.
|
|
80
|
-
* @param {ClaspCredentials?} creds An optional credentials object.
|
|
81
|
-
* @param {string[]} [scopes=[]] List of OAuth scopes to authorize.
|
|
82
|
-
*/
|
|
83
|
-
export const authorize = async (options) => {
|
|
84
|
-
try {
|
|
85
|
-
// Set OAuth2 Client Options
|
|
86
|
-
let oAuth2ClientOptions;
|
|
87
|
-
if (options.creds) {
|
|
88
|
-
// If we passed our own creds
|
|
89
|
-
// Use local credentials
|
|
90
|
-
const { client_id: clientId, client_secret: clientSecret, project_id, redirect_uris: redirectUris, } = options.creds.installed;
|
|
91
|
-
console.log(LOG.CREDS_FROM_PROJECT(project_id));
|
|
92
|
-
oAuth2ClientOptions = { clientId, clientSecret, redirectUri: redirectUris[0] };
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
// Use global credentials
|
|
96
|
-
const globalOauth2ClientOptions = {
|
|
97
|
-
clientId: '1072944905499-vm2v2i5dvn0a0d2o4ca36i1vge8cvbn0.apps.googleusercontent.com',
|
|
98
|
-
clientSecret: 'v6V3fKV_zWU7iw1DrpO1rknX',
|
|
99
|
-
redirectUri: 'http://localhost',
|
|
100
|
-
};
|
|
101
|
-
oAuth2ClientOptions = globalOauth2ClientOptions;
|
|
102
|
-
}
|
|
103
|
-
// Set scopes
|
|
104
|
-
let scope = (options.creds
|
|
105
|
-
? // Set scopes to custom scopes
|
|
106
|
-
options.scopes
|
|
107
|
-
: defaultScopes);
|
|
108
|
-
if (options.creds && scope.length === 0) {
|
|
109
|
-
scope = defaultScopes;
|
|
110
|
-
// TODO formal error
|
|
111
|
-
// throw new ClaspError('You need to specify scopes in the manifest.' +
|
|
112
|
-
// 'View appsscript.json. Add a list of scopes in "oauthScopes"' +
|
|
113
|
-
// 'Tip:' +
|
|
114
|
-
// '1. clasp open' +
|
|
115
|
-
// '2. File > Project Properties > Scopes');
|
|
116
|
-
}
|
|
117
|
-
const oAuth2ClientAuthUrlOptions = { access_type: 'offline', scope };
|
|
118
|
-
// Grab a token from the credentials.
|
|
119
|
-
const token = await (options.useLocalhost ? authorizeWithLocalhost : authorizeWithoutLocalhost)(oAuth2ClientOptions, oAuth2ClientAuthUrlOptions);
|
|
120
|
-
console.log(`${LOG.AUTH_SUCCESSFUL}\n`);
|
|
121
|
-
// Save the token and own creds together.
|
|
122
|
-
let claspToken;
|
|
123
|
-
if (options.creds) {
|
|
124
|
-
const { client_id: clientId, client_secret: clientSecret, redirect_uris: redirectUri } = options.creds.installed;
|
|
125
|
-
// Save local ClaspCredentials.
|
|
126
|
-
claspToken = {
|
|
127
|
-
token,
|
|
128
|
-
oauth2ClientSettings: { clientId, clientSecret, redirectUri: redirectUri[0] },
|
|
129
|
-
isLocalCreds: true,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
// Save global ClaspCredentials.
|
|
134
|
-
claspToken = {
|
|
135
|
-
token,
|
|
136
|
-
oauth2ClientSettings: globalOauth2ClientSettings,
|
|
137
|
-
isLocalCreds: false,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
await DOTFILE.AUTH(claspToken.isLocalCreds).write(claspToken);
|
|
141
|
-
console.log(LOG.SAVED_CREDS(Boolean(options.creds)));
|
|
142
|
-
}
|
|
143
|
-
catch (error) {
|
|
144
|
-
if (error instanceof ClaspError) {
|
|
145
|
-
throw error;
|
|
146
|
-
}
|
|
147
|
-
throw new ClaspError(`${ERROR.ACCESS_TOKEN}${error}`);
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
export const getLoggedInEmail = async () => {
|
|
151
|
-
await loadAPICredentials();
|
|
152
|
-
try {
|
|
153
|
-
return (await google.oauth2('v2').userinfo.get({ auth: globalOAuth2Client })).data.email;
|
|
154
|
-
}
|
|
155
|
-
catch {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
/**
|
|
160
|
-
* Loads the Apps Script API credentials for the CLI.
|
|
161
|
-
*
|
|
162
|
-
* Required before every API call.
|
|
163
|
-
*/
|
|
164
|
-
export const loadAPICredentials = async (local = false) => {
|
|
165
|
-
// Gets the OAuth settings. May be local or global.
|
|
166
|
-
const rc = await getOAuthSettings(local);
|
|
167
|
-
await setOauthClientCredentials(rc);
|
|
168
|
-
return rc;
|
|
169
|
-
};
|
|
170
|
-
/**
|
|
171
|
-
* Requests authorization to manage Apps Script projects. Spins up
|
|
172
|
-
* a temporary HTTP server to handle the auth redirect.
|
|
173
|
-
* @param {OAuth2ClientOptions} oAuth2ClientOptions The required client options for auth
|
|
174
|
-
* @param {GenerateAuthUrlOpts} oAuth2ClientAuthUrlOptions Auth URL options
|
|
175
|
-
* Used for local/global testing.
|
|
176
|
-
*/
|
|
177
|
-
const authorizeWithLocalhost = async (oAuth2ClientOptions, oAuth2ClientAuthUrlOptions) => {
|
|
178
|
-
// Wait until the server is listening, otherwise we don't have
|
|
179
|
-
// the server port needed to set up the Oauth2Client.
|
|
180
|
-
const server = await new Promise(resolve => {
|
|
181
|
-
const s = createServer();
|
|
182
|
-
enableDestroy(s);
|
|
183
|
-
s.listen(0, () => resolve(s));
|
|
184
|
-
});
|
|
185
|
-
const { port } = server.address();
|
|
186
|
-
const client = new OAuth2Client({ ...oAuth2ClientOptions, redirectUri: `http://localhost:${port}` });
|
|
187
|
-
// TODO Add spinner
|
|
188
|
-
const authCode = await new Promise((resolve, reject) => {
|
|
189
|
-
server.on('request', (request, response) => {
|
|
190
|
-
var _a;
|
|
191
|
-
const urlParts = new URL((_a = request.url) !== null && _a !== void 0 ? _a : '', 'http://localhost').searchParams;
|
|
192
|
-
const code = urlParts.get('code');
|
|
193
|
-
const error = urlParts.get('error');
|
|
194
|
-
if (code) {
|
|
195
|
-
resolve(code);
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
reject(error);
|
|
199
|
-
}
|
|
200
|
-
response.end(LOG.AUTH_PAGE_SUCCESSFUL);
|
|
201
|
-
});
|
|
202
|
-
const authUrl = client.generateAuthUrl(oAuth2ClientAuthUrlOptions);
|
|
203
|
-
console.log(LOG.AUTHORIZE(authUrl));
|
|
204
|
-
(async () => open(authUrl))();
|
|
205
|
-
});
|
|
206
|
-
server.destroy();
|
|
207
|
-
return (await client.getToken(authCode)).tokens;
|
|
208
|
-
};
|
|
209
|
-
/**
|
|
210
|
-
* Requests authorization to manage Apps Script projects. Requires the user to
|
|
211
|
-
* manually copy/paste the authorization code. No HTTP server is used.
|
|
212
|
-
* @param {OAuth2ClientOptions} oAuth2ClientOptions The required client options for auth.
|
|
213
|
-
* @param {GenerateAuthUrlOpts} oAuth2ClientAuthUrlOptions Auth URL options
|
|
214
|
-
*/
|
|
215
|
-
const authorizeWithoutLocalhost = async (oAuth2ClientOptions, oAuth2ClientAuthUrlOptions) => {
|
|
216
|
-
const client = new OAuth2Client({ ...oAuth2ClientOptions, redirectUri: REDIRECT_URI_OOB });
|
|
217
|
-
console.log(LOG.AUTHORIZE(client.generateAuthUrl(oAuth2ClientAuthUrlOptions)));
|
|
218
|
-
// TODO Add spinner
|
|
219
|
-
const authCode = await new Promise((resolve, reject) => {
|
|
220
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
221
|
-
rl.question(LOG.AUTH_CODE, (code) => {
|
|
222
|
-
rl.close();
|
|
223
|
-
if (code && code.length > 0) {
|
|
224
|
-
resolve(code);
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
reject(new ClaspError('No authorization code entered.'));
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
return (await client.getToken(authCode)).tokens;
|
|
232
|
-
};
|
|
233
|
-
/**
|
|
234
|
-
* Set OAuth client credentails from rc.
|
|
235
|
-
* Can be global or local.
|
|
236
|
-
* Saves new credentials if access token refreshed.
|
|
237
|
-
* @param {ClaspToken} rc OAuth client settings from rc file.
|
|
238
|
-
*/
|
|
239
|
-
// Because of mutation:
|
|
240
|
-
const setOauthClientCredentials = async (rc) => {
|
|
241
|
-
/**
|
|
242
|
-
* Refreshes the credentials and saves them.
|
|
243
|
-
*/
|
|
244
|
-
const refreshCredentials = async (oAuthClient) => {
|
|
245
|
-
await oAuthClient.getAccessToken(); // Refreshes expiry date if required
|
|
246
|
-
rc.token = oAuthClient.credentials;
|
|
247
|
-
};
|
|
248
|
-
// Set credentials and refresh them.
|
|
249
|
-
try {
|
|
250
|
-
if (rc.isLocalCreds) {
|
|
251
|
-
const { clientId, clientSecret, redirectUri } = rc.oauth2ClientSettings;
|
|
252
|
-
localOAuth2Client = new OAuth2Client({ clientId, clientSecret, redirectUri });
|
|
253
|
-
localOAuth2Client.setCredentials(rc.token);
|
|
254
|
-
await refreshCredentials(localOAuth2Client);
|
|
255
|
-
}
|
|
256
|
-
else {
|
|
257
|
-
globalOAuth2Client.setCredentials(rc.token);
|
|
258
|
-
await refreshCredentials(globalOAuth2Client);
|
|
259
|
-
}
|
|
260
|
-
// Save the credentials.
|
|
261
|
-
await DOTFILE.AUTH(rc.isLocalCreds).write(rc);
|
|
262
|
-
}
|
|
263
|
-
catch (error) {
|
|
264
|
-
if (error instanceof ClaspError) {
|
|
265
|
-
throw error;
|
|
266
|
-
}
|
|
267
|
-
throw new ClaspError(`${ERROR.ACCESS_TOKEN}${error}`);
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
// /**
|
|
271
|
-
// * Compare global OAuth client scopes against manifest and prompt user to
|
|
272
|
-
// * authorize if new scopes found (local OAuth credentails only).
|
|
273
|
-
// * @param {ClaspToken} rc OAuth client settings from rc file.
|
|
274
|
-
// */
|
|
275
|
-
// // TODO: currently unused. Check relevancy
|
|
276
|
-
// export async function checkOauthScopes(rc: ReadonlyDeep<ClaspToken>) {
|
|
277
|
-
// try {
|
|
278
|
-
// await checkIfOnline();
|
|
279
|
-
// await setOauthClientCredentials(rc);
|
|
280
|
-
// const {scopes} = await globalOAuth2Client.getTokenInfo(globalOAuth2Client.credentials.access_token as string);
|
|
281
|
-
// const {oauthScopes} = await readManifest();
|
|
282
|
-
// const newScopes = oauthScopes && oauthScopes.length > 1 ? oauthScopes.filter(x => !scopes.includes(x)) : [];
|
|
283
|
-
// if (newScopes.length === 0) return;
|
|
284
|
-
// console.log('New authorization scopes detected in manifest:\n', newScopes);
|
|
285
|
-
// const answers = await oauthScopesPrompt();
|
|
286
|
-
// if (answers.doAuth) {
|
|
287
|
-
// if (!rc.isLocalCreds) throw new ClaspError(ERROR.NO_LOCAL_CREDENTIALS);
|
|
288
|
-
// await authorize({useLocalhost: answers.localhost, scopes: newScopes});
|
|
289
|
-
// }
|
|
290
|
-
// } catch (error) {
|
|
291
|
-
// if (error instanceof ClaspError) throw error;
|
|
292
|
-
// throw new ClaspError(ERROR.BAD_REQUEST((error as {message: string}).message));
|
|
293
|
-
// }
|
|
294
|
-
// }
|
|
295
|
-
//# sourceMappingURL=auth.js.map
|
package/build/src/auth.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;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AK,CAAC;SACb;QAED,MAAM,IAAI,UAAU,CAAC,GAAG,KAAK,CAAC,YAAY,GAAG,KAAK,EAAE,CAAC,CAAC;KACvD;AACH,CAAC,CAAC;AAEF,MAAM;AACN,4EAA4E;AAC5E,mEAAmE;AACnE,gEAAgE;AAChE,MAAM;AACN,6CAA6C;AAC7C,yEAAyE;AACzE,UAAU;AACV,6BAA6B;AAC7B,2CAA2C;AAC3C,qHAAqH;AACrH,kDAAkD;AAClD,mHAAmH;AACnH,0CAA0C;AAC1C,kFAAkF;AAClF,iDAAiD;AAEjD,4BAA4B;AAC5B,gFAAgF;AAChF,+EAA+E;AAC/E,QAAQ;AACR,sBAAsB;AACtB,oDAAoD;AACpD,qFAAqF;AACrF,MAAM;AACN,IAAI"}
|
package/build/src/clasp-error.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export class ClaspError extends Error {
|
|
2
|
-
constructor(message, exitCode = 1) {
|
|
3
|
-
super(message);
|
|
4
|
-
// @see: typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html
|
|
5
|
-
Object.setPrototypeOf(this, new.target.prototype); // Restore prototype chain
|
|
6
|
-
this.name = ClaspError.name; // Stack traces display correctly now
|
|
7
|
-
process.exitCode = exitCode;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=clasp-error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clasp-error.js","sourceRoot":"","sources":["../../src/clasp-error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAe,EAAE,QAAQ,GAAG,CAAC;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,2EAA2E;QAC3E,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,0BAA0B;QAC7E,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,qCAAqC;QAClE,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
interface CommandOption {
|
|
2
|
-
readonly open?: string;
|
|
3
|
-
}
|
|
4
|
-
declare const _default: (options: CommandOption) => Promise<void>;
|
|
5
|
-
/**
|
|
6
|
-
* Acts as a router to apis subcommands
|
|
7
|
-
* Calls functions for list, enable, or disable
|
|
8
|
-
* Otherwise returns an error of command not supported
|
|
9
|
-
*/
|
|
10
|
-
export default _default;
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import open from 'open';
|
|
2
|
-
import { PUBLIC_ADVANCED_SERVICES } from '../apis.js';
|
|
3
|
-
import { enableOrDisableAPI } from '../apiutils.js';
|
|
4
|
-
import { discovery, loadAPICredentials, serviceUsage } from '../auth.js';
|
|
5
|
-
import { ClaspError } from '../clasp-error.js';
|
|
6
|
-
import { ERROR } from '../messages.js';
|
|
7
|
-
import { URL } from '../urls.js';
|
|
8
|
-
import { getProjectId } from '../utils.js';
|
|
9
|
-
/**
|
|
10
|
-
* Acts as a router to apis subcommands
|
|
11
|
-
* Calls functions for list, enable, or disable
|
|
12
|
-
* Otherwise returns an error of command not supported
|
|
13
|
-
*/
|
|
14
|
-
export default async (options) => {
|
|
15
|
-
await loadAPICredentials();
|
|
16
|
-
// clasp apis --open
|
|
17
|
-
if (options.open) {
|
|
18
|
-
return openApiUrl();
|
|
19
|
-
}
|
|
20
|
-
const [_bin, _sourcePath, ...args] = process.argv;
|
|
21
|
-
const [_command, subCommand, serviceName] = args;
|
|
22
|
-
// The apis subcommands.
|
|
23
|
-
const apiSubCommands = {
|
|
24
|
-
disable: async () => enableOrDisableAPI(serviceName, false),
|
|
25
|
-
enable: async () => enableOrDisableAPI(serviceName, true),
|
|
26
|
-
list: async () => {
|
|
27
|
-
var _a, _b, _c;
|
|
28
|
-
/**
|
|
29
|
-
* List currently enabled APIs.
|
|
30
|
-
*/
|
|
31
|
-
console.log('\n# Currently enabled APIs:');
|
|
32
|
-
const projectId = await getProjectId(); // Will prompt user to set up if required
|
|
33
|
-
const MAX_PAGE_SIZE = 200; // This is the max page size according to the docs.
|
|
34
|
-
const list = await serviceUsage.services.list({
|
|
35
|
-
parent: `projects/${projectId}`,
|
|
36
|
-
filter: 'state:ENABLED',
|
|
37
|
-
pageSize: MAX_PAGE_SIZE,
|
|
38
|
-
});
|
|
39
|
-
const serviceList = (_a = list.data.services) !== null && _a !== void 0 ? _a : [];
|
|
40
|
-
if (serviceList.length >= MAX_PAGE_SIZE) {
|
|
41
|
-
console.log('There is a bug with pagination. Please file an issue on Github.');
|
|
42
|
-
}
|
|
43
|
-
// Filter out the disabled ones. Print the enabled ones.
|
|
44
|
-
const enabledAPIs = serviceList.filter((service) => service.state === 'ENABLED');
|
|
45
|
-
for (const { config } of enabledAPIs) {
|
|
46
|
-
if (config === null || config === void 0 ? void 0 : config.documentation) {
|
|
47
|
-
const name = (_b = config.name) !== null && _b !== void 0 ? _b : 'Unknown name.';
|
|
48
|
-
console.log(`${name.slice(0, name.indexOf('.'))} - ${config.documentation.summary}`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* List available APIs.
|
|
53
|
-
*/
|
|
54
|
-
console.log('\n# List of available APIs:');
|
|
55
|
-
const { data } = await discovery.apis.list({
|
|
56
|
-
preferred: true,
|
|
57
|
-
});
|
|
58
|
-
const services = (_c = data.items) !== null && _c !== void 0 ? _c : [];
|
|
59
|
-
// Only get the public service IDs
|
|
60
|
-
const publicAdvancedServicesIds = PUBLIC_ADVANCED_SERVICES.map(advancedService => advancedService.serviceId);
|
|
61
|
-
// Merge discovery data with public services data.
|
|
62
|
-
const publicServices = publicAdvancedServicesIds
|
|
63
|
-
.map(publicServiceId => services.find(s => (s === null || s === void 0 ? void 0 : s.name) === publicServiceId))
|
|
64
|
-
.filter(service => (service === null || service === void 0 ? void 0 : service.id) && service.description);
|
|
65
|
-
// Sort the services based on id
|
|
66
|
-
publicServices.sort((a, b) => (a.id > b.id ? 1 : a.id < b.id ? -1 : 0));
|
|
67
|
-
// Format the list
|
|
68
|
-
for (const service of publicServices) {
|
|
69
|
-
console.log(`${service.name.padEnd(25)} - ${service.description.padEnd(60)}`);
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
undefined: async () => {
|
|
73
|
-
await apiSubCommands.list();
|
|
74
|
-
console.log(`# Try these commands:
|
|
75
|
-
- clasp apis list
|
|
76
|
-
- clasp apis enable slides
|
|
77
|
-
- clasp apis disable slides`);
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
if (subCommand in apiSubCommands) {
|
|
81
|
-
await apiSubCommands[subCommand]();
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
throw new ClaspError(ERROR.COMMAND_DNE(`apis ${subCommand}`));
|
|
85
|
-
};
|
|
86
|
-
const openApiUrl = async () => {
|
|
87
|
-
const apisUrl = URL.APIS(await getProjectId());
|
|
88
|
-
console.log(apisUrl);
|
|
89
|
-
await open(apisUrl, { wait: false });
|
|
90
|
-
};
|
|
91
|
-
//# sourceMappingURL=apis.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apis.js","sourceRoot":"","sources":["../../../src/commands/apis.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAC,wBAAwB,EAAC,MAAM,YAAY,CAAC;AACpD,OAAO,EAAC,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAC,SAAS,EAAE,kBAAkB,EAAE,YAAY,EAAC,MAAM,YAAY,CAAC;AACvE,OAAO,EAAC,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAC,KAAK,EAAC,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAC,GAAG,EAAC,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa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AE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAExE,kBAAkB;YAClB,KAAK,MAAM,OAAO,IAAI,cAAc,EAAE;gBACpC,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;aAC/E;QACH,CAAC;QACD,SAAS,EAAE,KAAK,IAAI,EAAE;YACpB,MAAM,cAAc,CAAC,IAAI,EAAE,CAAC;YAC5B,OAAO,CAAC,GAAG,CAAC;;;4BAGU,CAAC,CAAC;QAC1B,CAAC;KACF,CAAC;IAEF,IAAI,UAAU,IAAI,cAAc,EAAE;QAChC,MAAM,cAAc,CAAC,UAAU,CAAC,EAAE,CAAC;QACnC,OAAO;KACR;IAED,MAAM,IAAI,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,UAAU,EAAE,CAAC,CAAC,CAAC;AAChE,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,KAAK,IAAI,EAAE;IAC5B,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,YAAY,EAAE,CAAC,CAAC;IAC/C,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrB,MAAM,IAAI,CAAC,OAAO,EAAE,EAAC,IAAI,EAAE,KAAK,EAAC,CAAC,CAAC;AACrC,CAAC,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
interface CommandOption {
|
|
2
|
-
readonly rootDir: string;
|
|
3
|
-
}
|
|
4
|
-
declare const _default: (scriptId: string | undefined, versionNumber: number | undefined, options: CommandOption) => Promise<void>;
|
|
5
|
-
/**
|
|
6
|
-
* Fetches an Apps Script project.
|
|
7
|
-
* Prompts the user if no script ID is provided.
|
|
8
|
-
* @param scriptId {string} The Apps Script project ID or project URL to fetch.
|
|
9
|
-
* @param versionNumber {string} An optional version to pull the script from.
|
|
10
|
-
* @param options.rootDir {string} Specifies the local directory in which clasp will store your project files.
|
|
11
|
-
* If not specified, clasp will default to the current directory.
|
|
12
|
-
*/
|
|
13
|
-
export default _default;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { drive, loadAPICredentials } from '../auth.js';
|
|
2
|
-
import { ClaspError } from '../clasp-error.js';
|
|
3
|
-
import { fetchProject, hasProject, writeProjectFiles } from '../files.js';
|
|
4
|
-
import { scriptIdPrompt } from '../inquirer.js';
|
|
5
|
-
import { ERROR, LOG } from '../messages.js';
|
|
6
|
-
import { extractScriptId } from '../urls.js';
|
|
7
|
-
import { saveProject, spinner } from '../utils.js';
|
|
8
|
-
import status from './status.js';
|
|
9
|
-
import { Conf } from '../conf.js';
|
|
10
|
-
const config = Conf.get();
|
|
11
|
-
/**
|
|
12
|
-
* Fetches an Apps Script project.
|
|
13
|
-
* Prompts the user if no script ID is provided.
|
|
14
|
-
* @param scriptId {string} The Apps Script project ID or project URL to fetch.
|
|
15
|
-
* @param versionNumber {string} An optional version to pull the script from.
|
|
16
|
-
* @param options.rootDir {string} Specifies the local directory in which clasp will store your project files.
|
|
17
|
-
* If not specified, clasp will default to the current directory.
|
|
18
|
-
*/
|
|
19
|
-
export default async (scriptId, versionNumber, options) => {
|
|
20
|
-
if (options.rootDir) {
|
|
21
|
-
config.projectRootDirectory = options.rootDir;
|
|
22
|
-
}
|
|
23
|
-
if (hasProject()) {
|
|
24
|
-
throw new ClaspError(ERROR.FOLDER_EXISTS());
|
|
25
|
-
}
|
|
26
|
-
const id = scriptId ? extractScriptId(scriptId) : await getScriptId();
|
|
27
|
-
spinner.start(LOG.CLONING);
|
|
28
|
-
await saveProject({ scriptId: id, rootDir: config.projectRootDirectory }, false);
|
|
29
|
-
await writeProjectFiles(await fetchProject(id, versionNumber), config.projectRootDirectory);
|
|
30
|
-
await status();
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Lists a user's AppsScripts and prompts them to choose one to clone.
|
|
34
|
-
*/
|
|
35
|
-
const getScriptId = async () => {
|
|
36
|
-
await loadAPICredentials();
|
|
37
|
-
const { data, statusText } = await drive.files.list({
|
|
38
|
-
// fields: 'files(id, name)',
|
|
39
|
-
orderBy: 'modifiedByMeTime desc',
|
|
40
|
-
// pageSize: 10,
|
|
41
|
-
q: 'mimeType="application/vnd.google-apps.script"',
|
|
42
|
-
});
|
|
43
|
-
if (!data) {
|
|
44
|
-
throw new ClaspError(statusText !== null && statusText !== void 0 ? statusText : 'Unable to use the Drive API.');
|
|
45
|
-
}
|
|
46
|
-
const { files = [] } = data;
|
|
47
|
-
if (files.length > 0) {
|
|
48
|
-
const fileIds = files.map((file) => {
|
|
49
|
-
var _a, _b;
|
|
50
|
-
return ({
|
|
51
|
-
name: `${file.name.padEnd(20)} - ${LOG.SCRIPT_LINK((_a = file.id) !== null && _a !== void 0 ? _a : '')}`,
|
|
52
|
-
value: (_b = file.id) !== null && _b !== void 0 ? _b : '',
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
return (await scriptIdPrompt(fileIds)).scriptId;
|
|
56
|
-
}
|
|
57
|
-
throw new ClaspError(LOG.FINDING_SCRIPTS_DNE);
|
|
58
|
-
};
|
|
59
|
-
//# sourceMappingURL=clone.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clone.js","sourceRoot":"","sources":["../../../src/commands/clone.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,KAAK,EAAE,kBAAkB,EAAC,MAAM,YAAY,CAAC;AACrD,OAAO,EAAC,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAC,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAC,MAAM,aAAa,CAAC;AACxE,OAAO,EAAiB,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AM,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC;QAChD,6BAA6B;QAC7B,OAAO,EAAE,uBAAuB;QAChC,gBAAgB;QAChB,CAAC,EAAE,+CAA+C;KACnD,CAAC,CAAC;IACH,IAAI,CAAC,IAAI,EAAE;QACT,MAAM,IAAI,UAAU,CAAC,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,8BAA8B,CAAC,CAAC;KACpE;IAED,MAAM,EAAC,KAAK,GAAG,EAAE,EAAC,GAAG,IAAI,CAAC;IAC1B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;QACpB,MAAM,OAAO,GAAqB,KAAK,CAAC,GAAG,CAAC,CAAC,IAAmC,EAAE,EAAE;;YAAC,OAAA,CAAC;gBACpF,IAAI,EAAE,GAAG,IAAI,CAAC,IAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,GAAG,CAAC,WAAW,CAAC,MAAA,IAAI,CAAC,EAAE,mCAAI,EAAE,CAAC,EAAE;gBACpE,KAAK,EAAE,MAAA,IAAI,CAAC,EAAE,mCAAI,EAAE;aACrB,CAAC,CAAA;SAAA,CAAC,CAAC;QAEJ,OAAO,CAAC,MAAM,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;KACjD;IAED,MAAM,IAAI,UAAU,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;AAChD,CAAC,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
interface CommandOption {
|
|
2
|
-
readonly parentId?: string;
|
|
3
|
-
readonly rootDir?: string;
|
|
4
|
-
readonly title?: string;
|
|
5
|
-
readonly type?: string;
|
|
6
|
-
}
|
|
7
|
-
declare const _default: (options: CommandOption) => Promise<void>;
|
|
8
|
-
/**
|
|
9
|
-
* Creates a new Apps Script project.
|
|
10
|
-
* @param options.type {string} The type of the Apps Script project.
|
|
11
|
-
* @param options.title {string} The title of the Apps Script project's file
|
|
12
|
-
* @param options.parentId {string} The Drive ID of the G Suite doc this script is bound to.
|
|
13
|
-
* @param options.rootDir {string} Specifies the local directory in which clasp will store your project files.
|
|
14
|
-
* If not specified, clasp will default to the current directory.
|
|
15
|
-
*/
|
|
16
|
-
export default _default;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import is from '@sindresorhus/is';
|
|
2
|
-
import { SCRIPT_TYPES } from '../apis.js';
|
|
3
|
-
import { drive, loadAPICredentials, script } from '../auth.js';
|
|
4
|
-
import { ClaspError } from '../clasp-error.js';
|
|
5
|
-
import { fetchProject, hasProject, writeProjectFiles } from '../files.js';
|
|
6
|
-
import { scriptTypePrompt } from '../inquirer.js';
|
|
7
|
-
import { manifestExists } from '../manifest.js';
|
|
8
|
-
import { ERROR, LOG } from '../messages.js';
|
|
9
|
-
import { getDefaultProjectName, getProjectSettings, saveProject, spinner, stopSpinner } from '../utils.js';
|
|
10
|
-
import { Conf } from '../conf.js';
|
|
11
|
-
const config = Conf.get();
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new Apps Script project.
|
|
14
|
-
* @param options.type {string} The type of the Apps Script project.
|
|
15
|
-
* @param options.title {string} The title of the Apps Script project's file
|
|
16
|
-
* @param options.parentId {string} The Drive ID of the G Suite doc this script is bound to.
|
|
17
|
-
* @param options.rootDir {string} Specifies the local directory in which clasp will store your project files.
|
|
18
|
-
* If not specified, clasp will default to the current directory.
|
|
19
|
-
*/
|
|
20
|
-
export default async (options) => {
|
|
21
|
-
var _a;
|
|
22
|
-
if (options.rootDir) {
|
|
23
|
-
config.projectRootDirectory = options.rootDir;
|
|
24
|
-
}
|
|
25
|
-
// Handle common errors.
|
|
26
|
-
if (hasProject()) {
|
|
27
|
-
throw new ClaspError(ERROR.FOLDER_EXISTS());
|
|
28
|
-
}
|
|
29
|
-
await loadAPICredentials();
|
|
30
|
-
// Create defaults.
|
|
31
|
-
const { parentId: optionParentId, title: name = getDefaultProjectName(), type: optionType } = options;
|
|
32
|
-
let parentId = optionParentId;
|
|
33
|
-
const filetype = optionType !== null && optionType !== void 0 ? optionType : (optionParentId ? '' : (await scriptTypePrompt()).type);
|
|
34
|
-
// Create files with MIME type.
|
|
35
|
-
// https://developers.google.com/drive/api/v3/mime-types
|
|
36
|
-
const DRIVE_FILE_MIMETYPES = {
|
|
37
|
-
[SCRIPT_TYPES.DOCS]: 'application/vnd.google-apps.document',
|
|
38
|
-
[SCRIPT_TYPES.FORMS]: 'application/vnd.google-apps.form',
|
|
39
|
-
[SCRIPT_TYPES.SHEETS]: 'application/vnd.google-apps.spreadsheet',
|
|
40
|
-
[SCRIPT_TYPES.SLIDES]: 'application/vnd.google-apps.presentation',
|
|
41
|
-
};
|
|
42
|
-
const mimeType = DRIVE_FILE_MIMETYPES[filetype];
|
|
43
|
-
if (mimeType) {
|
|
44
|
-
spinner.start(LOG.CREATE_DRIVE_FILE_START(filetype));
|
|
45
|
-
const { data: { id: newParentId }, } = await drive.files.create({ requestBody: { mimeType, name } });
|
|
46
|
-
parentId = newParentId;
|
|
47
|
-
stopSpinner();
|
|
48
|
-
console.log(LOG.CREATE_DRIVE_FILE_FINISH(filetype, parentId));
|
|
49
|
-
}
|
|
50
|
-
// CLI Spinner
|
|
51
|
-
spinner.start(LOG.CREATE_PROJECT_START(name));
|
|
52
|
-
let projectExist;
|
|
53
|
-
try {
|
|
54
|
-
projectExist = is.string((await getProjectSettings()).scriptId);
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
process.exitCode = 0; // To reset `exitCode` that was overriden in ClaspError constructor.
|
|
58
|
-
projectExist = false;
|
|
59
|
-
}
|
|
60
|
-
if (projectExist) {
|
|
61
|
-
throw new ClaspError(ERROR.NO_NESTED_PROJECTS);
|
|
62
|
-
}
|
|
63
|
-
// Create a new Apps Script project
|
|
64
|
-
const { data, status, statusText } = await script.projects.create({
|
|
65
|
-
requestBody: { parentId, title: name },
|
|
66
|
-
});
|
|
67
|
-
stopSpinner();
|
|
68
|
-
if (status !== 200) {
|
|
69
|
-
if (parentId) {
|
|
70
|
-
console.log(statusText, ERROR.CREATE_WITH_PARENT);
|
|
71
|
-
}
|
|
72
|
-
throw new ClaspError(statusText !== null && statusText !== void 0 ? statusText : ERROR.CREATE);
|
|
73
|
-
}
|
|
74
|
-
const scriptId = (_a = data.scriptId) !== null && _a !== void 0 ? _a : '';
|
|
75
|
-
console.log(LOG.CREATE_PROJECT_FINISH(filetype, scriptId));
|
|
76
|
-
await saveProject({ scriptId, rootDir: config.projectRootDirectory, parentId: parentId ? [parentId] : undefined }, false);
|
|
77
|
-
if (!manifestExists(config.projectRootDirectory)) {
|
|
78
|
-
await writeProjectFiles(await fetchProject(scriptId), config.projectRootDirectory); // Fetches appsscript.json, o.w. `push` breaks
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
//# sourceMappingURL=create.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/commands/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AACxC,OAAO,EAAC,KAAK,EAAE,kBAAkB,EAAE,MAAM,EAAC,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAC,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAC,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAC,MAAM,aAAa,CAAC;AACxE,OAAO,EAAC,gBAAgB,EAAC,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAC,KAAK,EAAE,GAAG,EAAC,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAC,qBAAqB,EAAE,kBAAkB,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAC,MAAM,aAAa,CAAC;AACzG,OAAO,EAAC,IAAI,EAAC,MAAM,YAAY,CAAC;AAEhC,MAAM,MAAM,GAAG,IAAI,CAAC,G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AG,CAAC,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC3D,MAAM,WAAW,CACf,EAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,oBAAoB,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,EAAC,EAC7F,KAAK,CACN,CAAC;IAEF,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,oBAAoB,CAAC,EAAE;QAChD,MAAM,iBAAiB,CAAC,MAAM,YAAY,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAC,8CAA8C;KACnI;AACH,CAAC,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Command } from 'commander';
|
|
2
|
-
import type { ReadonlyDeep } from 'type-fest';
|
|
3
|
-
declare const _default: (_: unknown, command: ReadonlyDeep<Command>) => Promise<void>;
|
|
4
|
-
/**
|
|
5
|
-
* Displays a default message when an unknown command is typed.
|
|
6
|
-
* @param command {string} The command that was typed.
|
|
7
|
-
*/
|
|
8
|
-
export default _default;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ClaspError } from '../clasp-error.js';
|
|
2
|
-
import { ERROR } from '../messages.js';
|
|
3
|
-
/**
|
|
4
|
-
* Displays a default message when an unknown command is typed.
|
|
5
|
-
* @param command {string} The command that was typed.
|
|
6
|
-
*/
|
|
7
|
-
export default async (_, command) => {
|
|
8
|
-
throw new ClaspError(ERROR.COMMAND_DNE(command.args.join(' ')));
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=default.js.map
|