@overlayed/cli 0.0.1 → 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/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": "lib",
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,13 +0,0 @@
1
- import { defineConfig } from "tsdown";
2
-
3
- export default defineConfig({
4
- entry: {
5
- cli: "src/cli.ts",
6
- },
7
- platform: "node",
8
- dts: {
9
- sourcemap: false,
10
- },
11
- tsconfig: "tsconfig.build.json",
12
- sourcemap: false,
13
- });
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
- });