@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/dist/cli.js +4 -1679
- package/package.json +8 -4
- package/.attest/assertions/typescript.json +0 -1
- package/__mocks__/fs/promises.cjs +0 -2
- package/__mocks__/fs.cjs +0 -2
- package/__tests__/bundler.test.ts +0 -457
- package/__tests__/temp.test.ts +0 -7
- package/__tests__/utils.ts +0 -2
- package/dist/chunk-RDQt0V5E.js +0 -31
- package/dist/lib-DalWKwNu.js +0 -1041
- package/moon.yml +0 -18
- package/setupVitest.ts +0 -5
- package/src/bundle/command.ts +0 -87
- package/src/bundle/internal/appBundler.ts +0 -35
- package/src/bundle/internal/bundler.ts +0 -77
- package/src/bundle/internal/isBundleConfig.ts +0 -6
- package/src/cli.ts +0 -4
- package/src/consts.ts +0 -3
- package/temp/myfile.txt +0 -0
- package/temp/overlayed.config.ts +0 -8
- package/temp/someotherfile.ts +0 -0
- package/tsconfig.build.json +0 -8
- package/tsconfig.json +0 -38
- package/tsdown.config.ts +0 -13
- package/vitest.config.ts +0 -17
package/moon.yml
DELETED
package/setupVitest.ts
DELETED
package/src/bundle/command.ts
DELETED
|
@@ -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
|
-
}
|
package/src/cli.ts
DELETED
package/src/consts.ts
DELETED
package/temp/myfile.txt
DELETED
|
File without changes
|
package/temp/overlayed.config.ts
DELETED
package/temp/someotherfile.ts
DELETED
|
File without changes
|
package/tsconfig.build.json
DELETED
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
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
|
-
});
|