@peachy/core 0.0.9 → 0.0.11

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.
@@ -0,0 +1 @@
1
+ export { };
@@ -1,11 +1,18 @@
1
1
  #!/usr/bin/env node
2
+ import { loadUserOptions } from "../load.mjs";
2
3
  import { build } from "./build.mjs";
3
4
  import { watch } from "./watch.mjs";
5
+ import { join } from "node:path";
4
6
  import { minArgs } from "minargs";
5
7
 
6
- //#region src/bin.ts
8
+ //#region src/cli/bin.ts
7
9
  const { positionals } = minArgs();
8
- const config = { input: positionals[2] || "./src/index.tsx" };
10
+ const config = {
11
+ input: positionals[2] || "./src/index.tsx",
12
+ output: join(process.cwd(), "dist"),
13
+ user: await loadUserOptions(),
14
+ runner: { env: {} }
15
+ };
9
16
  switch (positionals[0]) {
10
17
  case "build":
11
18
  await build({
@@ -1,8 +1,8 @@
1
- import { getOptions } from "./options.mjs";
2
- import { build } from "rolldown";
1
+ import { getOptions } from "../options.mjs";
3
2
  import { join, resolve } from "node:path";
3
+ import { build } from "rolldown";
4
4
 
5
- //#region src/build.ts
5
+ //#region src/cli/build.ts
6
6
  async function build$1(config) {
7
7
  const { input, output } = getOptions(config);
8
8
  const result = await build({
@@ -0,0 +1,22 @@
1
+ import { getOptions } from "../options.mjs";
2
+ import { watch } from "rolldown";
3
+
4
+ //#region src/cli/watch.ts
5
+ function watch$1(config) {
6
+ return new Promise((resolve) => {
7
+ const { input, output } = getOptions(config);
8
+ const watcher = watch({
9
+ ...input,
10
+ output
11
+ });
12
+ watcher.on("event", (event) => {
13
+ switch (event.code) {
14
+ case "ERROR": console.error(event.error.message);
15
+ }
16
+ });
17
+ watcher.on("close", () => resolve());
18
+ });
19
+ }
20
+
21
+ //#endregion
22
+ export { watch$1 as watch };
@@ -1,14 +1,14 @@
1
1
  import { WebSocketServer } from "ws";
2
2
 
3
- //#region src/ws.ts
3
+ //#region src/cli/ws.ts
4
4
  function createWebSocketServer() {
5
5
  const wss = new WebSocketServer({ port: 0 });
6
6
  let reloadHandler = null;
7
7
  wss.on("connection", (ws) => {
8
8
  ws.on("error", console.error);
9
- ws.on("message", (data) => {
9
+ ws.on("message", async (data) => {
10
10
  try {
11
- if (JSON.parse(data.toString()).type === "reload") if (reloadHandler) reloadHandler();
11
+ if (JSON.parse(data.toString()).type === "reload") if (reloadHandler) await reloadHandler();
12
12
  else console.warn("[HMR] No reload handler registered");
13
13
  } catch {}
14
14
  });
@@ -0,0 +1,6 @@
1
+ import { UserOptions } from "./types.mjs";
2
+
3
+ //#region src/config.d.ts
4
+ declare function defineConfig(options: UserOptions): UserOptions;
5
+ //#endregion
6
+ export { defineConfig };
@@ -0,0 +1,7 @@
1
+ //#region src/config.ts
2
+ function defineConfig(options) {
3
+ return options;
4
+ }
5
+
6
+ //#endregion
7
+ export { defineConfig };
@@ -0,0 +1,5 @@
1
+ //#region src/constants.ts
2
+ const PEACHY_ICONS_DEFAULT_PATH = "data/icons";
3
+
4
+ //#endregion
5
+ export { PEACHY_ICONS_DEFAULT_PATH };
@@ -0,0 +1,3 @@
1
+ import { InternalOptions, UserOptions } from "./types.mjs";
2
+ import { defineConfig } from "./config.mjs";
3
+ export { InternalOptions, UserOptions, defineConfig };
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { defineConfig } from "./config.mjs";
2
+
3
+ export { defineConfig };
package/dist/load.mjs ADDED
@@ -0,0 +1,42 @@
1
+ import fs from "fs/promises";
2
+ import path from "path";
3
+
4
+ //#region src/load.ts
5
+ const CONFIG_NAMES = [
6
+ "peachy.config.ts",
7
+ "peachy.config.mts",
8
+ "peachy.config.js",
9
+ "peachy.config.mjs"
10
+ ];
11
+ /**
12
+ * Loads the user configuration from `process.cwd()`
13
+ */
14
+ async function loadUserOptions() {
15
+ for (const name of CONFIG_NAMES) {
16
+ const confName = path.resolve(process.cwd(), name);
17
+ if (!await exists(confName)) continue;
18
+ let module;
19
+ try {
20
+ module = await import(confName);
21
+ } catch (error) {
22
+ throw new TypeError(`The config file at "${confName}" is not a valid module`, { cause: error });
23
+ }
24
+ if (!module.default) throw new TypeError(`The config file at "${confName}" doesn't have a default export`);
25
+ return module.default;
26
+ }
27
+ const packageJsonPath = path.resolve(process.cwd(), "package.json");
28
+ if (await exists(packageJsonPath)) {
29
+ const packageJson = await fs.readFile(packageJsonPath, "utf8");
30
+ try {
31
+ const { peachy } = JSON.parse(packageJson);
32
+ if (typeof peachy === "object") return peachy;
33
+ } catch {}
34
+ }
35
+ return {};
36
+ }
37
+ async function exists(path) {
38
+ return fs.stat(path).then((info) => info.isFile()).catch(() => false);
39
+ }
40
+
41
+ //#endregion
42
+ export { loadUserOptions };
package/dist/options.mjs CHANGED
@@ -1,13 +1,17 @@
1
- import { broadcastMessage, createWebSocketServer } from "./ws.mjs";
2
- import { react } from "@peachy/plugin-react";
3
- import { gjsRunner } from "@peachy/plugin-runner";
1
+ import { broadcastMessage, createWebSocketServer } from "./cli/ws.mjs";
2
+ import { PEACHY_ICONS_DEFAULT_PATH } from "./constants.mjs";
4
3
  import { resolve } from "node:path";
4
+ import { cssPlugin } from "@peachy/plugin-css";
5
+ import { reactHMRPlugin } from "@peachy/plugin-react";
6
+ import { resourcesPlugin } from "@peachy/plugin-resources";
7
+ import { gjsRunner } from "@peachy/plugin-runner";
5
8
  import { replacePlugin } from "rolldown/plugins";
6
9
  import { cleandir } from "rollup-plugin-cleandir";
7
10
 
8
11
  //#region src/options.ts
9
- function getOptions({ input, run = false, prod = false }) {
12
+ function getOptions(options) {
10
13
  const { wss, port, setReloadHandler } = createWebSocketServer();
14
+ const { input, run = false, prod = false, output } = options;
11
15
  return {
12
16
  input: {
13
17
  input: resolve(process.cwd(), input),
@@ -16,7 +20,7 @@ function getOptions({ input, run = false, prod = false }) {
16
20
  tsconfig: true,
17
21
  plugins: [
18
22
  prod ? cleandir(["dist"]) : void 0,
19
- prod ? void 0 : react(port),
23
+ prod ? void 0 : reactHMRPlugin(port),
20
24
  run ? gjsRunner({
21
25
  sendMessage: (message) => {
22
26
  if (wss.clients.size === 0) {
@@ -25,15 +29,28 @@ function getOptions({ input, run = false, prod = false }) {
25
29
  }
26
30
  broadcastMessage(wss, JSON.stringify(message));
27
31
  },
28
- setReloadHandler
32
+ setReloadHandler,
33
+ options: options.runner
29
34
  }) : void 0,
30
- replacePlugin({ "process.env.NODE_ENV": JSON.stringify(prod ? "production" : "development") })
35
+ replacePlugin({ "process.env.NODE_ENV": JSON.stringify(prod ? "production" : "development") }),
36
+ options.user.resources !== false ? resourcesPlugin({
37
+ applicationId: options.user.applicationId,
38
+ outdir: output,
39
+ prod,
40
+ setRunnerEnv(key, value) {
41
+ options.runner.env[key] = value;
42
+ },
43
+ iconsPath: options.user.resources == true || options.user.resources?.icons === true ? PEACHY_ICONS_DEFAULT_PATH : options.user.resources?.icons == false ? false : options.user.resources?.icons ?? PEACHY_ICONS_DEFAULT_PATH,
44
+ bundle: typeof options.user.resources === "object" ? options.user.resources.bundle : void 0
45
+ }) : null,
46
+ cssPlugin({ prod })
31
47
  ]
32
48
  },
33
49
  output: {
34
50
  format: "esm",
35
- dir: "./dist",
51
+ dir: output,
36
52
  preserveModules: !prod,
53
+ preserveModulesRoot: process.cwd(),
37
54
  sourcemap: true,
38
55
  minify: prod
39
56
  }
@@ -0,0 +1,40 @@
1
+ import { BundledResource } from "@peachy/plugin-resources";
2
+ import { RunnerOptions } from "@peachy/plugin-runner";
3
+
4
+ //#region src/types.d.ts
5
+ interface UserOptions {
6
+ /**
7
+ * Options pertaining to the package
8
+ */
9
+ /**
10
+ * The name of this application, in RDNSS name format (i.e. dev.peach.Example)
11
+ */
12
+ applicationId?: string;
13
+ /**
14
+ * Whether to enable the automatic resources handling
15
+ */
16
+ resources?: boolean | {
17
+ /**
18
+ * Whether to automatically enable loading of icons from this directory.
19
+ *
20
+ * If set to true, will default to the default directory: `./data/icons`
21
+ *
22
+ * Default is true
23
+ */
24
+ icons?: boolean | string;
25
+ /**
26
+ * Resources to bundle automatically
27
+ */
28
+ bundle?: BundledResource[];
29
+ };
30
+ }
31
+ interface InternalOptions {
32
+ input: string;
33
+ output: string;
34
+ run?: boolean;
35
+ prod?: boolean;
36
+ user: UserOptions;
37
+ runner: RunnerOptions;
38
+ }
39
+ //#endregion
40
+ export { InternalOptions, UserOptions };
package/package.json CHANGED
@@ -1,34 +1,41 @@
1
1
  {
2
2
  "name": "@peachy/core",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Base peachy CLI",
5
- "type": "module",
5
+ "license": "MIT",
6
+ "author": "Angelo Verlain <hey@vixalien.com>",
6
7
  "bin": {
7
- "peachy": "./dist/bin.mjs"
8
+ "peachy": "./dist/cli/bin.mjs"
8
9
  },
10
+ "files": [
11
+ "dist",
12
+ "tsconfig.json"
13
+ ],
14
+ "type": "module",
9
15
  "exports": {
16
+ ".": {
17
+ "import": "./dist/index.mjs",
18
+ "types": "./dist/index.d.ts"
19
+ },
10
20
  "./tsconfig": "./tsconfig.json"
11
21
  },
12
- "author": "Angelo Verlain <hey@vixalien.com>",
13
- "license": "MIT",
14
- "devDependencies": {
15
- "@types/node": "^25.0.9",
16
- "tsdown": "0.20.0-beta.4",
17
- "tsx": "^4.21.0"
18
- },
19
22
  "dependencies": {
20
- "@peachy/types": "^2025.1.18",
23
+ "@peachy/types": "^0.0.0-girgen.2",
21
24
  "minargs": "^2.1.0",
22
- "rolldown": "1.0.0-beta.60",
25
+ "rolldown": "1.0.0-rc.3",
23
26
  "rollup-plugin-cleandir": "^3.0.0",
24
27
  "ws": "^8.19.0",
25
- "@peachy/plugin-react": "0.0.9",
26
- "@peachy/plugin-runner": "0.0.9"
28
+ "@peachy/plugin-css": "0.0.11",
29
+ "@peachy/plugin-react": "0.0.11",
30
+ "@peachy/plugin-runner": "0.0.11",
31
+ "@peachy/plugin-resources": "0.0.11"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^25.2.1",
35
+ "@types/ws": "^8.18.1",
36
+ "tsdown": "0.20.3",
37
+ "tsx": "^4.21.0"
27
38
  },
28
- "files": [
29
- "dist",
30
- "tsconfig.json"
31
- ],
32
39
  "scripts": {
33
40
  "build": "tsdown"
34
41
  }
package/tsconfig.json CHANGED
@@ -1,20 +1,26 @@
1
1
  {
2
2
  "compilerOptions": {
3
+ "strict": true,
3
4
  "checkJs": true,
4
5
  "esModuleInterop": true,
5
6
  "lib": ["es2024"],
6
7
  "allowSyntheticDefaultImports": true,
7
8
  "target": "ES2020",
8
- "module": "es2022",
9
+ "module": "Preserve",
9
10
  "moduleResolution": "bundler",
10
11
  "noEmit": true,
11
- "skipLibCheck": true,
12
+ "skipLibCheck": true
12
13
  },
13
14
  "include": [
14
15
  // when installed locally
15
16
  "./node_modules/@peachy/types/types/index.d.ts",
17
+ "./node_modules/@peachy/plugin-resources/src/modules.d.ts",
18
+ "./node_modules/@peachy/plugin-css/src/modules.d.ts",
16
19
  // when installed via npm/pnpm
17
20
  "../types/types/index.d.ts",
18
- "${configDir}/src/**/*",
21
+ "../plugin-resources/src/modules.d.ts",
22
+ "../plugin-css/src/modules.d.ts",
23
+ "${configDir}/src/**/*"
19
24
  ],
25
+ "exclude": ["dist", "${configDir}/dist"]
20
26
  }
package/dist/watch.mjs DELETED
@@ -1,15 +0,0 @@
1
- import { getOptions } from "./options.mjs";
2
- import { watch } from "rolldown";
3
-
4
- //#region src/watch.ts
5
- async function watch$1(config) {
6
- const { input, output } = getOptions(config);
7
- watch({
8
- ...input,
9
- output
10
- });
11
- await new Promise(() => {});
12
- }
13
-
14
- //#endregion
15
- export { watch$1 as watch };