myphp-cli 0.0.0-stage → 1.29.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 +39 -2
- package/bin/myphp.js +37 -0
- package/index.d.ts +205 -0
- package/index.js +45 -0
- package/package.json +28 -4
package/README.md
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
-
#
|
|
1
|
+
# myphp-cli
|
|
2
2
|
|
|
3
|
-
|
|
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
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Runs the myphp command of the MyPHP checkout with the arguments of this script.
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { binaryPath } from "../index.js";
|
|
5
|
+
|
|
6
|
+
let bin;
|
|
7
|
+
try {
|
|
8
|
+
bin = binaryPath();
|
|
9
|
+
} catch (err) {
|
|
10
|
+
console.error(err.message);
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
const args = process.argv.slice(2);
|
|
14
|
+
|
|
15
|
+
if (typeof process.execve === "function") {
|
|
16
|
+
// Become the command (Node.js 23.11 and later, Bun), so that signals and
|
|
17
|
+
// the exit status are its own.
|
|
18
|
+
process.execve(bin, [bin, ...args]);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const child = spawn(bin, args, { stdio: "inherit" });
|
|
22
|
+
// Ctrl+C reaches the command from the terminal too: let it decide when to
|
|
23
|
+
// exit, which myphp dev takes a moment for.
|
|
24
|
+
process.on("SIGINT", () => {});
|
|
25
|
+
process.on("SIGTERM", () => child.kill("SIGTERM"));
|
|
26
|
+
child.on("error", (err) => {
|
|
27
|
+
console.error(`myphp-cli: cannot run ${bin}: ${err.message}`);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
});
|
|
30
|
+
child.on("exit", (code, signal) => {
|
|
31
|
+
if (signal) {
|
|
32
|
+
process.removeAllListeners(signal);
|
|
33
|
+
process.kill(process.pid, signal);
|
|
34
|
+
} else {
|
|
35
|
+
process.exit(code ?? 1);
|
|
36
|
+
}
|
|
37
|
+
});
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the path of the myphp command to run: $MYPHP_CLI_BINARY when
|
|
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.
|
|
7
|
+
*/
|
|
8
|
+
export declare function binaryPath(cwd?: string): string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Types the configuration of myphp.config.ts, which takes the place of
|
|
12
|
+
* myphp.json:
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { defineConfig } from "myphp-cli";
|
|
16
|
+
*
|
|
17
|
+
* export default defineConfig({
|
|
18
|
+
* name: "My App",
|
|
19
|
+
* identifier: "com.example.myapp",
|
|
20
|
+
* devUrl: "http://localhost:5173",
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* A function gets the command running and returns the configuration, or a
|
|
25
|
+
* promise of it.
|
|
26
|
+
*/
|
|
27
|
+
export declare function defineConfig(config: Config): Config;
|
|
28
|
+
export declare function defineConfig(config: Promise<Config>): Promise<Config>;
|
|
29
|
+
export declare function defineConfig(config: ConfigFn): ConfigFn;
|
|
30
|
+
|
|
31
|
+
/** A configuration computed for the command running. */
|
|
32
|
+
export type ConfigFn = (env: ConfigEnv) => Config | Promise<Config>;
|
|
33
|
+
|
|
34
|
+
/** What a configuration function gets. */
|
|
35
|
+
export interface ConfigEnv {
|
|
36
|
+
/** The myphp command running. */
|
|
37
|
+
command: "dev" | "build" | "generate" | "init" | "i18n" | "install-skills";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The configuration of a MyPHP project. Every field is optional. */
|
|
41
|
+
export interface Config {
|
|
42
|
+
/** The name users see: the app, its executable, menus and disk image (default: the directory's name). */
|
|
43
|
+
name?: string;
|
|
44
|
+
/**
|
|
45
|
+
* A reverse DNS name unique to the app, such as `com.example.myapp`, on
|
|
46
|
+
* which macOS keys preferences, permissions and registrations (default:
|
|
47
|
+
* `com.myphp.` and the name's letters and digits).
|
|
48
|
+
*/
|
|
49
|
+
identifier?: string;
|
|
50
|
+
/** The version of the app, which updates compare (default: `0.1.0`). */
|
|
51
|
+
version?: string;
|
|
52
|
+
/** The copyright notice of the app. */
|
|
53
|
+
copyright?: string;
|
|
54
|
+
/** A square PNG, ideally 1024×1024 (default: `resources/icon.png` when it exists). */
|
|
55
|
+
icon?: string;
|
|
56
|
+
/** The PHP file the app runs, relative to the project (default: `app.php`). */
|
|
57
|
+
entry?: string;
|
|
58
|
+
/** The MyPHP checkout the project runs on, which built apps carry. */
|
|
59
|
+
framework?: string;
|
|
60
|
+
/** Where `myphp build` writes the builds, one directory per platform (default: `dist`). */
|
|
61
|
+
out?: string;
|
|
62
|
+
/** Where `myphp generate` writes the TypeScript client (an app without one, as of native UI, gets none). */
|
|
63
|
+
bindings?: string;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The dev server `myphp dev` points the app at, such as
|
|
67
|
+
* `http://localhost:5173`: windows load it for URLs without a scheme.
|
|
68
|
+
*/
|
|
69
|
+
devUrl?: string;
|
|
70
|
+
/** Runs in the project while `myphp dev` runs, e.g. the dev server; the app starts once `devUrl` answers. */
|
|
71
|
+
devCommand?: string;
|
|
72
|
+
/** Builds the frontend before `myphp build` packages the app. */
|
|
73
|
+
buildCommand?: string;
|
|
74
|
+
/**
|
|
75
|
+
* The directory of the built frontend, which `myphp build` puts in the
|
|
76
|
+
* app; `myphp dev` serves it from disk without `devUrl`.
|
|
77
|
+
*/
|
|
78
|
+
frontendDist?: string;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Files and directories copied into the app under their base names, next
|
|
82
|
+
* to the contents of the project's resources directory, whose directories
|
|
83
|
+
* named after a platform, such as `resources/darwin-arm64`, hold the files
|
|
84
|
+
* of one platform.
|
|
85
|
+
*/
|
|
86
|
+
resources?: string[];
|
|
87
|
+
/** The URL schemes the app opens, such as `myapp` for `myapp://…`, which reach `App::onOpenURL`. */
|
|
88
|
+
urlSchemes?: string[];
|
|
89
|
+
/** The types of files the app opens, which reach `App::onOpenFile`. */
|
|
90
|
+
fileAssociations?: FileAssociation[];
|
|
91
|
+
/**
|
|
92
|
+
* The catalogs of the app's messages, which make the languages it ships.
|
|
93
|
+
* Without it, the app ships English only.
|
|
94
|
+
*/
|
|
95
|
+
i18n?: I18nConfig;
|
|
96
|
+
/** Signed updates, which `MyPHP\Updater` installs. */
|
|
97
|
+
updates?: UpdatesConfig;
|
|
98
|
+
/** macOS packaging. */
|
|
99
|
+
macos?: MacOSConfig;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The catalogs of the app's messages: a JSON file per language in `dir`,
|
|
104
|
+
* named after its BCP 47 tag (`de.json`, `zh-Hant.json`), whose messages
|
|
105
|
+
* `myphp generate` writes typed PHP and TypeScript functions for.
|
|
106
|
+
*/
|
|
107
|
+
export interface I18nConfig {
|
|
108
|
+
/** The directory of the catalogs (default `locales`). */
|
|
109
|
+
dir?: string;
|
|
110
|
+
/** The language the app is written in, which the others fall back to (default `en`). */
|
|
111
|
+
source?: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** A type of file the app opens. */
|
|
115
|
+
export interface FileAssociation {
|
|
116
|
+
/** The file name extensions, without dots, e.g. `["md"]`. */
|
|
117
|
+
ext: string[];
|
|
118
|
+
/** What the files are, e.g. `"Markdown Document"`. */
|
|
119
|
+
name?: string;
|
|
120
|
+
/** The MIME type of the files. */
|
|
121
|
+
mimeType?: string;
|
|
122
|
+
/** The app's role for the files (default: `"Editor"`). */
|
|
123
|
+
role?: "Editor" | "Viewer";
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Signed updates: `publicKey` and one of `github` and `url` are required. */
|
|
127
|
+
export interface UpdatesConfig {
|
|
128
|
+
/** The contents of myphp-update.pub, from `myphp keygen`. */
|
|
129
|
+
publicKey: string;
|
|
130
|
+
/** A public GitHub repository, `owner/name`, whose releases hold the updates. */
|
|
131
|
+
github?: string;
|
|
132
|
+
/**
|
|
133
|
+
* What precedes the version in release tags (default: `v`). Another prefix,
|
|
134
|
+
* such as `desktop-v`, lets the repository hold other releases: apps find
|
|
135
|
+
* the newest release tagged with it through the GitHub API instead of
|
|
136
|
+
* reading the latest release.
|
|
137
|
+
*/
|
|
138
|
+
tagPrefix?: string;
|
|
139
|
+
/** Instead of `github`, the HTTPS URL of a directory holding the updates. */
|
|
140
|
+
url?: string;
|
|
141
|
+
/** The bucket that serves `url`, which `myphp build -upload` uploads to. */
|
|
142
|
+
s3?: S3Config;
|
|
143
|
+
/** The path of myphp-update.key; `MYPHP_UPDATER_PRIVATE_KEY`, holding the key, takes precedence. */
|
|
144
|
+
privateKey?: string;
|
|
145
|
+
/** A Markdown file whose `## <version>` section becomes the release notes (default: `CHANGELOG.md` when it exists). */
|
|
146
|
+
changelog?: string;
|
|
147
|
+
/** How many earlier versions get a delta update, a smaller download of what changed (default: `3`; `0` for none). */
|
|
148
|
+
deltas?: number;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* A bucket of Amazon S3, or of a compatible service such as Cloudflare R2.
|
|
153
|
+
* The credentials come from `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and
|
|
154
|
+
* `AWS_SESSION_TOKEN`.
|
|
155
|
+
*/
|
|
156
|
+
export interface S3Config {
|
|
157
|
+
/** The name of the bucket. */
|
|
158
|
+
bucket: string;
|
|
159
|
+
/** The directory of the files in the bucket, e.g. `my-app` (default: its root). */
|
|
160
|
+
prefix?: string;
|
|
161
|
+
/** The region of the bucket (default: `AWS_REGION`, else `AWS_DEFAULT_REGION`, else `us-east-1`). */
|
|
162
|
+
region?: string;
|
|
163
|
+
/** The endpoint of a compatible service, e.g. `https://<account>.r2.cloudflarestorage.com` (default: Amazon S3's). */
|
|
164
|
+
endpoint?: string;
|
|
165
|
+
/** Names the bucket in the path of URLs rather than in the host name (default: with `endpoint`, or a bucket name with dots). */
|
|
166
|
+
pathStyle?: boolean;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** macOS packaging. */
|
|
170
|
+
export interface MacOSConfig {
|
|
171
|
+
/**
|
|
172
|
+
* The icon as an asset catalog: an `Assets.car` compiled with actool (its
|
|
173
|
+
* app icon named `AppIcon`, unless `infoPlist` sets `CFBundleIconName`), or
|
|
174
|
+
* an Icon Composer `.icon`, which builds compile with Xcode 26 or later.
|
|
175
|
+
* The `.icns` made from `icon` remains the fallback.
|
|
176
|
+
*/
|
|
177
|
+
icon?: string;
|
|
178
|
+
/** The oldest macOS the app runs on (default: `12.0`). */
|
|
179
|
+
minimumSystemVersion?: string;
|
|
180
|
+
/** The identity that signs the app and its disk image, e.g. `Developer ID Application: Jane Doe (TEAMID)` (default: `-`, ad hoc). */
|
|
181
|
+
signingIdentity?: string;
|
|
182
|
+
/** A property list of entitlements to sign the app with. */
|
|
183
|
+
entitlements?: string;
|
|
184
|
+
/**
|
|
185
|
+
* Property lists of entitlements for code among the resources, by its path
|
|
186
|
+
* there, e.g. `{ "bin/server": "server.entitlements.plist" }` for a helper
|
|
187
|
+
* that needs `com.apple.security.cs.allow-jit` under the hardened runtime.
|
|
188
|
+
* Other code keeps the entitlements it is signed with.
|
|
189
|
+
*/
|
|
190
|
+
helperEntitlements?: Record<string, string>;
|
|
191
|
+
/** Keys added to the app's Info.plist, replacing MyPHP's, e.g. `NSCameraUsageDescription`. */
|
|
192
|
+
infoPlist?: Record<string, unknown>;
|
|
193
|
+
/** The volume name of the disk image (default: the name). */
|
|
194
|
+
dmgTitle?: string;
|
|
195
|
+
/** Notarizes production disk images. */
|
|
196
|
+
notarize?: NotarizeConfig;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Credentials of `xcrun notarytool store-credentials <profile>`. */
|
|
200
|
+
export interface NotarizeConfig {
|
|
201
|
+
/** The profile holding the credentials. */
|
|
202
|
+
keychainProfile: string;
|
|
203
|
+
/** The keychain holding the profile (default: the login keychain). */
|
|
204
|
+
keychain?: string;
|
|
205
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
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";
|
|
8
|
+
import { dirname, join } from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
|
|
11
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
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
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Returns the path of the myphp command to run: $MYPHP_CLI_BINARY when
|
|
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.
|
|
23
|
+
*/
|
|
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
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Types the configuration of myphp.config.ts: an object, or a function of
|
|
41
|
+
* the command running that returns one.
|
|
42
|
+
*/
|
|
43
|
+
export function defineConfig(config) {
|
|
44
|
+
return config;
|
|
45
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "myphp-cli",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.29.0",
|
|
4
|
+
"description": "The myphp command line tool: create, develop and package MyPHP desktop apps",
|
|
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
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"bin": {
|
|
14
|
+
"myphp": "bin/myphp.js"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./index.d.ts",
|
|
19
|
+
"default": "./index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"types": "./index.d.ts",
|
|
23
|
+
"files": ["bin", "index.js", "index.d.ts", "README.md"],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "bun test"
|
|
29
|
+
}
|
|
30
|
+
}
|