-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.ts
73 lines (65 loc) · 1.86 KB
/
index.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { Command } from 'commander';
import packageJson from './package.json';
import chalk from 'chalk';
import { mkdir, unlink } from 'fs/promises';
import tar from 'tar';
import { join } from 'path';
import { tmpdir } from 'os';
import { pipeline } from 'stream/promises';
import got from 'got';
import { createWriteStream } from 'fs';
import prompts from 'prompts';
async function downloadTar(url: string) {
const tempFile = join(tmpdir(), `create-web3-frontend.temp-${Date.now()}`);
await pipeline(got.stream(url), createWriteStream(tempFile));
return tempFile;
}
async function getUserInput() {
const response = await prompts({
type: 'text',
name: 'input',
message: 'Project name:',
});
return response.input;
}
const main = async () => {
let projectPath = '';
const program = new Command(packageJson.name)
.version(packageJson.version)
.arguments('<project-directory>')
.usage(`${chalk.green('<project-directory>')} [options]`)
.action((name) => {
projectPath = name;
})
.parse(process.argv);
if (!projectPath) {
projectPath = await getUserInput();
}
await mkdir(projectPath);
const tempFile = await downloadTar(
`https://codeload.github.com/Dhaiwat10/cw3f-new-template/tar.gz/main`
);
await tar.x({
file: tempFile,
strip: 1,
cwd: join(process.cwd(), projectPath),
});
await unlink(tempFile);
console.log();
console.log();
console.log(
chalk.green('⚡️ Success! Created a web3 frontend at ' + projectPath)
);
console.log();
console.log();
console.log('To get started:');
console.log();
console.log(`- cd into the project directory: cd ${projectPath}`);
console.log('- Install dependencies by running `pnpm install`');
console.log('- Run the dev server by running `pnpm dev`');
console.log();
console.log();
};
main().catch((err) => {
console.error(err);
});