@overlayed/cli 0.0.2 → 0.0.3

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/package.json CHANGED
@@ -9,23 +9,27 @@
9
9
  "keywords": [
10
10
  "typescript"
11
11
  ],
12
- "version": "0.0.2",
12
+ "version": "0.0.3",
13
13
  "description": "Overlayed CLI",
14
14
  "packageManager": "pnpm@10.6.3",
15
15
  "type": "module",
16
16
  "bin": {
17
17
  "ogg": "./dist/cli.js"
18
18
  },
19
+ "files": [
20
+ "dist/**/*"
21
+ ],
19
22
  "devDependencies": {
20
23
  "@ark/attest": "^0.45.0",
21
- "@types/fs-extra": "^11.0.4",
22
24
  "@overlayed/utils": "workspace:*",
23
25
  "@overlayed/utils-node": "workspace:*",
26
+ "@types/fs-extra": "^11.0.4",
24
27
  "tsdown": "^0.12.9",
25
28
  "typescript": "^5.8.2",
26
29
  "vitest": "^3.0.9"
27
30
  },
28
31
  "dependencies": {
32
+ "arktype": "^2.1.20",
29
33
  "chalk": "^5.4.1",
30
34
  "clipanion": "4.0.0-rc.4",
31
35
  "fs-extra": "^11.3.0",
@@ -1 +0,0 @@
1
- {}
@@ -1,2 +0,0 @@
1
- const { fs } = require("memfs");
2
- module.exports = fs.promises;
package/__mocks__/fs.cjs DELETED
@@ -1,2 +0,0 @@
1
- const { fs } = require("memfs");
2
- module.exports = fs;
@@ -1,457 +0,0 @@
1
- import { describe, beforeEach, afterEach, it, expect, vi, type MockedFunction } from "vitest";
2
- import { vol } from "memfs";
3
- import { Bundler } from "../src/bundle/internal/bundler";
4
- import { AppBundler } from "../src/bundle/internal/appBundler";
5
- import { glob } from "glob";
6
- import path from "node:path";
7
-
8
- vi.mock("node:fs");
9
- vi.mock("glob");
10
-
11
- const mockGlob = glob as MockedFunction<typeof glob>;
12
-
13
- describe("Bundler", () => {
14
- let bundler: Bundler;
15
-
16
- beforeEach(() => {
17
- vol.reset();
18
- bundler = new Bundler();
19
- vi.clearAllMocks();
20
- });
21
-
22
- afterEach(() => {
23
- vi.clearAllMocks();
24
- });
25
-
26
- describe("addGlobPattern", () => {
27
- it("should add a single string pattern", () => {
28
- bundler.addGlobPattern("*.js");
29
- // Test passes if no error is thrown
30
- expect(bundler).toBeDefined();
31
- });
32
-
33
- it("should add an array of patterns", () => {
34
- bundler.addGlobPattern(["*.js", "*.ts"]);
35
- // Test passes if no error is thrown
36
- expect(bundler).toBeDefined();
37
- });
38
-
39
- it("should add pattern with options", () => {
40
- bundler.addGlobPattern("*.js", { ignore: ["node_modules/**"] });
41
- // Test passes if no error is thrown
42
- expect(bundler).toBeDefined();
43
- });
44
-
45
- it("should add multiple patterns", () => {
46
- bundler.addGlobPattern("*.js");
47
- bundler.addGlobPattern(["*.ts", "*.json"]);
48
- bundler.addGlobPattern("*.md", { ignore: ["README.md"] });
49
- // Test passes if no error is thrown
50
- expect(bundler).toBeDefined();
51
- });
52
- });
53
-
54
- describe("bundle", () => {
55
- beforeEach(() => {
56
- // Set up a mock file system with current working directory paths
57
- const testCwd = process.cwd();
58
- vol.fromJSON({
59
- [path.join(testCwd, "file1.js")]: "console.log('file1');",
60
- [path.join(testCwd, "file2.js")]: "console.log('file2');",
61
- [path.join(testCwd, "src", "index.ts")]: "export const hello = 'world';",
62
- [path.join(testCwd, "src", "utils.ts")]: "export const utils = true;",
63
- [path.join(testCwd, "package.json")]: '{"name": "test-project"}',
64
- [path.join(testCwd, "README.md")]: "# Test Project",
65
- [path.join(testCwd, "node_modules", "dep", "index.js")]: "module.exports = {};",
66
- });
67
- });
68
-
69
- it("should bundle files matching a single pattern", async () => {
70
- const testCwd = process.cwd();
71
- mockGlob.mockResolvedValueOnce([path.join(testCwd, "file1.js"), path.join(testCwd, "file2.js")]);
72
-
73
- bundler.addGlobPattern("*.js");
74
- const zip = await bundler.bundle();
75
-
76
- expect(mockGlob).toHaveBeenCalledWith(
77
- ["*.js"],
78
- expect.objectContaining({
79
- absolute: true,
80
- cwd: testCwd,
81
- }),
82
- );
83
-
84
- const files = Object.keys(zip.files);
85
- expect(files).toContain("file1.js");
86
- expect(files).toContain("file2.js");
87
- });
88
-
89
- it("should bundle files matching multiple patterns", async () => {
90
- const testCwd = process.cwd();
91
- mockGlob
92
- .mockResolvedValueOnce([path.join(testCwd, "file1.js"), path.join(testCwd, "file2.js")])
93
- .mockResolvedValueOnce([path.join(testCwd, "src", "index.ts"), path.join(testCwd, "src", "utils.ts")]);
94
-
95
- bundler.addGlobPattern("*.js");
96
- bundler.addGlobPattern("src/*.ts");
97
- const zip = await bundler.bundle();
98
-
99
- expect(mockGlob).toHaveBeenCalledTimes(2);
100
- expect(mockGlob).toHaveBeenNthCalledWith(1, ["*.js"], expect.any(Object));
101
- expect(mockGlob).toHaveBeenNthCalledWith(2, ["src/*.ts"], expect.any(Object));
102
-
103
- const files = Object.keys(zip.files);
104
- expect(files).toContain("file1.js");
105
- expect(files).toContain("file2.js");
106
- expect(files).toContain(path.join("src", "index.ts"));
107
- expect(files).toContain(path.join("src", "utils.ts"));
108
- });
109
-
110
- it("should handle array patterns", async () => {
111
- const testCwd = process.cwd();
112
- mockGlob.mockResolvedValueOnce([path.join(testCwd, "file1.js"), path.join(testCwd, "src", "index.ts")]);
113
-
114
- bundler.addGlobPattern(["*.js", "src/*.ts"]);
115
- const zip = await bundler.bundle();
116
-
117
- expect(mockGlob).toHaveBeenCalledWith(["*.js", "src/*.ts"], expect.any(Object));
118
-
119
- const files = Object.keys(zip.files);
120
- expect(files).toContain("file1.js");
121
- expect(files).toContain(path.join("src", "index.ts"));
122
- });
123
-
124
- it("should respect glob options", async () => {
125
- const testCwd = process.cwd();
126
- mockGlob.mockResolvedValueOnce([path.join(testCwd, "file1.js")]);
127
-
128
- const options = { ignore: ["node_modules/**"] };
129
- bundler.addGlobPattern("**/*.js", options);
130
- await bundler.bundle();
131
-
132
- expect(mockGlob).toHaveBeenCalledWith(
133
- ["**/*.js"],
134
- expect.objectContaining({
135
- ignore: ["node_modules/**"],
136
- absolute: true,
137
- }),
138
- );
139
- });
140
-
141
- it("should use provided cwd option", async () => {
142
- const customCwd = path.resolve("custom", "path");
143
- mockGlob.mockResolvedValueOnce([path.join(customCwd, "file.js")]);
144
-
145
- bundler.addGlobPattern("*.js", { cwd: customCwd });
146
- await bundler.bundle();
147
-
148
- expect(mockGlob).toHaveBeenCalledWith(
149
- ["*.js"],
150
- expect.objectContaining({
151
- cwd: customCwd,
152
- absolute: true,
153
- }),
154
- );
155
- });
156
-
157
- it("should handle URL cwd option", async () => {
158
- const testCwd = path.resolve("url", "path");
159
- // Create the directory structure in the mock filesystem
160
- vol.mkdirSync(testCwd, { recursive: true });
161
- vol.writeFileSync(path.join(testCwd, "file.js"), "test");
162
-
163
- mockGlob.mockResolvedValueOnce([path.join(testCwd, "file.js")]);
164
-
165
- const urlCwd = new URL(`file:///${testCwd.replace(/\\/g, "/")}`);
166
- bundler.addGlobPattern("*.js", { cwd: urlCwd });
167
- await bundler.bundle();
168
-
169
- expect(mockGlob).toHaveBeenCalledWith(
170
- ["*.js"],
171
- expect.objectContaining({
172
- cwd: testCwd,
173
- absolute: true,
174
- }),
175
- );
176
- });
177
-
178
- it("should resolve relative cwd paths", async () => {
179
- mockGlob.mockResolvedValueOnce([]);
180
-
181
- bundler.addGlobPattern("*.js", { cwd: "./relative/path" });
182
- await bundler.bundle();
183
-
184
- expect(mockGlob).toHaveBeenCalledWith(
185
- ["*.js"],
186
- expect.objectContaining({
187
- cwd: path.resolve("./relative/path"),
188
- absolute: true,
189
- }),
190
- );
191
- });
192
-
193
- it("should create zip with correct file paths relative to cwd", async () => {
194
- const testCwd = path.resolve("project");
195
- vol.mkdirSync(path.join(testCwd, "src"), { recursive: true });
196
- vol.writeFileSync(path.join(testCwd, "src", "index.ts"), "test content");
197
- vol.writeFileSync(path.join(testCwd, "package.json"), "{}");
198
-
199
- mockGlob.mockResolvedValueOnce([path.join(testCwd, "src", "index.ts"), path.join(testCwd, "package.json")]);
200
-
201
- bundler.addGlobPattern("**/*", { cwd: testCwd });
202
- const zip = await bundler.bundle();
203
-
204
- const files = Object.keys(zip.files);
205
- expect(files).toContain(path.join("src", "index.ts"));
206
- expect(files).toContain("package.json");
207
- // Ensure absolute paths are not used
208
- expect(files.every((f) => !path.isAbsolute(f))).toBe(true);
209
- });
210
-
211
- it("should handle empty glob results", async () => {
212
- mockGlob.mockResolvedValueOnce([]);
213
-
214
- bundler.addGlobPattern("*.nonexistent");
215
- const zip = await bundler.bundle();
216
-
217
- expect(Object.keys(zip.files)).toHaveLength(0);
218
- });
219
-
220
- it("should handle multiple patterns with some empty results", async () => {
221
- const testCwd = process.cwd();
222
- mockGlob.mockResolvedValueOnce([path.join(testCwd, "file1.js")]).mockResolvedValueOnce([]);
223
-
224
- bundler.addGlobPattern("*.js");
225
- bundler.addGlobPattern("*.nonexistent");
226
- const zip = await bundler.bundle();
227
-
228
- const files = Object.keys(zip.files);
229
- expect(files).toContain("file1.js");
230
- expect(files).toHaveLength(1);
231
- });
232
-
233
- it("should use DEFLATE compression", async () => {
234
- const testCwd = process.cwd();
235
- mockGlob.mockResolvedValueOnce([path.join(testCwd, "file1.js")]);
236
-
237
- bundler.addGlobPattern("*.js");
238
- const zip = await bundler.bundle();
239
-
240
- const files = Object.keys(zip.files);
241
- expect(files).toHaveLength(1);
242
-
243
- const file = zip.files[files[0]];
244
- expect(file).toBeDefined();
245
- expect(file.options.compression).toBe("DEFLATE");
246
- });
247
-
248
- it("should handle glob errors gracefully", async () => {
249
- const error = new Error("Glob failed");
250
- mockGlob.mockRejectedValueOnce(error);
251
-
252
- bundler.addGlobPattern("*.js");
253
-
254
- await expect(bundler.bundle()).rejects.toThrow("Glob failed");
255
- });
256
- });
257
-
258
- describe("AppBundler", () => {
259
- let appBundler: AppBundler;
260
-
261
- beforeEach(() => {
262
- vol.reset();
263
- appBundler = new AppBundler();
264
- vi.clearAllMocks();
265
- });
266
-
267
- describe("constructor", () => {
268
- it("should automatically include package.json pattern", () => {
269
- // Test passes if no error is thrown during construction
270
- // The package.json pattern is added in constructor
271
- expect(appBundler).toBeDefined();
272
- });
273
- });
274
-
275
- describe("installer folder exclusion", () => {
276
- beforeEach(() => {
277
- const testCwd = process.cwd();
278
- vol.fromJSON({
279
- [path.join(testCwd, "package.json")]: '{"name": "test-app"}',
280
- [path.join(testCwd, "src", "index.js")]: "console.log('app');",
281
- [path.join(testCwd, "installer", "setup.exe")]: "binary content",
282
- [path.join(testCwd, "installer", "data", "config.json")]: '{"setup": true}',
283
- [path.join(testCwd, "nested", "installer", "tool.exe")]: "tool content",
284
- [path.join(testCwd, "dist", "app.js")]: "built app",
285
- });
286
- });
287
-
288
- it("should exclude installer folder when no ignore options provided", async () => {
289
- const testCwd = process.cwd();
290
- // Mock package.json call (first call for auto-added pattern)
291
- mockGlob.mockResolvedValueOnce([path.join(testCwd, "package.json")]);
292
- // Mock user pattern call
293
- mockGlob.mockResolvedValueOnce([
294
- path.join(testCwd, "src", "index.js"),
295
- path.join(testCwd, "dist", "app.js"),
296
- ]);
297
-
298
- appBundler.addGlobPattern("**/*.js");
299
- const zip = await appBundler.bundle();
300
-
301
- expect(mockGlob).toHaveBeenNthCalledWith(
302
- 2,
303
- ["**/*.js"],
304
- expect.objectContaining({
305
- ignore: "**/installer/**",
306
- }),
307
- );
308
-
309
- const files = Object.keys(zip.files);
310
- expect(files).toContain("package.json");
311
- expect(files).toContain(path.join("src", "index.js"));
312
- expect(files).toContain(path.join("dist", "app.js"));
313
- });
314
-
315
- it("should merge installer exclusion with existing ignore patterns (string)", async () => {
316
- const testCwd = process.cwd();
317
- mockGlob.mockResolvedValueOnce([path.join(testCwd, "package.json")]);
318
- mockGlob.mockResolvedValueOnce([path.join(testCwd, "src", "index.js")]);
319
-
320
- appBundler.addGlobPattern("**/*.js", { ignore: "node_modules/**" });
321
- await appBundler.bundle();
322
-
323
- expect(mockGlob).toHaveBeenNthCalledWith(
324
- 2,
325
- ["**/*.js"],
326
- expect.objectContaining({
327
- ignore: ["node_modules/**", "**/installer/**"],
328
- }),
329
- );
330
- });
331
-
332
- it("should merge installer exclusion with existing ignore patterns (array)", async () => {
333
- const testCwd = process.cwd();
334
- mockGlob.mockResolvedValueOnce([path.join(testCwd, "package.json")]);
335
- mockGlob.mockResolvedValueOnce([path.join(testCwd, "src", "index.js")]);
336
-
337
- appBundler.addGlobPattern("**/*.js", {
338
- ignore: ["node_modules/**", "*.test.js"],
339
- });
340
- await appBundler.bundle();
341
-
342
- expect(mockGlob).toHaveBeenNthCalledWith(
343
- 2,
344
- ["**/*.js"],
345
- expect.objectContaining({
346
- ignore: ["node_modules/**", "*.test.js", "**/installer/**"],
347
- }),
348
- );
349
- });
350
-
351
- it("should not duplicate installer exclusion if already present", async () => {
352
- const testCwd = process.cwd();
353
- mockGlob.mockResolvedValueOnce([path.join(testCwd, "package.json")]);
354
- mockGlob.mockResolvedValueOnce([path.join(testCwd, "src", "index.js")]);
355
-
356
- appBundler.addGlobPattern("**/*.js", {
357
- ignore: ["**/installer/**", "node_modules/**"],
358
- });
359
- await appBundler.bundle();
360
-
361
- expect(mockGlob).toHaveBeenNthCalledWith(
362
- 2,
363
- ["**/*.js"],
364
- expect.objectContaining({
365
- ignore: ["**/installer/**", "node_modules/**", "**/installer/**"],
366
- }),
367
- );
368
- // Note: The current implementation doesn't dedupe, which is acceptable
369
- });
370
- });
371
-
372
- describe("package.json requirement", () => {
373
- it("should include package.json by default", async () => {
374
- const testCwd = process.cwd();
375
- mockGlob.mockResolvedValueOnce([path.join(testCwd, "package.json")]);
376
-
377
- const zip = await appBundler.bundle();
378
-
379
- expect(mockGlob).toHaveBeenCalledWith(["package.json"], expect.any(Object));
380
-
381
- const files = Object.keys(zip.files);
382
- expect(files).toContain("package.json");
383
- });
384
-
385
- it("should not throw error when package.json is automatically included", async () => {
386
- const testCwd = process.cwd();
387
- // Set up files in mock filesystem first
388
- vol.fromJSON({
389
- [path.join(testCwd, "package.json")]: '{"name": "test"}',
390
- [path.join(testCwd, "src", "index.js")]: "console.log('test');",
391
- });
392
-
393
- mockGlob.mockResolvedValueOnce([path.join(testCwd, "package.json")]);
394
- mockGlob.mockResolvedValueOnce([path.join(testCwd, "src", "index.js")]);
395
-
396
- appBundler.addGlobPattern("src/**/*.js");
397
-
398
- await expect(appBundler.bundle()).resolves.toBeDefined();
399
- });
400
-
401
- it("should throw error if package.json is not found despite being added", async () => {
402
- // Mock package.json pattern to return empty (simulating missing file)
403
- mockGlob.mockResolvedValueOnce([]);
404
- mockGlob.mockResolvedValueOnce([]);
405
-
406
- appBundler.addGlobPattern("src/**/*.js");
407
-
408
- await expect(appBundler.bundle()).rejects.toThrow("package.json not found");
409
- });
410
- });
411
-
412
- describe("multiple patterns with installer exclusion", () => {
413
- beforeEach(() => {
414
- const testCwd = process.cwd();
415
- vol.fromJSON({
416
- [path.join(testCwd, "package.json")]: '{"name": "test-app"}',
417
- [path.join(testCwd, "src", "index.js")]: "app code",
418
- [path.join(testCwd, "assets", "logo.png")]: "image data",
419
- [path.join(testCwd, "installer", "setup.exe")]: "installer",
420
- });
421
- });
422
-
423
- it("should apply installer exclusion to all patterns", async () => {
424
- const testCwd = process.cwd();
425
- mockGlob.mockResolvedValueOnce([path.join(testCwd, "package.json")]);
426
- mockGlob.mockResolvedValueOnce([path.join(testCwd, "src", "index.js")]);
427
- mockGlob.mockResolvedValueOnce([path.join(testCwd, "assets", "logo.png")]);
428
-
429
- appBundler.addGlobPattern("src/**/*.js", { ignore: "*.test.js" });
430
- appBundler.addGlobPattern("assets/**/*");
431
-
432
- const zip = await appBundler.bundle();
433
-
434
- // Check that installer exclusion is applied to both patterns
435
- expect(mockGlob).toHaveBeenNthCalledWith(
436
- 2,
437
- ["src/**/*.js"],
438
- expect.objectContaining({
439
- ignore: ["*.test.js", "**/installer/**"],
440
- }),
441
- );
442
- expect(mockGlob).toHaveBeenNthCalledWith(
443
- 3,
444
- ["assets/**/*"],
445
- expect.objectContaining({
446
- ignore: "**/installer/**",
447
- }),
448
- );
449
-
450
- const files = Object.keys(zip.files);
451
- expect(files).toContain("package.json");
452
- expect(files).toContain(path.join("src", "index.js"));
453
- expect(files).toContain(path.join("assets", "logo.png"));
454
- });
455
- });
456
- });
457
- });
@@ -1,7 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
-
3
- describe("temp", () => {
4
- it("should be true", () => {
5
- expect(true).toBe(true);
6
- });
7
- });
@@ -1,2 +0,0 @@
1
- // eslint-disable no-export
2
- export const noop = () => {};
package/moon.yml DELETED
@@ -1,18 +0,0 @@
1
- id: "cli"
2
- language: "typescript"
3
- type: "library"
4
-
5
- tasks:
6
- build:
7
- command: "tsdown"
8
- outputs:
9
- - "dist"
10
-
11
- test:
12
- command: "vitest run"
13
-
14
- test-watch:
15
- command: "vitest"
16
- local: true
17
- env:
18
- ATTEST_skipTypes: "1"
package/setupVitest.ts DELETED
@@ -1,5 +0,0 @@
1
- // eslint-disable no-export
2
- import { setup } from "@ark/attest";
3
-
4
- // config options can be passed here
5
- export default () => setup({});
@@ -1,87 +0,0 @@
1
- import { Command, UsageError } from "clipanion";
2
- import chalk from "chalk";
3
- import fs from "node:fs";
4
- import { COMMAND_CATEGORIES } from "../consts";
5
- import {
6
- type BundleAppConfig,
7
- type BundleSiteConfig,
8
- OVERLAYED_CONFIG_GLOB,
9
- getOverlayedConfigs,
10
- } from "@overlayed/utils-node";
11
- import { AppBundler } from "./internal/appBundler";
12
- import { Bundler } from "./internal/bundler";
13
-
14
- export class BundleCommand extends Command {
15
- private readonly overlayedConfigGlob = "**/overlayed.config.{js,ts,mts}";
16
-
17
- public static override paths = [["bundle"]];
18
-
19
- public static override usage = Command.Usage({
20
- category: COMMAND_CATEGORIES.deployment,
21
- description: "Bundle the app and site for deployment.",
22
- details: `
23
- Bundle the app and site for deployment.
24
-
25
- [Docs](http://docs.overlayed.gg/cli/bundle)
26
- `,
27
- examples: [["Basic usage", "$0 bundle"]],
28
- });
29
-
30
- public async execute(): Promise<void> {
31
- const config = await this.resolveConfig();
32
-
33
- // TODO remove this and send via API instead
34
- const appWriteStream = fs.createWriteStream(process.cwd() + "/app.zip");
35
- const appZip = await config.app.bundle();
36
- appWriteStream.write(await appZip.generateAsync({ type: "nodebuffer" }));
37
-
38
- if (config.site) {
39
- const siteWriteStream = fs.createWriteStream(process.cwd() + "/site.zip");
40
- const siteZip = await config.site?.bundle();
41
-
42
- siteWriteStream.write(await siteZip?.generateAsync({ type: "nodebuffer" }));
43
- }
44
-
45
- this.context.stdout.write(chalk.green("Bundle created successfully."));
46
- }
47
-
48
- private async resolveConfig() {
49
- const configs = await getOverlayedConfigs();
50
-
51
- if (configs.length === 0) {
52
- throw new UsageError("No config file found matching " + this.overlayedConfigGlob);
53
- }
54
-
55
- if (configs.length > 1) {
56
- this.context.stdout.write(
57
- chalk.yellow(`
58
- Multiple config files found matching ${OVERLAYED_CONFIG_GLOB}, using the first one.
59
- `),
60
- );
61
- }
62
-
63
- const config = configs.at(0)!;
64
- return {
65
- app: this.getAppBundler(config.app),
66
- site: config.site ? this.getSiteBundler(config.site) : undefined,
67
- };
68
- }
69
-
70
- private getAppBundler(config: BundleAppConfig) {
71
- const bundler = new AppBundler();
72
- bundler.addGlobPattern(config.include, {
73
- ignore: config.exclude,
74
- });
75
-
76
- return bundler;
77
- }
78
-
79
- private getSiteBundler(config: BundleSiteConfig) {
80
- const bundler = new Bundler();
81
- bundler.addGlobPattern(config.include, {
82
- ignore: config.exclude,
83
- });
84
-
85
- return bundler;
86
- }
87
- }
@@ -1,35 +0,0 @@
1
- import { Bundler, type BundlerPatternOptions } from "./bundler";
2
- import type Zip from "jszip";
3
-
4
- export class AppBundler extends Bundler {
5
- private readonly installerFolderGlob = "**/installer/**";
6
-
7
- public constructor() {
8
- super();
9
- this.addGlobPattern("package.json");
10
- }
11
-
12
- public override async bundle(): Promise<Zip> {
13
- const zip = await super.bundle();
14
-
15
- const packageJson = zip.file("package.json");
16
- if (!packageJson) {
17
- throw new Error("package.json not found");
18
- }
19
-
20
- return zip;
21
- }
22
-
23
- protected override resolveOptions(options: BundlerPatternOptions | undefined): BundlerPatternOptions | undefined {
24
- if (!options) {
25
- return {
26
- ignore: this.installerFolderGlob,
27
- };
28
- }
29
-
30
- const ignore = typeof options.ignore === "string" ? [options.ignore] : (options.ignore ?? []);
31
- ignore.push(this.installerFolderGlob);
32
- options.ignore = ignore;
33
- return options;
34
- }
35
- }
@@ -1,77 +0,0 @@
1
- import { glob, type GlobOptionsWithFileTypesFalse } from "glob";
2
- import { createReadStream } from "node:fs";
3
- import { fileURLToPath } from "node:url";
4
- import path from "node:path";
5
- import Zip from "jszip";
6
- import { asArray } from "@overlayed/utils";
7
-
8
- class PatternSet {
9
- public readonly pattern: string[];
10
- public readonly options?: GlobOptionsWithFileTypesFalse;
11
-
12
- constructor(pattern: string[], options?: BundlerPatternOptions) {
13
- this.pattern = pattern;
14
- this.options = options;
15
- }
16
- }
17
-
18
- export interface BundlerPatternOptions extends GlobOptionsWithFileTypesFalse {
19
- ignore?: string | string[];
20
- }
21
-
22
- /**
23
- * Bundles files into a zip file based on a set of glob patterns.
24
- *
25
- * Always includes package.json in the bundle.
26
- * Excludes installer folder.
27
- */
28
- export class Bundler {
29
- private patterns: PatternSet[] = [];
30
-
31
- public addGlobPattern(pattern: string | string[], options?: BundlerPatternOptions): void {
32
- const resolvedOptions = this.resolveOptions(options);
33
- const patternArray = asArray(pattern);
34
- this.patterns.push(new PatternSet(patternArray, resolvedOptions));
35
- }
36
-
37
- public async bundle(): Promise<Zip> {
38
- const zip = new Zip();
39
-
40
- for (const pattern of this.patterns) {
41
- const options = pattern.options ?? {};
42
-
43
- let cwd: string;
44
-
45
- if (!options.cwd) {
46
- cwd = process.cwd();
47
- } else if (typeof options.cwd === "string") {
48
- cwd = options.cwd;
49
- } else {
50
- cwd = fileURLToPath(options.cwd);
51
- }
52
-
53
- if (!path.isAbsolute(cwd)) {
54
- cwd = path.resolve(cwd);
55
- }
56
-
57
- options.absolute = true;
58
- options.cwd = cwd;
59
-
60
- const files = await glob(pattern.pattern, options);
61
- await Promise.all(
62
- files.map(async (file) => {
63
- const zipPath = path.relative(cwd, file);
64
- const stream = createReadStream(file, "binary");
65
-
66
- zip.file(zipPath, stream, { compression: "DEFLATE" });
67
- }),
68
- );
69
- }
70
-
71
- return zip;
72
- }
73
-
74
- protected resolveOptions(options: BundlerPatternOptions | undefined): BundlerPatternOptions | undefined {
75
- return options;
76
- }
77
- }
@@ -1,6 +0,0 @@
1
- import { isObject } from "@overlayed/utils";
2
- import type { defineConfig } from "../config";
3
-
4
- export function isBundleConfig(config: unknown): config is ReturnType<typeof defineConfig> {
5
- return isObject(config) && "app" in config;
6
- }
package/src/cli.ts DELETED
@@ -1,4 +0,0 @@
1
- import { runExit } from "clipanion";
2
- import { BundleCommand } from "./bundle/command";
3
-
4
- runExit([BundleCommand]);
package/src/consts.ts DELETED
@@ -1,3 +0,0 @@
1
- export const COMMAND_CATEGORIES = {
2
- deployment: "deployment",
3
- } as const;
package/temp/myfile.txt DELETED
File without changes
@@ -1,8 +0,0 @@
1
- import { defineConfig } from "../src/bundle/config";
2
-
3
- // TODO think about allowing just an object
4
- export default defineConfig({
5
- app: {
6
- include: ["**/*.ts"],
7
- },
8
- });
File without changes
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.options.json",
3
- "compilerOptions": {
4
- "outDir": "dist",
5
- "rootDir": "src"
6
- },
7
- "include": ["src/**/*"]
8
- }
package/tsconfig.json DELETED
@@ -1,38 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.options.json",
3
- "compilerOptions": {
4
- "emitDeclarationOnly": true,
5
- "outDir": "./dist",
6
- "paths": {
7
- "@overlayed/utils": [
8
- "../utils/src/index.ts"
9
- ],
10
- "@overlayed/utils/*": [
11
- "../utils/src/*"
12
- ],
13
- "@overlayed/utils-node": [
14
- "../utils-node/src/index.ts"
15
- ],
16
- "@overlayed/utils-node/*": [
17
- "../utils-node/src/*"
18
- ]
19
- }
20
- },
21
- "include": [
22
- "*.js",
23
- "*.ts",
24
- "__tests__/**/*",
25
- "src/**/*"
26
- ],
27
- "references": [
28
- {
29
- "path": "./tsconfig.build.json"
30
- },
31
- {
32
- "path": "../utils"
33
- },
34
- {
35
- "path": "../utils-node"
36
- }
37
- ]
38
- }
package/tsdown.config.ts DELETED
@@ -1,18 +0,0 @@
1
- import { defineConfig } from "tsdown";
2
-
3
- export default defineConfig({
4
- tsconfig: "tsconfig.build.json",
5
- platform: "node",
6
- entry: {
7
- cli: "src/cli.ts",
8
- },
9
- dts: {
10
- sourcemap: false,
11
- resolve: true,
12
- },
13
- minify: true,
14
- sourcemap: false,
15
- // TODO: investigate why treeshaking is not working, maybe a bug with tsdown since its still a newer package
16
- // for now we can at least remove arktype since its huge
17
- external: [/arktype/, /@ark\/util/],
18
- });
package/vitest.config.ts DELETED
@@ -1,17 +0,0 @@
1
- import { defineConfig } from "vitest/config";
2
- import tsconfigPaths from "vite-tsconfig-paths";
3
- export default defineConfig({
4
- plugins: [tsconfigPaths({
5
- skip(dir) {
6
- return !dir.includes("templates");
7
- },
8
- }),],
9
- test: {
10
- globalSetup: "./setupVitest.ts",
11
- typecheck: {
12
- enabled: true,
13
- ignoreSourceErrors: true,
14
- tsconfig: "./tsconfig.build.json",
15
- }
16
- },
17
- });