@promte/app-upload 0.1.2 → 0.1.5
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/README.md +3 -2
- package/bin/promte-app-upload.js +62 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,11 +11,12 @@ npx promte-app-upload push
|
|
|
11
11
|
## Commands
|
|
12
12
|
```
|
|
13
13
|
promte-app-upload config
|
|
14
|
-
- interactive setup for host/workspaceId/dist (stored in
|
|
14
|
+
- interactive setup for host/workspaceId/dist (stored in ./promte-app-upload.config.json)
|
|
15
15
|
|
|
16
|
-
promte-app-upload push [--host ...] [--workspaceId ...] [--dist ...] [--serviceKey ...]
|
|
16
|
+
promte-app-upload push [--host ...] [--workspaceId ...] [--dist ...] [--zip ...] [--serviceKey ...]
|
|
17
17
|
- uploads ./dist by default
|
|
18
18
|
- host defaults to https://app.promte.dk
|
|
19
|
+
- use --zip <file> to upload an existing zip
|
|
19
20
|
```
|
|
20
21
|
|
|
21
22
|
Notes:
|
package/bin/promte-app-upload.js
CHANGED
|
@@ -10,14 +10,14 @@ const { FormData, File } = undici;
|
|
|
10
10
|
|
|
11
11
|
const DEFAULT_HOST = "https://app.promte.dk";
|
|
12
12
|
const DEFAULT_DIST = "./dist";
|
|
13
|
-
const CONFIG_PATH = path.
|
|
13
|
+
const CONFIG_PATH = path.resolve(process.cwd(), "promte-app-upload.config.json");
|
|
14
14
|
|
|
15
15
|
function usage() {
|
|
16
16
|
console.log(
|
|
17
17
|
[
|
|
18
18
|
"Usage:",
|
|
19
19
|
" promte-app-upload config",
|
|
20
|
-
" promte-app-upload push [--host <url>] [--workspaceId <id>] [--dist <path>] [--serviceKey <key>]",
|
|
20
|
+
" promte-app-upload push [--host <url>] [--workspaceId <id>] [--dist <path>] [--zip <file>] [--serviceKey <key>]",
|
|
21
21
|
"",
|
|
22
22
|
"Defaults:",
|
|
23
23
|
` host: ${DEFAULT_HOST}`,
|
|
@@ -121,32 +121,86 @@ function ensureDist(distPath) {
|
|
|
121
121
|
const indexPath = path.join(abs, "index.html");
|
|
122
122
|
assert(
|
|
123
123
|
fs.existsSync(indexPath),
|
|
124
|
-
`index.html not found in dist folder: ${indexPath}
|
|
124
|
+
`index.html not found in dist folder: ${indexPath}. Make sure you're pointing at the built output.`,
|
|
125
125
|
);
|
|
126
126
|
return abs;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
+
function normalizeZipPath(p) {
|
|
130
|
+
return p.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function detectSingleRoot(entryNames) {
|
|
134
|
+
const roots = new Set(
|
|
135
|
+
entryNames
|
|
136
|
+
.map(normalizeZipPath)
|
|
137
|
+
.filter(Boolean)
|
|
138
|
+
.map((p) => p.split("/")[0]),
|
|
139
|
+
);
|
|
140
|
+
return roots.size === 1 ? [...roots][0] : null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function ensureZipHasIndex(zipPath) {
|
|
144
|
+
const abs = path.resolve(process.cwd(), zipPath);
|
|
145
|
+
assert(fs.existsSync(abs), `Zip file not found: ${abs}`);
|
|
146
|
+
assert(fs.statSync(abs).isFile(), `Zip path is not a file: ${abs}`);
|
|
147
|
+
assert(/\.zip$/i.test(abs), `File must be a .zip: ${abs}`);
|
|
148
|
+
|
|
149
|
+
const zip = new AdmZip(abs);
|
|
150
|
+
const entries = zip.getEntries().filter((e) => !e.isDirectory);
|
|
151
|
+
assert(entries.length > 0, "Zip contains no files.");
|
|
152
|
+
|
|
153
|
+
const entryNames = entries.map((e) => e.entryName);
|
|
154
|
+
const singleRoot = detectSingleRoot(entryNames);
|
|
155
|
+
|
|
156
|
+
const normalized = entryNames
|
|
157
|
+
.map(normalizeZipPath)
|
|
158
|
+
.map((name) => {
|
|
159
|
+
if (singleRoot && name.startsWith(singleRoot + "/")) {
|
|
160
|
+
return name.slice(singleRoot.length + 1);
|
|
161
|
+
}
|
|
162
|
+
return name;
|
|
163
|
+
})
|
|
164
|
+
.filter(Boolean);
|
|
165
|
+
|
|
166
|
+
assert(
|
|
167
|
+
normalized.includes("index.html"),
|
|
168
|
+
"Zip is missing index.html at the root (after unzipping).",
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
return { abs, name: path.basename(abs) };
|
|
172
|
+
}
|
|
173
|
+
|
|
129
174
|
async function runPush(args) {
|
|
130
175
|
const config = loadConfig();
|
|
131
176
|
const host = args.host || config.host || DEFAULT_HOST;
|
|
132
177
|
const workspaceId = args.workspaceId || config.workspaceId;
|
|
133
178
|
const dist = args.dist || config.dist || DEFAULT_DIST;
|
|
179
|
+
const zipPath = args.zip;
|
|
134
180
|
let serviceKey = args.serviceKey;
|
|
135
181
|
|
|
136
182
|
assert(workspaceId, "workspaceId is required (config or --workspaceId)");
|
|
137
|
-
const absDist = ensureDist(dist);
|
|
183
|
+
const absDist = zipPath ? null : ensureDist(dist);
|
|
138
184
|
|
|
139
185
|
if (!serviceKey) {
|
|
140
186
|
serviceKey = await promptSecret("Service key");
|
|
141
187
|
}
|
|
142
188
|
assert(serviceKey, "serviceKey is required");
|
|
143
189
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
190
|
+
let zipBuffer;
|
|
191
|
+
let zipName = "dist.zip";
|
|
192
|
+
if (zipPath) {
|
|
193
|
+
const { abs, name } = ensureZipHasIndex(zipPath);
|
|
194
|
+
zipBuffer = fs.readFileSync(abs);
|
|
195
|
+
zipName = name;
|
|
196
|
+
} else {
|
|
197
|
+
const zip = new AdmZip();
|
|
198
|
+
zip.addLocalFolder(absDist, "");
|
|
199
|
+
zipBuffer = zip.toBuffer();
|
|
200
|
+
}
|
|
147
201
|
|
|
148
202
|
const form = new FormData();
|
|
149
|
-
const file = new File([zipBuffer],
|
|
203
|
+
const file = new File([zipBuffer], zipName, {
|
|
150
204
|
type: "application/zip",
|
|
151
205
|
});
|
|
152
206
|
form.append("app", file);
|