-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateTemplate.ts
55 lines (46 loc) · 1.49 KB
/
generateTemplate.ts
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
import path from 'path';
import * as fs from 'fs';
import install, { PackageManager } from './install';
import { _technologyChoices } from './constants';
import spawn from 'cross-spawn';
interface GenerateHTMXTemplateParams {
projectName: string;
pkgManager: PackageManager;
technology: 'javascript' | 'typescript' | 'go';
}
export const generateJavascriptHTMXTemplate = async ({
projectName,
technology,
pkgManager,
}: GenerateHTMXTemplateParams) => {
const currentDir = process.cwd();
const projectDir = path.join(currentDir, projectName);
const templateDir = path.resolve(__dirname, `templates/${technology}`);
console.log('Creating the directory...');
try {
fs.mkdirSync(projectDir);
} catch (err) {
console.log(err);
process.exit(1);
}
console.log(
'\n\n\nInitializing empty git repository in the project directory'
);
spawn.sync('git', ['init'], { cwd: projectDir, stdio: 'inherit' });
fs.cpSync(templateDir, projectDir, { recursive: true });
fs.renameSync(
path.join(projectDir, 'gitignore'),
path.join(projectDir, '.gitignore')
);
const projectPackageJson = require(path.join(projectDir, 'package.json'));
projectPackageJson.name = projectName;
fs.writeFileSync(
path.join(projectDir, 'package.json'),
JSON.stringify(projectPackageJson, null, 2)
);
console.log('\n\n\nInstalling dependencies...');
install(pkgManager, projectDir);
console.log('\n\n\n');
console.log('HTMX project installed :)');
process.exit(0);
};