@ehduardu/bat-framework
Version:
A simple framework for Google Apps Script
165 lines (164 loc) • 8.21 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createProject = void 0;
const chalk_1 = __importDefault(require("chalk"));
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const cpy_1 = __importDefault(require("cpy"));
const os_1 = __importDefault(require("os"));
const git_1 = require("../tools/git");
const install_1 = require("../tools/install");
const logger_1 = __importDefault(require("../tools/logger"));
function createProject({ appPath, appName }) {
return __awaiter(this, void 0, void 0, function* () {
const root = path_1.default.resolve(appPath);
if (!appName) {
logger_1.default.error(chalk_1.default.blueBright("argument projectName not specified!"));
process.exit(1);
}
function canWrite(path) {
return __awaiter(this, void 0, void 0, function* () {
try {
yield fs_1.default.promises.access(path, (fs_1.default.constants || fs_1.default).W_OK);
return true;
}
catch (_a) {
return false;
}
});
}
if (!(yield canWrite(path_1.default.dirname(root)))) {
console.error('The application path is not writable, please check folder permissions and try again.');
console.error('It is likely you do not have write permissions for this folder.');
process.exit(1);
}
yield fs_1.default.promises.mkdir(root, { recursive: true });
const originalDirectory = process.cwd();
console.log(`Creating a new apps script project in ${chalk_1.default.green(root)}`);
process.chdir(root);
const packageJSON = {
"name": appName,
"version": '1.0.0',
"description": "Starter project for using React with Google Apps Script to build Web Apps",
"scripts": {
"test": "test",
"login": "clasp login",
"setup:use-id": "clasp setting scriptId",
"build": "webpack --mode production",
"deploy": "npm run build && npx clasp push"
},
"keywords": [
"react",
"google",
"apps",
"script",
"sheets"
],
"author": "Carlos Eduardo",
"license": "MIT",
"engines": {
"node": ">=10.0.0",
"npm": ">=6.0.0"
},
"dependencies": {
"prop-types": "^15.7.2",
"react": "^16.13.0",
"react-bootstrap": "^1.0.1",
"react-dom": "^16.13.0",
"react-router-dom": "^5.2.0",
"react-transition-group": "^4.4.1",
"styled-components": "^5.1.1"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.7",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-object-rest-spread": "^7.8.3",
"@babel/plugin-transform-object-assign": "^7.8.3",
"@babel/polyfill": "^7.8.7",
"@babel/preset-env": "^7.8.7",
"@babel/preset-react": "^7.8.3",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.0.6",
"babel-plugin-add-module-exports": "^1.0.2",
"babel-plugin-transform-es3-member-expression-literals": "^6.22.0",
"babel-plugin-transform-es3-property-literals": "^6.22.0",
"copy-webpack-plugin": "^5.1.1",
"css-loader": "^3.4.2",
"dynamic-cdn-webpack-plugin": "^5.0.0",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-prettier": "^6.10.0",
"eslint-config-standard": "^14.1.0",
"eslint-loader": "^3.0.3",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-googleappsscript": "^1.0.3",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-standard": "^4.0.1",
"gas-lib": "^2.0.3",
"gas-types-detailed": "^1.0.0",
"gas-webpack-plugin": "^1.0.2",
"html-webpack-inline-source-plugin": "0.0.10",
"html-webpack-plugin": "^3.2.0",
"module-to-cdn": "^3.1.5",
"prettier": "^1.19.1",
"style-loader": "^1.1.3",
"tern": "^0.24.3",
"terser-webpack-plugin": "^2.3.5",
"webpack": "^4.42.0",
"webpack-clean": "^1.2.3",
"webpack-cli": "^3.3.11"
}
};
console.log(`Copying ${chalk_1.default.cyan('template')} and ${chalk_1.default.cyan('base files')}`);
const rootDirName = path_1.default.resolve(__dirname, '..', '..');
yield (0, cpy_1.default)(['.*', '.**', '**', '*.**'], root, {
parents: true,
dot: true,
cwd: path_1.default.join(rootDirName, 'templates', 'project'),
});
fs_1.default.writeFileSync(path_1.default.join(root, 'package.json'), JSON.stringify(packageJSON, null, 2) + os_1.default.EOL);
console.log('Installing development dependencies...');
yield (0, install_1.install)(root, [
"@google/clasp@2.3.0",
], true);
const gitInitialized = (0, git_1.gitInit)(root);
if (gitInitialized) {
console.log('Git repository initialized\n');
}
console.log(`${chalk_1.default.green('Success!')} Created ${appName} at ${chalk_1.default.cyan(appPath)}\n`);
console.log(`${chalk_1.default.yellow('Attention!')} Before start, make sure to change the scriptId in the ${chalk_1.default.cyan('.clasp.json')}`);
console.log('Inside that directory, you can run several commands:\n');
console.log(chalk_1.default.cyan(' yarn login'));
console.log(' To do login in google clasp.\n');
console.log(chalk_1.default.cyan(' yarn build'));
console.log(' Builds the app to dist folder.\n');
console.log(chalk_1.default.cyan(' yarn deploy'));
console.log(' Builds the app and push to gas server.\n');
console.log('We suggest that you begin by typing:\n');
console.log(` ${chalk_1.default.cyan('yarn login\n')}`);
if (!gitInitialized) {
console.log(`${chalk_1.default.yellow('Attention!')} ${chalk_1.default.redBright('git repository it not initialized!')}`);
console.log('Inside that directory, you need to run this commands:\n');
console.log(chalk_1.default.cyan(' git init'));
}
});
}
exports.createProject = createProject;