create-amytis 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +53 -9
- package/package.json +3 -7
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import * as fs from "fs";
|
|
|
7
7
|
import * as path from "path";
|
|
8
8
|
import * as https from "https";
|
|
9
9
|
import * as readline from "readline";
|
|
10
|
-
import { execSync } from "child_process";
|
|
10
|
+
import { execFileSync, execSync } from "child_process";
|
|
11
11
|
function prompt(question, defaultVal = "") {
|
|
12
12
|
const rl = readline.createInterface({
|
|
13
13
|
input: process.stdin,
|
|
@@ -68,10 +68,52 @@ function downloadFile(url, dest) {
|
|
|
68
68
|
doGet(url);
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
-
function
|
|
71
|
+
function getArchiveMetadata(tag, platform = process.platform) {
|
|
72
|
+
if (platform === "win32") {
|
|
73
|
+
return {
|
|
74
|
+
url: `https://github.com/hutusi/amytis/archive/refs/tags/${tag}.zip`,
|
|
75
|
+
filename: `amytis-${tag}.zip`,
|
|
76
|
+
kind: "zip"
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
url: `https://github.com/hutusi/amytis/archive/refs/tags/${tag}.tar.gz`,
|
|
81
|
+
filename: `amytis-${tag}.tar.gz`,
|
|
82
|
+
kind: "tar.gz"
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function buildExtractCommand(archivePath, tmpDir, kind, platform = process.platform) {
|
|
86
|
+
if (kind === "zip") {
|
|
87
|
+
if (platform !== "win32") {
|
|
88
|
+
throw new Error("ZIP extraction is only supported on Windows in create-amytis");
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
command: "powershell.exe",
|
|
92
|
+
args: [
|
|
93
|
+
"-NoProfile",
|
|
94
|
+
"-NonInteractive",
|
|
95
|
+
"-ExecutionPolicy",
|
|
96
|
+
"Bypass",
|
|
97
|
+
"-Command",
|
|
98
|
+
"Expand-Archive",
|
|
99
|
+
"-LiteralPath",
|
|
100
|
+
archivePath,
|
|
101
|
+
"-DestinationPath",
|
|
102
|
+
tmpDir,
|
|
103
|
+
"-Force"
|
|
104
|
+
]
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
command: "tar",
|
|
109
|
+
args: ["xzf", archivePath, "-C", tmpDir]
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function extractArchive(archivePath, outDir, kind, platform = process.platform) {
|
|
72
113
|
const tmpDir = `${outDir}.__tmp__`;
|
|
73
114
|
fs.mkdirSync(tmpDir, { recursive: true });
|
|
74
|
-
|
|
115
|
+
const { command, args } = buildExtractCommand(archivePath, tmpDir, kind, platform);
|
|
116
|
+
execFileSync(command, args, { stdio: "inherit" });
|
|
75
117
|
const entries = fs.readdirSync(tmpDir);
|
|
76
118
|
if (entries.length !== 1) {
|
|
77
119
|
throw new Error(`Unexpected tarball structure: ${entries.join(", ")}`);
|
|
@@ -79,7 +121,7 @@ function extractTarball(tarPath, outDir) {
|
|
|
79
121
|
const innerDir = path.join(tmpDir, entries[0]);
|
|
80
122
|
fs.renameSync(innerDir, outDir);
|
|
81
123
|
fs.rmdirSync(tmpDir);
|
|
82
|
-
fs.unlinkSync(
|
|
124
|
+
fs.unlinkSync(archivePath);
|
|
83
125
|
}
|
|
84
126
|
function escapeTemplateLiteral(str) {
|
|
85
127
|
return str.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
@@ -132,12 +174,12 @@ Fetching latest Amytis release...`);
|
|
|
132
174
|
if (!tag)
|
|
133
175
|
throw new Error("Could not determine latest release tag");
|
|
134
176
|
console.log(` Found: ${tag}`);
|
|
135
|
-
const
|
|
136
|
-
const
|
|
177
|
+
const archive = getArchiveMetadata(tag);
|
|
178
|
+
const archiveDest = path.join(process.cwd(), archive.filename);
|
|
137
179
|
console.log("Downloading tarball...");
|
|
138
|
-
await downloadFile(
|
|
180
|
+
await downloadFile(archive.url, archiveDest);
|
|
139
181
|
console.log("Extracting...");
|
|
140
|
-
|
|
182
|
+
extractArchive(archiveDest, targetDir, archive.kind);
|
|
141
183
|
console.log(` Scaffolded: ${targetDir}`);
|
|
142
184
|
const siteTitle = await prompt(`
|
|
143
185
|
Site title`, projectName);
|
|
@@ -169,5 +211,7 @@ Error:`, err.message);
|
|
|
169
211
|
}
|
|
170
212
|
export {
|
|
171
213
|
patchSiteConfig,
|
|
172
|
-
patchPackageJson
|
|
214
|
+
patchPackageJson,
|
|
215
|
+
getArchiveMetadata,
|
|
216
|
+
buildExtractCommand
|
|
173
217
|
};
|
package/package.json
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-amytis",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Create a new Amytis digital garden",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"bin": {
|
|
7
|
-
"create-amytis": "dist/index.js"
|
|
8
|
-
},
|
|
6
|
+
"bin": { "create-amytis": "./dist/index.js" },
|
|
9
7
|
"scripts": {
|
|
10
8
|
"build": "bun build src/index.ts --outfile dist/index.js --target node --sourcemap=none",
|
|
11
9
|
"dev": "bun src/index.ts",
|
|
12
10
|
"test": "bun test src"
|
|
13
11
|
},
|
|
14
|
-
"files": [
|
|
15
|
-
"dist"
|
|
16
|
-
]
|
|
12
|
+
"files": ["dist"]
|
|
17
13
|
}
|