-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathnew.ts
74 lines (59 loc) · 1.85 KB
/
new.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
74
import { Command, flags } from "@oclif/command";
import { execSync } from "child_process";
import * as fs from "fs-extra";
import * as request from "superagent";
import * as Zip from "adm-zip";
import cli from "cli-ux";
import * as path from "path";
export default class New extends Command {
static description = "Create new dapp from template.";
static examples = [
"$ terrain new awesome-dapp",
"$ terrain new awesome-dapp --path path/to/dapp",
];
static flags = {
path: flags.string({ description: "path to keep the project" }),
version: flags.string({
default: "0.16",
}),
};
static args = [{ name: "name", required: true }];
async run() {
const { args, flags } = this.parse(New);
cli.log("generating: ");
cli.action.start("- contract");
if (flags.path) {
process.chdir(flags.path);
}
fs.mkdirSync(args.name);
process.chdir(args.name);
fs.mkdirSync("contracts");
process.chdir("contracts");
execSync(
`cargo generate --git https://github.com/CosmWasm/cw-template.git --branch ${flags.version} --name counter`
);
cli.action.stop();
process.chdir("..");
cli.action.start("- frontend");
const file = fs.createWriteStream("frontend.zip");
await new Promise((resolve, reject) => {
request
.get(
"https://github.com/iboss-ptk/terrain-frontend-template/archive/refs/heads/main.zip"
)
.on("error", (error) => {
reject(error);
})
.pipe(file)
.on("finish", () => {
cli.action.stop();
resolve(null);
});
});
const zip = new Zip("frontend.zip");
zip.extractAllTo(".", true);
fs.renameSync("terrain-frontend-template-main", "frontend");
fs.removeSync("frontend.zip");
fs.copySync(path.join(__dirname, "..", "template"), process.cwd());
}
}