UNPKG

@google/clasp

Version:

Develop Apps Script Projects locally

53 lines (52 loc) 2.41 kB
// Copyright 2025 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // This file defines the 'list-scripts' (alias 'list') command for the clasp // CLI. import { Command } from 'commander'; import { intl } from '../intl.js'; import { ellipsize, withSpinner } from './utils.js'; export const command = new Command('list-scripts') .alias('list') .description('List App Scripts projects') .option('--noShorten', 'Do not shorten long names', false) .action(async function () { const options = this.optsWithGlobals(); const clasp = options.clasp; const spinnerMsg = intl.formatMessage({ id: "x0awdZ", defaultMessage: [{ type: 0, value: "Finding your scripts..." }] }); const files = await withSpinner(spinnerMsg, async () => { return clasp.project.listScripts(); }); if (options.json) { const scripts = files.results.map(file => ({ id: file.id, name: file.name, })); console.log(JSON.stringify(scripts, null, 2)); return; } if (!files.results.length) { const msg = intl.formatMessage({ id: "rPMgOk", defaultMessage: [{ type: 0, value: "No script files found." }] }); console.log(msg); return; } const successMessage = intl.formatMessage({ id: "TBJtFJ", defaultMessage: [{ type: 0, value: "Found " }, { type: 6, value: "count", options: { one: { value: [{ type: 7 }, { type: 0, value: " script" }] }, other: { value: [{ type: 7 }, { type: 0, value: " scripts" }] } }, offset: 0, pluralType: "cardinal" }, { type: 0, value: "." }] }, { count: files.results.length, }); console.log(successMessage); files.results.forEach(file => { const name = options.noShorten ? file.name : ellipsize(file.name, 20); const url = `https://script.google.com/d/${file.id}/edit`; console.log(`${name} - ${url}`); }); });