@google/dscc-gen
Version:
Create component & connector projects with sane defaults.
78 lines • 2.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.assertNever = exports.format = exports.spinnify = exports.pause = exports.npmInstall = exports.fileExists = exports.writeFile = exports.readFile = exports.readDir = void 0;
const chalk_1 = require("chalk");
const cli_spinner_1 = require("cli-spinner");
const execa = require("execa");
const fs = require("fs");
exports.readDir = (path) => {
const data = fs.readdirSync(path);
return data;
};
exports.readFile = (filePath, encoding) => {
return fs.readFileSync(filePath, encoding);
};
exports.writeFile = (filePath, data, encoding) => {
fs.writeFileSync(filePath, data, encoding);
return true;
};
exports.fileExists = (filePath) => {
return new Promise((resolve, _) => {
// The callback version (fs.exists) is deprecated so using synchronous
// version (that isn't).
const exists = fs.existsSync(filePath);
resolve(exists);
});
};
exports.npmInstall = async (projectPath, answers) => {
const execOptions = { cwd: projectPath };
if (answers.yarn) {
return execa('yarn', [], execOptions);
}
else {
return execa('npm', ['install'], execOptions);
}
};
exports.pause = async (millis) => {
return new Promise((resolve, _) => {
setInterval(() => {
resolve();
}, millis);
});
};
exports.spinnify = async (spinnerText, fn) => {
const spinner = new cli_spinner_1.Spinner(spinnerText);
spinner.start();
try {
return await fn();
}
finally {
spinner.stop(true);
}
};
exports.format = {
green: chalk_1.default.bold.rgb(15, 157, 88),
blue: chalk_1.default.bold.rgb(66, 133, 244),
yellow: chalk_1.default.bold.rgb(244, 160, 0),
red: chalk_1.default.bold.rgb(219, 68, 55),
};
exports.assertNever = (x) => {
throw new Error('Unexpected object: ' + x);
};
//# sourceMappingURL=util.js.map