-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·88 lines (71 loc) · 2.6 KB
/
index.js
File metadata and controls
executable file
·88 lines (71 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env node
import { execSync } from 'child_process';
import fs from 'fs';
import path from 'path';
import dotenv from 'dotenv';
import { fileURLToPath } from 'url';
import { parseFlags } from './handlers/parse-flags.js';
import { applyScripts, installDeps } from './handlers/apply-config.js';
import { copyNewFiles } from './handlers/copy-new-files.js';
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 || !fs.existsSync(localDevDir))
return `git clone --depth 1 ${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, flags } = parseFlags(process.argv);
let lang = 'javascript';
for (const flag of flags) {
if ('ts' === flag.name && true === flag.value) lang = 'typescript';
}
(async () => {
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'));
console.log('Applying language config...');
const configPath = path.join(folderPath, `.config/${lang}`);
const configFiles = path.join(configPath, 'files/');
const configScripts = path.join(configPath, 'config.js');
console.log('Copying language files...');
copyNewFiles(configFiles, folderPath);
console.log('Applying NPM scripts...');
const { npmScripts, deps } = await import(configScripts);
applyScripts(dir, npmScripts);
console.log('Installing dependencies...');
installDeps(dir, deps);
fs.rmSync(path.join(folderPath, '.config'), {
recursive: true,
force: true,
});
execSync(COMMANDS.gitInit(folderPath));
console.log('✅ Success!');
} catch (err) {
console.error(`❌ Something went wrong: ${err}`);
}
})();