/
list.ts
45 lines (38 loc) 路 1.21 KB
/
list.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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';
interface CommandOption {
readonly noShorten: boolean;
}
/**
* Lists a user's Apps Script projects using Google Drive.
* @param options.noShorten {boolean}
*/
export default async (options: CommandOption): Promise<void> => {
await checkIfOnlineOrDie();
await loadAPICredentials();
spinner.start(LOG.FINDING_SCRIPTS);
const {
data: {files = []},
status,
} = await drive.files.list({
pageSize: 50,
// Fields isn't currently supported
// https://github.com/googleapis/google-api-nodejs-client/issues/1374
// fields: 'nextPageToken, files(id, name)',
q: 'mimeType="application/vnd.google-apps.script"',
});
if (status !== 200) {
throw new ClaspError(ERROR.DRIVE);
}
stopSpinner();
if (files.length > 0) {
for (const file of files) {
console.log(`${!options.noShorten ? ellipsize(file.name!, 20) : file.name} - ${URL.SCRIPT(file.id ?? '')}`);
}
} else {
console.log(LOG.FINDING_SCRIPTS_DNE);
}
};