1 | const path = require("node:path");
|
2 | const fs = require("node:fs");
|
3 | const https = require("node:https");
|
4 |
|
5 | const dirName = "wakuwork-example";
|
6 |
|
7 | if (fs.existsSync(dirName)) {
|
8 | console.error(`Directory "${dirName}" already exists!`);
|
9 | process.exit(1);
|
10 | }
|
11 |
|
12 | const baseUrl =
|
13 | "https://raw.githubusercontent.com/dai-shi/wakuwork/v0.7.1/examples/01_counter/";
|
14 |
|
15 | const files = `
|
16 | entries.ts
|
17 | index.html
|
18 | package.json
|
19 | src/index.tsx
|
20 | src/App.tsx
|
21 | src/Counter.tsx
|
22 | `
|
23 | .split(/\s/)
|
24 | .filter((file) => file);
|
25 |
|
26 | const getFiles = (index = 0) => {
|
27 | const file = files[index];
|
28 | if (!file) return;
|
29 | const destFile = path.join(dirName, file.replace("/", path.sep));
|
30 | fs.mkdirSync(path.dirname(destFile), { recursive: true });
|
31 | https.get(baseUrl + file, (res) => {
|
32 | res.pipe(fs.createWriteStream(destFile));
|
33 | res.on("end", () => getFiles(index + 1));
|
34 | });
|
35 | };
|
36 |
|
37 | getFiles();
|
38 |
|
39 | process.on("exit", (code) => {
|
40 | if (!code) {
|
41 | console.info(`Done! Change directory "${dirName}"`);
|
42 | }
|
43 | });
|