google / clasp

🔗 Command Line Apps Script Projects
https://developers.google.com/apps-script/guides/clasp
Apache License 2.0
4.59k stars 428 forks source link

Feature Request - Commands to streamline management of multiple push targets. #625

Open DimuDesigns opened 5 years ago

DimuDesigns commented 5 years ago

Feature Request - Commands to streamline management of multiple push targets.

Describe the solution you'd like There have been a few similar proposals (#349 is one of them). I'd categorize this as a "nice-to-have", where we could have options to store, track and switch between multiple push targets (ie. scriptIds) via a switch/branching mechanism similar to how git branch functions. Likely requires a number of new commands. Something along the lines of:

Command Description
clasp target [TARGET-NAME] [SCRIPT-ID] Creates a new push target
clasp target switch [TARGET-NAME] Switches to named target.
clasp target list Lists targets.
clasp target delete [TARGET-NAME] Deletes named target.
clasp target Displays the name of the current target.

And .clasp.json may have the following configuration:

    {
        ...,
        "targets":[
            {
                "name":"(default)", // automatically created when project is 1st created or cloned 
                "scriptId":"xxxxxxxxxxxxxxxxxxxxxxxxxx"
            },
            {
                "name":"[TARGET-NAME]",
                "scriptId":"yyyyyyyyyyyyyyyyyyyyyyyy"
            },
            {...}
        ],
        "currentTarget":"(default)",
        ...
    }

Describe alternatives you've considered Currently, we can leverage the clasp settings command to set the scriptId key in .clasp.json. But there is no history of prior push targets. Ideally, push targets (ie. scriptIds) would be stored in clasp.json as previously proposed in #349.

PopGoesTheWza commented 5 years ago

@grant could you please advise on how the .claspignore file should be located?

Current code does not give a clear idea of the intended process:

export const DOTFILE = {
  /**
   * Reads DOT.IGNORE.PATH to get a glob pattern of ignored paths.
   * @return {Promise<string[]>} A list of file glob patterns
   */
  IGNORE: () => {
    // TODO: there seems to be a logic error in how `.claspignore` is resolved
    const projectPath = findUp.sync(DOT.PROJECT.PATH);
    const ignoreDirectory = path.join(projectPath ? path.dirname(projectPath) : DOT.PROJECT.DIR);
    return new Promise<string[]>((resolve, reject) => {
      if (
        fs.existsSync(ignoreDirectory) // TODO: is ignoreDirectory really needed?
        && fs.existsSync(DOT.IGNORE.PATH)
      ) {
        const buffer = stripBom(fs.readFileSync(DOT.IGNORE.PATH, { encoding: 'utf8' }));
        resolve(splitLines(buffer).filter((name: string) => name));
      } else {
        resolve(['**/**', '!appsscript.json', '!*.js', '!*.ts']);
      }
    });
  },

Unless I am missing something, it can be summarized as "look for .claspignore in CWD. If not present, use built-in default"

grant commented 5 years ago

Should be next to the .clasp.json