apps-script-engine
Version:
Creates boilerplate code for kick-ass Apps Script projects
57 lines (46 loc) • 1.61 kB
JavaScript
import { execSync } from 'child_process';
import fs from 'fs';
import path from 'path';
import dotenv from 'dotenv';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
dotenv.config({ path: path.join(__dirname, '.env') });
const REPO = 'https://github.com/WildH0g/apps-script-engine-template.git';
const COMMANDS = {
gitClone(dir = '') {
console.log(`⏳ Initiating Apps Script Engine in directory "${dir}"`);
const localDevDir = process.env.DEV_MODE_DIR;
if (!localDevDir) return `git clone ${REPO} "${dir}"`;
console.log(`Copying from local DEV directory: ${localDevDir}`);
return `cp -r "${localDevDir}/." "${dir}"`;
},
gitInit(dir = '.') {
console.log(`⏳ Initiating git repository in ${dir}`);
const commands = [
`cd "${dir}"`,
'git init',
'npm i',
'npm run install:husky',
'git add .',
'git commit -m "Install Apps Script Engine template"',
];
return commands.join(' && ');
},
};
const dir = process.argv[2] || 'apps-script-project';
try {
execSync(COMMANDS.gitClone(dir));
const folderPath = path.join(process.cwd(), dir);
fs.rmSync(path.join(folderPath, '.git'), { recursive: true, force: true });
fs.renameSync(
path.join(folderPath, 'README.md'),
path.join(folderPath, 'INSTRUCTIONS.md')
);
fs.truncateSync(path.join(folderPath, 'HISTORY.md'));
execSync(COMMANDS.gitInit(folderPath));
console.log('✅ Success!');
} catch (err) {
console.error(`❌ Something went wrong: ${err}`);
}