@kosmojs/dev 0.0.4 → 0.0.6
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 +31 -11
- package/pkg/cli/cli.js +566 -0
- package/pkg/cli/cli.js.map +7 -0
- package/pkg/cli/index.js +408 -0
- package/pkg/cli/index.js.map +7 -0
- package/pkg/cli/templates/.env +1 -0
- package/pkg/cli/templates/@src/api/app.hbs +32 -0
- package/pkg/cli/templates/@src/api/router.hbs +11 -0
- package/pkg/cli/templates/@src/api/server.hbs +4 -0
- package/pkg/cli/templates/@src/api/use.hbs +6 -0
- package/pkg/cli/templates/@src/config/index.hbs +2 -0
- package/pkg/cli/templates/@src/index.html +4 -0
- package/pkg/cli/templates/@src/vite.config.hbs +29 -0
- package/pkg/cli/templates/core/api/app.ts +6 -0
- package/pkg/cli/templates/core/api/env.d.ts +4 -0
- package/pkg/cli/templates/core/api/router.ts +6 -0
- package/pkg/cli/templates/core/api/server.ts +49 -0
- package/pkg/cli/templates/core/api/use.ts +21 -0
- package/pkg/cli/templates/vite.base.hbs +44 -0
- package/pkg/src/cli/base.d.ts +30 -0
- package/pkg/src/cli/cli.d.ts +2 -0
- package/pkg/src/cli/factory.d.ts +12 -0
- package/pkg/src/cli/index.d.ts +2 -0
- package/pkg/src/cli/templates/core/api/app.d.ts +3 -0
- package/pkg/src/cli/templates/core/api/router.d.ts +3 -0
- package/pkg/src/cli/templates/core/api/server.d.ts +3 -0
- package/pkg/src/cli/templates/core/api/use.d.ts +2 -0
- package/pkg/test/cli/create.test.d.ts +1 -0
- package/pkg/test/setup.d.ts +1 -0
- package/pkg/cli.js +0 -3
- package/pkg/cli.js.map +0 -7
- package/pkg/src/cli.d.ts +0 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
|
|
3
|
+
{{#each plugins}}{{importDeclaration}}
|
|
4
|
+
{{/each}}
|
|
5
|
+
import devPlugin, { apiGenerator, fetchGenerator } from "@kosmojs/dev";
|
|
6
|
+
{{#each generators}}{{importDeclaration}}
|
|
7
|
+
{{/each}}
|
|
8
|
+
|
|
9
|
+
import defineConfig from "../vite.base";
|
|
10
|
+
import { apiurl, baseurl } from "./config";
|
|
11
|
+
|
|
12
|
+
export default defineConfig(import.meta.dirname, {
|
|
13
|
+
base: join(baseurl, "/"),
|
|
14
|
+
server: {
|
|
15
|
+
port: {{folder.port}},
|
|
16
|
+
},
|
|
17
|
+
plugins: [
|
|
18
|
+
{{#each plugins}}{{importName}}({{options}}),
|
|
19
|
+
{{/each}}
|
|
20
|
+
devPlugin(apiurl, {
|
|
21
|
+
generators: [
|
|
22
|
+
apiGenerator(),
|
|
23
|
+
fetchGenerator(),
|
|
24
|
+
{{#each generators}}{{importName}}({{options}}),
|
|
25
|
+
{{/each}}
|
|
26
|
+
],
|
|
27
|
+
}),
|
|
28
|
+
],
|
|
29
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { chmod, unlink } from "node:fs/promises";
|
|
2
|
+
import { parseArgs } from "node:util";
|
|
3
|
+
|
|
4
|
+
import type { App } from "@kosmojs/api";
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
values: { port, sock },
|
|
8
|
+
} = parseArgs({
|
|
9
|
+
options: {
|
|
10
|
+
port: {
|
|
11
|
+
type: "string",
|
|
12
|
+
short: "p",
|
|
13
|
+
},
|
|
14
|
+
sock: {
|
|
15
|
+
type: "string",
|
|
16
|
+
short: "s",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
if (![port, sock].some((e) => e)) {
|
|
22
|
+
console.error("Please provide either -p/--port number or -s/--sock path");
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
console.log("\n ➜ Starting Server", { port, sock });
|
|
27
|
+
|
|
28
|
+
if (sock) {
|
|
29
|
+
await unlink(sock).catch((error) => {
|
|
30
|
+
if (error.code === "ENOENT") {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
console.error(error.message);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default async <T extends App = App>(
|
|
39
|
+
createApp: () => T | Promise<T>,
|
|
40
|
+
): Promise<import("node:http").Server> => {
|
|
41
|
+
const app = await createApp();
|
|
42
|
+
// app.listen is returning the actual server
|
|
43
|
+
return app.listen(port || sock, async () => {
|
|
44
|
+
if (sock) {
|
|
45
|
+
await chmod(sock, 0o777);
|
|
46
|
+
}
|
|
47
|
+
console.log("\n ➜ Server Started ✨\n");
|
|
48
|
+
});
|
|
49
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { use } from "@kosmojs/api";
|
|
2
|
+
import bodyparser from "@kosmojs/api/bodyparser";
|
|
3
|
+
|
|
4
|
+
// Middleware applied to all routes by default.
|
|
5
|
+
// Can be overridden on a per-route basis using the slot key.
|
|
6
|
+
export default [
|
|
7
|
+
use(bodyparser.json(), {
|
|
8
|
+
on: ["POST", "PUT", "PATCH"],
|
|
9
|
+
slot: "bodyparser",
|
|
10
|
+
}),
|
|
11
|
+
|
|
12
|
+
use(
|
|
13
|
+
(ctx, next) => {
|
|
14
|
+
ctx.payload = ["POST", "PUT", "PATCH"].includes(ctx.method)
|
|
15
|
+
? ctx.request.body
|
|
16
|
+
: ctx.query;
|
|
17
|
+
return next();
|
|
18
|
+
},
|
|
19
|
+
{ slot: "payload" },
|
|
20
|
+
),
|
|
21
|
+
];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { basename, resolve } from "node:path";
|
|
2
|
+
|
|
3
|
+
import { aliasPlugin, definePlugin } from "@kosmojs/dev";
|
|
4
|
+
import { loadEnv, mergeConfig, type UserConfig } from "vite";
|
|
5
|
+
|
|
6
|
+
import pkg from "./package.json" with { type: "json" };
|
|
7
|
+
|
|
8
|
+
export default async (sourceFolderPath: string, config: UserConfig) => {
|
|
9
|
+
const env = loadEnv("mock", import.meta.dirname);
|
|
10
|
+
const sourceFolder = basename(sourceFolderPath);
|
|
11
|
+
return mergeConfig(config, {
|
|
12
|
+
build: {
|
|
13
|
+
outDir: resolve(import.meta.dirname, `${pkg.distDir}/${sourceFolder}`),
|
|
14
|
+
emptyOutDir: true,
|
|
15
|
+
sourcemap: true,
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
server: {
|
|
19
|
+
host: true,
|
|
20
|
+
allowedHosts: [env.VITE_HOSTNAME],
|
|
21
|
+
fs: {
|
|
22
|
+
strict: false,
|
|
23
|
+
},
|
|
24
|
+
watch: {
|
|
25
|
+
awaitWriteFinish: {
|
|
26
|
+
stabilityThreshold: 800,
|
|
27
|
+
pollInterval: 200,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
cacheDir: resolve(import.meta.dirname, `var/.vite/${sourceFolder}`),
|
|
33
|
+
|
|
34
|
+
plugins: [
|
|
35
|
+
aliasPlugin(import.meta.dirname),
|
|
36
|
+
definePlugin([
|
|
37
|
+
{
|
|
38
|
+
// keys extracted from process.env and exposed to client
|
|
39
|
+
keys: ["DEBUG"],
|
|
40
|
+
},
|
|
41
|
+
]),
|
|
42
|
+
],
|
|
43
|
+
});
|
|
44
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type Project = {
|
|
2
|
+
name: string;
|
|
3
|
+
distDir?: string;
|
|
4
|
+
};
|
|
5
|
+
export type SourceFolder = {
|
|
6
|
+
name: string;
|
|
7
|
+
framework?: (typeof FRAMEWORK_OPTIONS)[number];
|
|
8
|
+
ssr?: boolean;
|
|
9
|
+
base?: string;
|
|
10
|
+
port?: number | string;
|
|
11
|
+
};
|
|
12
|
+
export declare const CREATE_OPTIONS: readonly ["project", "folder"];
|
|
13
|
+
export declare const FRAMEWORK_OPTIONS: readonly ["none", "solid", "react"];
|
|
14
|
+
export declare const NODE_VERSION = "22";
|
|
15
|
+
export declare const DEFAULT_DIST = "dist";
|
|
16
|
+
export declare const DEFAULT_BASE = "/";
|
|
17
|
+
export declare const DEFAULT_PORT = "4000";
|
|
18
|
+
export declare const DEFAULT_FRAMEWORK: "none";
|
|
19
|
+
export declare const copyFiles: (src: string, dst: string, { exclude }?: {
|
|
20
|
+
exclude?: Array<string | RegExp>;
|
|
21
|
+
}) => Promise<void>;
|
|
22
|
+
export declare const pathExists: (path: string) => Promise<boolean>;
|
|
23
|
+
export declare const validateName: (name: string | undefined) => "Invalid name provided" | "May contain only alphanumerics, hyphens, periods or any of @ $ +" | undefined;
|
|
24
|
+
export declare const validateBase: (base: string | undefined) => "Should start with a slash" | "Should not contain path traversal patterns" | undefined;
|
|
25
|
+
export declare const validatePort: (port: string | number | undefined) => "Invalid port number" | undefined;
|
|
26
|
+
export declare const assertNoError: (validator: () => string | undefined) => void;
|
|
27
|
+
export declare const messageFactory: (logger?: (...lines: Array<unknown>) => void) => {
|
|
28
|
+
projectCreated(project: Project): unknown[] | undefined;
|
|
29
|
+
sourceFolderCreated(_folder: SourceFolder): unknown[] | undefined;
|
|
30
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Project, type SourceFolder } from "./base";
|
|
2
|
+
export declare const createProject: (path: string, project: Project, assets?: {
|
|
3
|
+
NODE_VERSION?: `${number}`;
|
|
4
|
+
dependencies?: Record<string, string>;
|
|
5
|
+
devDependencies?: Record<string, string>;
|
|
6
|
+
}) => Promise<void>;
|
|
7
|
+
export declare const createSourceFolder: (projectRoot: string, // path inside project
|
|
8
|
+
folder: SourceFolder, opt?: {
|
|
9
|
+
frameworkOptions?: Record<string, unknown>;
|
|
10
|
+
dependencies?: Record<string, string>;
|
|
11
|
+
devDependencies?: Record<string, string>;
|
|
12
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/pkg/cli.js
DELETED
package/pkg/cli.js.map
DELETED
package/pkg/src/cli.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "kosmojs/cli";
|