myphp-cli 1.28.0 → 1.30.0

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/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # myphp-cli
2
+
3
+ The `myphp` command of [MyPHP](https://github.com/owner888/myphp) for the
4
+ scripts of a project's package.json, and the types of `myphp.config.ts`.
5
+
6
+ MyPHP's command line tool is PHP, part of the framework, which the project
7
+ installs with Composer:
8
+
9
+ ```sh
10
+ composer require owner888/myphp
11
+ npm install -D myphp-cli
12
+ ```
13
+
14
+ ```json
15
+ {
16
+ "scripts": {
17
+ "dev": "myphp dev",
18
+ "build": "myphp build"
19
+ }
20
+ }
21
+ ```
22
+
23
+ `myphp` runs, in this order, `$MYPHP_CLI_BINARY` when it is set; bin/myphp
24
+ of the MyPHP checkout the package is part of (a `file:` dependency, as
25
+ `myphp init -template web` writes it); else
26
+ `vendor/owner888/myphp/bin/myphp` in the current directory or the nearest
27
+ directory above it that has one. It needs PHP 8.3 or later with FFI.
28
+
29
+ `defineConfig` types the configuration of `myphp.config.ts`, which takes
30
+ the place of myphp.json:
31
+
32
+ ```ts
33
+ import { defineConfig } from "myphp-cli";
34
+
35
+ export default defineConfig({
36
+ name: "My App",
37
+ identifier: "com.example.myapp",
38
+ devUrl: "http://localhost:5173",
39
+ });
40
+ ```
package/bin/myphp.js CHANGED
@@ -3,7 +3,13 @@
3
3
  import { spawn } from "node:child_process";
4
4
  import { binaryPath } from "../index.js";
5
5
 
6
- const bin = binaryPath();
6
+ let bin;
7
+ try {
8
+ bin = binaryPath();
9
+ } catch (err) {
10
+ console.error(err.message);
11
+ process.exit(1);
12
+ }
7
13
  const args = process.argv.slice(2);
8
14
 
9
15
  if (typeof process.execve === "function") {
package/index.d.ts CHANGED
@@ -1,8 +1,11 @@
1
1
  /**
2
2
  * Returns the path of the myphp command to run: $MYPHP_CLI_BINARY when
3
- * set, else bin/myphp of the MyPHP checkout this package is in.
3
+ * set; bin/myphp of the MyPHP checkout this package is part of; else
4
+ * vendor/owner888/myphp/bin/myphp, which Composer installs, in `cwd` (by
5
+ * default the current directory) or the nearest directory above it that
6
+ * has one. Throws when there is none.
4
7
  */
5
- export declare function binaryPath(): string;
8
+ export declare function binaryPath(cwd?: string): string;
6
9
 
7
10
  /**
8
11
  * Types the configuration of myphp.config.ts, which takes the place of
package/index.js CHANGED
@@ -1,17 +1,39 @@
1
- // myphp-cli runs the myphp command line tool, bin/myphp of the MyPHP
2
- // checkout it is part of, from the scripts of a project's package.json,
3
- // and types myphp.config.ts (mygo-cli's index.js, whose binaries are Go's).
1
+ // myphp-cli runs the myphp command line tool, bin/myphp of MyPHP, from the
2
+ // scripts of a project's package.json, and types myphp.config.ts
3
+ // (mygo-cli's index.js, whose binaries are Go's). MyPHP's CLI is PHP, part
4
+ // of the framework: the project's Composer installs it, as
5
+ // vendor/owner888/myphp, or the package is part of a MyPHP checkout
6
+ // (a file: dependency, as `myphp init -template web` writes it).
7
+ import { existsSync } from "node:fs";
4
8
  import { dirname, join } from "node:path";
5
9
  import { fileURLToPath } from "node:url";
6
10
 
7
11
  const here = dirname(fileURLToPath(import.meta.url));
8
12
 
13
+ /** Whether $dir is a MyPHP checkout: its CLI and its sources. */
14
+ function isCheckout(dir) {
15
+ return existsSync(join(dir, "bin", "myphp")) && existsSync(join(dir, "src", "App.php"));
16
+ }
17
+
9
18
  /**
10
19
  * Returns the path of the myphp command to run: $MYPHP_CLI_BINARY when
11
- * set, else bin/myphp of the checkout this package is in.
20
+ * set; bin/myphp of the MyPHP checkout this package is part of; else
21
+ * vendor/owner888/myphp/bin/myphp, which Composer installs, in $cwd or the
22
+ * nearest directory above it that has one.
12
23
  */
13
- export function binaryPath() {
14
- return process.env.MYPHP_CLI_BINARY || join(here, "..", "..", "bin", "myphp");
24
+ export function binaryPath(cwd = process.cwd()) {
25
+ if (process.env.MYPHP_CLI_BINARY) return process.env.MYPHP_CLI_BINARY;
26
+ const checkout = join(here, "..", "..");
27
+ if (isCheckout(checkout)) return join(checkout, "bin", "myphp");
28
+ for (let dir = cwd; ; dir = dirname(dir)) {
29
+ const bin = join(dir, "vendor", "owner888", "myphp", "bin", "myphp");
30
+ if (existsSync(bin)) return bin;
31
+ if (dirname(dir) === dir) break;
32
+ }
33
+ throw new Error(
34
+ `myphp-cli: MyPHP is not installed in ${cwd} or above it: install it with Composer, ` +
35
+ "composer require owner888/myphp, or set MYPHP_CLI_BINARY to its bin/myphp",
36
+ );
15
37
  }
16
38
 
17
39
  /**
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "myphp-cli",
3
- "version": "1.28.0",
3
+ "version": "1.30.0",
4
4
  "description": "The myphp command line tool: create, develop and package MyPHP desktop apps",
5
5
  "keywords": ["myphp", "desktop", "webview", "php", "cli"],
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/owner888/myphp.git",
9
+ "directory": "packages/cli"
10
+ },
6
11
  "license": "MIT",
7
12
  "type": "module",
8
13
  "bin": {