@google/dscc-gen
Version:
Create component & connector projects with sane defaults.
97 lines • 3.55 kB
JavaScript
;
/**
* @license
* Copyright 2018 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDeploymentIdByName = exports.authenticate = exports.isAuthenticated = exports.deploy = exports.getScriptId = exports.version = exports.push = exports.clone = exports.create = void 0;
const execa = require("execa");
const path = require("path");
const files = require("../files");
exports.create = async (appsscriptPath, projectName) => {
const options = {
cwd: appsscriptPath,
};
await execa('npx', [
'@google/clasp',
'create',
'--title',
projectName,
'--type',
'standalone',
'--rootDir',
'src',
], options);
};
exports.clone = async (appscriptPath, scriptId, rootDir) => {
const options = {
cwd: appscriptPath,
};
let args = ['@google/clasp', 'clone'];
args = rootDir !== undefined ? args.concat('--rootDir', rootDir) : args;
args = args.concat(scriptId);
await execa('npx', args, options);
};
exports.push = async (appsscriptPath) => {
const options = {
cwd: appsscriptPath,
};
await execa('npx', ['@google/clasp', 'push', '--force'], options);
};
exports.version = async (appsscriptPath, description = 'Initial code') => {
const options = { cwd: appsscriptPath };
await execa(`npx`, ['@google/clasp', 'version', description], options);
};
exports.getScriptId = async (appsscriptPath) => {
const claspJsonPath = path.join(appsscriptPath, '.clasp.json');
const claspJson = await files.parseJsonFile(claspJsonPath);
return claspJson.scriptId;
};
exports.deploy = async (appsscriptPath, deploymentName) => {
const options = { cwd: appsscriptPath };
const { stdout: out } = await execa('npx', ['@google/clasp', 'deploy', '--description', `${deploymentName}`], options);
const [, deploymentId] = out.match(/- ([-_A-Za-z\d]*) @[0-9]+\./);
return deploymentId;
};
// TODO(mjhamrick) - add implementation.
exports.isAuthenticated = async () => {
return true;
};
// TODO(mjhamrick) - add implementation.
exports.authenticate = async () => {
return true;
};
exports.getDeploymentIdByName = async (appsscriptPath, name) => {
const options = { cwd: appsscriptPath };
const { stdout: out } = await execa(`npx`, ['@google/clasp', 'deployments'], options);
const deploymentStrings = out
.split('\n')
.filter((s) => s.startsWith('-'))
.filter((s) => s.includes(name))
.map((s) => s.match(/- (.*) @.*/));
if (deploymentStrings.length === 0) {
return undefined;
}
if (deploymentStrings.length > 1) {
throw new Error(`There was more than one deployment with the name: "${name}"`);
}
const deploymentString = deploymentStrings[0];
if (deploymentString === null) {
return undefined;
}
const deploymentId = deploymentString[1];
return deploymentId;
};
//# sourceMappingURL=appsscript.js.map