@morkaai/runtime 0.0.0-stage → 0.2.1
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/LICENSE +21 -0
- package/README.md +13 -2
- package/bin/morka.cjs +57 -0
- package/dist/agent-actions/access.js +44 -0
- package/dist/agent-actions/manifest.js +52 -0
- package/dist/agent-actions/runner.js +69 -0
- package/dist/agents/account.js +42 -0
- package/dist/agents/acp-sandbox.js +118 -0
- package/dist/agents/activity.js +26 -0
- package/dist/agents/attachments.js +129 -0
- package/dist/agents/context.js +76 -0
- package/dist/agents/contracts.js +2 -0
- package/dist/agents/process.js +61 -0
- package/dist/agents/providers/acp.js +411 -0
- package/dist/agents/providers/claude.js +180 -0
- package/dist/agents/providers/codex.js +416 -0
- package/dist/agents/registry.js +76 -0
- package/dist/agents/sessions.js +331 -0
- package/dist/app-runtime/bridge.js +40 -0
- package/dist/app-runtime/starter/agents.json +1 -0
- package/dist/app-runtime/starter/index.html +11 -0
- package/dist/app-runtime/starter/main.js +0 -0
- package/dist/app-runtime/starter/package-lock.json +13 -0
- package/dist/app-runtime/starter/package.json +9 -0
- package/dist/app-runtime/starter/server.mjs +20 -0
- package/dist/app-runtime/starter/styles.css +0 -0
- package/dist/app-runtime/text-file.js +18 -0
- package/dist/branding/Morka.icns +0 -0
- package/dist/branding/README.md +24 -0
- package/dist/branding/generated-app-icon.png +0 -0
- package/dist/branding/morka-icon.png +0 -0
- package/dist/branding/morka-logo.png +0 -0
- package/dist/electron/main.js +802 -0
- package/dist/electron/preload.js +51 -0
- package/dist/instances/desktop.js +223 -0
- package/dist/instances/distribution.js +240 -0
- package/dist/instances/macos.js +62 -0
- package/dist/instances/repository.js +183 -0
- package/dist/instances/shadow-repository.js +95 -0
- package/dist/project/app-proxy.js +325 -0
- package/dist/project/bundle-toolchain.js +35 -0
- package/dist/project/drafts.js +27 -0
- package/dist/project/files.js +176 -0
- package/dist/project/live-preview.js +198 -0
- package/dist/project/managed-runtime.js +324 -0
- package/dist/project/node-lifecycle.js +45 -0
- package/dist/project/packages.js +302 -0
- package/dist/project/page-state.js +198 -0
- package/dist/project/project.js +112 -0
- package/dist/project/shadow-effects.js +156 -0
- package/dist/project/shadows.js +122 -0
- package/dist/project/toolchain.js +216 -0
- package/dist/renderer/activity.js +91 -0
- package/dist/renderer/app-setup.js +126 -0
- package/dist/renderer/chat-tools.css +83 -0
- package/dist/renderer/highlight.css +118 -0
- package/dist/renderer/icons/attach.png +0 -0
- package/dist/renderer/icons/brain-weight.png +0 -0
- package/dist/renderer/icons/brain.png +0 -0
- package/dist/renderer/icons/chat.png +0 -0
- package/dist/renderer/icons/chevron.png +0 -0
- package/dist/renderer/icons/clone.png +0 -0
- package/dist/renderer/icons/close.png +0 -0
- package/dist/renderer/icons/document.png +0 -0
- package/dist/renderer/icons/edit.png +0 -0
- package/dist/renderer/icons/folder.png +0 -0
- package/dist/renderer/icons/import.png +0 -0
- package/dist/renderer/icons/open-folder.png +0 -0
- package/dist/renderer/icons/play.png +0 -0
- package/dist/renderer/icons/plus.png +0 -0
- package/dist/renderer/icons/remove.png +0 -0
- package/dist/renderer/icons/search.png +0 -0
- package/dist/renderer/icons/send.png +0 -0
- package/dist/renderer/icons/shadow.png +0 -0
- package/dist/renderer/icons/stop.png +0 -0
- package/dist/renderer/icons/terminal.png +0 -0
- package/dist/renderer/index.html +130 -0
- package/dist/renderer/launcher/OFL.txt +93 -0
- package/dist/renderer/launcher/cell.js +322 -0
- package/dist/renderer/launcher/launcher.css +79 -0
- package/dist/renderer/launcher/lexend-caption-bold.ttf +0 -0
- package/dist/renderer/launcher.html +23 -0
- package/dist/renderer/licenses/dompurify.txt +202 -0
- package/dist/renderer/licenses/github-slugger.txt +5 -0
- package/dist/renderer/licenses/highlight.js.txt +29 -0
- package/dist/renderer/licenses/marked-footnote.txt +21 -0
- package/dist/renderer/licenses/marked-gfm-heading-id.txt +21 -0
- package/dist/renderer/licenses/marked.txt +44 -0
- package/dist/renderer/markdown.css +43 -0
- package/dist/renderer/markdown.js +74 -0
- package/dist/renderer/renderer.js +18902 -0
- package/dist/renderer/styles.css +351 -0
- package/dist/skills/morka-agent-action/SKILL.md +39 -0
- package/dist/skills/morka-app/SKILL.md +36 -0
- package/dist/skills/morka-shadow-authoring/SKILL.md +32 -0
- package/package.json +30 -4
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const electron_1 = require("electron");
|
|
4
|
+
if (process.isMainFrame) {
|
|
5
|
+
electron_1.contextBridge.exposeInMainWorld("lab", {
|
|
6
|
+
currentApp: () => electron_1.ipcRenderer.invoke("instance:current"),
|
|
7
|
+
installApp: (name) => electron_1.ipcRenderer.invoke("instance:install", name),
|
|
8
|
+
openProject: () => electron_1.ipcRenderer.invoke("instance:open"),
|
|
9
|
+
getPreview: () => electron_1.ipcRenderer.invoke("canvas:current"),
|
|
10
|
+
onPreview: (listener) => {
|
|
11
|
+
electron_1.ipcRenderer.on("canvas:update", (_event, url) => listener(url));
|
|
12
|
+
},
|
|
13
|
+
onPreviewUpdating: (listener) => {
|
|
14
|
+
electron_1.ipcRenderer.on("canvas:updating", (_event, updating) => listener(updating));
|
|
15
|
+
},
|
|
16
|
+
runtimeState: () => electron_1.ipcRenderer.invoke("runtime:state"),
|
|
17
|
+
retryRuntime: () => electron_1.ipcRenderer.invoke("runtime:retry"),
|
|
18
|
+
onRuntimeState: (listener) => {
|
|
19
|
+
electron_1.ipcRenderer.on("runtime:state", (_event, state) => listener(state));
|
|
20
|
+
},
|
|
21
|
+
importShadow: () => electron_1.ipcRenderer.invoke("shadow:import"),
|
|
22
|
+
installedShadows: () => electron_1.ipcRenderer.invoke("shadow:list"),
|
|
23
|
+
removeShadow: (id) => electron_1.ipcRenderer.invoke("shadow:remove", id),
|
|
24
|
+
newShadow: (name) => electron_1.ipcRenderer.invoke("shadow:new", name),
|
|
25
|
+
openShadow: () => electron_1.ipcRenderer.invoke("shadow:open"),
|
|
26
|
+
onShadowsChanged: (listener) => electron_1.ipcRenderer.on("shadow:changed", () => listener()),
|
|
27
|
+
chatTarget: () => electron_1.ipcRenderer.invoke("chat:target"),
|
|
28
|
+
listChats: () => electron_1.ipcRenderer.invoke("chat:list"),
|
|
29
|
+
newChat: () => electron_1.ipcRenderer.invoke("chat:new"),
|
|
30
|
+
openChat: (id) => electron_1.ipcRenderer.invoke("chat:open", id),
|
|
31
|
+
openLink: (url) => electron_1.ipcRenderer.invoke("chat:open-link", url),
|
|
32
|
+
attach: (kind) => electron_1.ipcRenderer.invoke("chat:attach", kind),
|
|
33
|
+
attachDropped: (files) => electron_1.ipcRenderer.invoke("chat:attach-paths", files.map(file => electron_1.webUtils.getPathForFile(file))),
|
|
34
|
+
revealAttachment: (id) => electron_1.ipcRenderer.invoke("chat:attachment-reveal", id),
|
|
35
|
+
providers: () => electron_1.ipcRenderer.invoke("chat:providers"),
|
|
36
|
+
agentSetup: () => electron_1.ipcRenderer.invoke("agent:setup"),
|
|
37
|
+
clearAgentAccess: () => electron_1.ipcRenderer.invoke("agent:clear-access"),
|
|
38
|
+
agentOptions: (providerId) => electron_1.ipcRenderer.invoke("chat:agent-options", providerId),
|
|
39
|
+
models: async (providerId) => (await electron_1.ipcRenderer.invoke("chat:agent-options", providerId)).models,
|
|
40
|
+
send: (id, message, model, shadow, selection, attachments) => electron_1.ipcRenderer.invoke("chat:send", id, message, model, shadow, selection, attachments),
|
|
41
|
+
stop: (id) => electron_1.ipcRenderer.invoke("chat:stop", id),
|
|
42
|
+
onChatEvent: (listener) => {
|
|
43
|
+
electron_1.ipcRenderer.on("chat:event", (_event, data) => listener(data));
|
|
44
|
+
},
|
|
45
|
+
getAgentActivity: () => electron_1.ipcRenderer.invoke("agent:activity"),
|
|
46
|
+
onAgentActivity: (listener) => {
|
|
47
|
+
electron_1.ipcRenderer.on("agent:activity", (_event, active) => listener(active));
|
|
48
|
+
},
|
|
49
|
+
invokeAddon: (url, request) => electron_1.ipcRenderer.invoke("addon:invoke", url, request),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installDesktopApp = installDesktopApp;
|
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
const promises_1 = require("node:fs/promises");
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
|
+
const node_util_1 = require("node:util");
|
|
9
|
+
const electron_1 = require("electron");
|
|
10
|
+
const original_fs_1 = require("original-fs");
|
|
11
|
+
const text_file_1 = require("../app-runtime/text-file");
|
|
12
|
+
const files_1 = require("../project/files");
|
|
13
|
+
const distribution_1 = require("./distribution");
|
|
14
|
+
const macos_1 = require("./macos");
|
|
15
|
+
const repository_1 = require("./repository");
|
|
16
|
+
const launchFile = "morka-launch.json";
|
|
17
|
+
const bootstrap = `
|
|
18
|
+
const { join } = require("node:path");
|
|
19
|
+
const launch = require("./${launchFile}");
|
|
20
|
+
const toolchain = join(__dirname, "toolchain");
|
|
21
|
+
const engine = join(launch.repository, "node_modules", "@morka", "runtime");
|
|
22
|
+
process.env.MORKA_NPM_REPOSITORY = launch.repository;
|
|
23
|
+
process.env.MORKA_NPM_KIT = join(launch.repository, ".morka", "npm");
|
|
24
|
+
process.env.MORKA_LOCAL_NODE = launch.bundledNode ? join(toolchain, "bin", "node") : launch.node;
|
|
25
|
+
process.env.MORKA_LOCAL_NPM = launch.bundledNode ? join(toolchain, "npm", "bin", "npm-cli.js") : launch.npm;
|
|
26
|
+
process.env.MORKA_DESKTOP_TOOLCHAIN = launch.bundledNode ? toolchain : "";
|
|
27
|
+
delete process.env.MORKA_INSTALL_APP;
|
|
28
|
+
delete process.env.MORKA_INSTALL_TOOLCHAIN;
|
|
29
|
+
try {
|
|
30
|
+
require(join(engine, "dist", "electron", "main.js"));
|
|
31
|
+
} catch (error) {
|
|
32
|
+
const { app, dialog } = require("electron");
|
|
33
|
+
dialog.showErrorBox(app.name, "The project runtime could not be opened. Run npm run install:app in " + launch.repository);
|
|
34
|
+
app.exit(1);
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
async function writeBootstrap(directory, name, config) {
|
|
38
|
+
await (0, promises_1.mkdir)(directory, { recursive: true, mode: 0o700 });
|
|
39
|
+
await Promise.all([
|
|
40
|
+
(0, text_file_1.writeTextAtomically)((0, node_path_1.join)(directory, "package.json"), JSON.stringify({ name: "morka-project", productName: name, main: "main.cjs" })),
|
|
41
|
+
(0, text_file_1.writeTextAtomically)((0, node_path_1.join)(directory, launchFile), JSON.stringify(config)),
|
|
42
|
+
(0, text_file_1.writeTextAtomically)((0, node_path_1.join)(directory, "main.cjs"), bootstrap),
|
|
43
|
+
]);
|
|
44
|
+
}
|
|
45
|
+
async function requireClosed(library, profile) {
|
|
46
|
+
const lock = await (0, promises_1.readlink)((0, node_path_1.join)(library, "instances", profile, "SingletonLock")).catch(() => "");
|
|
47
|
+
const pid = Number(/-(\d+)$/.exec(lock)?.[1]);
|
|
48
|
+
if (!pid)
|
|
49
|
+
return;
|
|
50
|
+
try {
|
|
51
|
+
process.kill(pid, 0);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (error.code === "ESRCH")
|
|
55
|
+
return;
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
throw new Error("Close the project before updating its installed app.");
|
|
59
|
+
}
|
|
60
|
+
async function installMacApp(name, config, library, toolchain) {
|
|
61
|
+
const applications = (0, node_path_1.join)(electron_1.app.getPath("home"), "Applications");
|
|
62
|
+
const bundle = (0, node_path_1.join)(applications, `${name}.app`);
|
|
63
|
+
const binary = (0, node_path_1.join)("Contents", "MacOS", (0, node_path_1.basename)(process.execPath));
|
|
64
|
+
const appResources = (0, node_path_1.join)("Contents", "Resources", "app");
|
|
65
|
+
const existing = await (0, files_1.info)(bundle);
|
|
66
|
+
if (existing) {
|
|
67
|
+
const saved = existing.isDirectory()
|
|
68
|
+
? await (0, promises_1.readFile)((0, node_path_1.join)(bundle, appResources, launchFile), "utf8").then(JSON.parse).catch(() => undefined)
|
|
69
|
+
: undefined;
|
|
70
|
+
if (saved?.profile !== config.profile || saved.repository !== config.repository) {
|
|
71
|
+
throw new Error(`An app named “${name}” already exists in Applications.`);
|
|
72
|
+
}
|
|
73
|
+
if (JSON.stringify(saved) === JSON.stringify(config) && (await (0, files_1.info)((0, node_path_1.join)(bundle, binary)))?.isFile())
|
|
74
|
+
return bundle;
|
|
75
|
+
await requireClosed(library, config.profile);
|
|
76
|
+
}
|
|
77
|
+
await (0, promises_1.mkdir)(applications, { recursive: true });
|
|
78
|
+
const stage = await (0, promises_1.mkdtemp)((0, node_path_1.join)(applications, ".morka-install-"));
|
|
79
|
+
const replacement = (0, node_path_1.join)(stage, (0, node_path_1.basename)(bundle));
|
|
80
|
+
const backup = (0, node_path_1.join)(stage, "previous.app");
|
|
81
|
+
let keepStage = false;
|
|
82
|
+
try {
|
|
83
|
+
await original_fs_1.promises.cp((0, node_path_1.resolve)(process.execPath, "../../.."), replacement, { recursive: true, verbatimSymlinks: true, mode: node_fs_1.constants.COPYFILE_FICLONE });
|
|
84
|
+
const resources = (0, node_path_1.join)(replacement, "Contents", "Resources");
|
|
85
|
+
await original_fs_1.promises.rm((0, node_path_1.join)(resources, "default_app.asar"), { force: true });
|
|
86
|
+
await writeBootstrap((0, node_path_1.join)(replacement, appResources), name, config);
|
|
87
|
+
await (0, promises_1.copyFile)((0, repository_1.repositoryFile)(config.repository, "icons", repository_1.appIcon), (0, node_path_1.join)(resources, repository_1.appIcon));
|
|
88
|
+
if (toolchain) {
|
|
89
|
+
await (0, promises_1.cp)(toolchain, (0, node_path_1.join)(replacement, appResources, "toolchain"), { recursive: true, verbatimSymlinks: true, mode: node_fs_1.constants.COPYFILE_FICLONE });
|
|
90
|
+
}
|
|
91
|
+
await (0, distribution_1.setBundleIdentity)((0, node_path_1.join)(replacement, "Contents", "Info.plist"), {
|
|
92
|
+
CFBundleName: name, CFBundleDisplayName: name, CFBundleIconFile: repository_1.appIcon,
|
|
93
|
+
CFBundleIdentifier: `local.morka.project.${config.profile}`,
|
|
94
|
+
});
|
|
95
|
+
await (0, distribution_1.signBundle)(replacement, true);
|
|
96
|
+
if (existing) {
|
|
97
|
+
await requireClosed(library, config.profile);
|
|
98
|
+
await (0, promises_1.rename)(bundle, backup);
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
await (0, promises_1.rename)(replacement, bundle);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (existing) {
|
|
105
|
+
try {
|
|
106
|
+
await (0, promises_1.rename)(backup, bundle);
|
|
107
|
+
}
|
|
108
|
+
catch (restoreError) {
|
|
109
|
+
keepStage = true;
|
|
110
|
+
throw new AggregateError([error, restoreError], `The previous app is still at ${backup}.`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
return bundle;
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
if (!keepStage)
|
|
119
|
+
await original_fs_1.promises.rm(stage, { recursive: true, force: true });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function iconFile(png) {
|
|
123
|
+
const header = Buffer.alloc(22);
|
|
124
|
+
header.writeUInt16LE(1, 2);
|
|
125
|
+
header.writeUInt16LE(1, 4);
|
|
126
|
+
header.writeUInt16LE(1, 10);
|
|
127
|
+
header.writeUInt16LE(32, 12);
|
|
128
|
+
header.writeUInt32LE(png.length, 14);
|
|
129
|
+
header.writeUInt32LE(header.length, 18);
|
|
130
|
+
return Buffer.concat([header, png]);
|
|
131
|
+
}
|
|
132
|
+
async function writeWindowsShortcut(directory, name, args, cwd, icon) {
|
|
133
|
+
const menu = (0, node_path_1.join)(electron_1.app.getPath("appData"), "Microsoft", "Windows", "Start Menu", "Programs", "Morka");
|
|
134
|
+
const shortcut = (0, node_path_1.join)(menu, `${name}.lnk`);
|
|
135
|
+
await (0, promises_1.mkdir)(menu, { recursive: true });
|
|
136
|
+
const existing = await (0, files_1.info)(shortcut);
|
|
137
|
+
if (existing && (!existing.isFile() || electron_1.shell.readShortcutLink(shortcut).args !== args)) {
|
|
138
|
+
throw new Error(`A shortcut named “${name}” already exists in the Start menu.`);
|
|
139
|
+
}
|
|
140
|
+
const temporary = await (0, promises_1.mkdtemp)((0, node_path_1.join)(directory, ".shortcut-"));
|
|
141
|
+
try {
|
|
142
|
+
const staged = (0, node_path_1.join)(temporary, (0, node_path_1.basename)(shortcut));
|
|
143
|
+
if (!electron_1.shell.writeShortcutLink(staged, { target: process.execPath, args, cwd, icon, iconIndex: 0, description: name })) {
|
|
144
|
+
throw new Error("Could not create the Start menu shortcut.");
|
|
145
|
+
}
|
|
146
|
+
if (existing)
|
|
147
|
+
await (0, promises_1.rename)(staged, shortcut);
|
|
148
|
+
else
|
|
149
|
+
await (0, promises_1.copyFile)(staged, shortcut, node_fs_1.constants.COPYFILE_EXCL);
|
|
150
|
+
return shortcut;
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
await (0, promises_1.rm)(temporary, { recursive: true, force: true });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function desktopValue(value) {
|
|
157
|
+
return value.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
|
|
158
|
+
}
|
|
159
|
+
function desktopArg(value) {
|
|
160
|
+
return `"${value.replace(/["\\$`]/g, "\\$&").replace(/%/g, "%%")}"`;
|
|
161
|
+
}
|
|
162
|
+
function desktopEntry(name, executable, directory, icon) {
|
|
163
|
+
const command = executable.includes("=") ? ["/bin/sh", "-c", 'exec "$@"', "morka", executable, directory]
|
|
164
|
+
: [executable, directory];
|
|
165
|
+
return [
|
|
166
|
+
"[Desktop Entry]", "Type=Application", `Name=${desktopValue(name)}`,
|
|
167
|
+
`Exec=${desktopValue(command.map(desktopArg).join(" "))}`,
|
|
168
|
+
`Icon=${desktopValue(icon)}`, "Terminal=false", "",
|
|
169
|
+
].join("\n");
|
|
170
|
+
}
|
|
171
|
+
async function installDesktopApp(repository, spec, open) {
|
|
172
|
+
const name = (0, repository_1.portableAppName)(spec.name);
|
|
173
|
+
const home = electron_1.app.getPath("home");
|
|
174
|
+
const library = (0, repository_1.appsDirectory)(electron_1.app.getPath("appData"));
|
|
175
|
+
const toolchain = process.platform === "darwin" ? process.env.MORKA_INSTALL_TOOLCHAIN : undefined;
|
|
176
|
+
const node = process.env.MORKA_LOCAL_NODE;
|
|
177
|
+
const npm = process.env.MORKA_LOCAL_NPM;
|
|
178
|
+
if (!node || !npm || !(0, node_path_1.isAbsolute)(node) || !(0, node_path_1.isAbsolute)(npm))
|
|
179
|
+
throw new Error("Node.js and npm are required to install this app.");
|
|
180
|
+
const config = { repository, profile: (0, repository_1.repositoryProfileId)(spec, repository), node, npm,
|
|
181
|
+
electron: process.versions.electron ?? "", bundledNode: Boolean(toolchain),
|
|
182
|
+
toolchainRevision: toolchain ? await (0, promises_1.readFile)((0, node_path_1.join)(toolchain, "toolchain.json"), "utf8") : undefined };
|
|
183
|
+
let entry;
|
|
184
|
+
const executable = process.execPath;
|
|
185
|
+
let args = [];
|
|
186
|
+
if (process.platform === "darwin") {
|
|
187
|
+
entry = await installMacApp(name, config, library, toolchain);
|
|
188
|
+
}
|
|
189
|
+
else if (process.platform === "win32" || process.platform === "linux") {
|
|
190
|
+
const directory = (0, node_path_1.join)(library, "desktop", config.profile);
|
|
191
|
+
await writeBootstrap(directory, name, config);
|
|
192
|
+
const png = (0, macos_1.projectIcon)(spec.iconColor).resize({ width: 256, height: 256 }).toPNG();
|
|
193
|
+
const icon = (0, node_path_1.join)(directory, process.platform === "win32" ? "icon.ico" : "icon.png");
|
|
194
|
+
await (0, promises_1.writeFile)(icon, process.platform === "win32" ? iconFile(png) : png);
|
|
195
|
+
args = [directory];
|
|
196
|
+
if (process.platform === "win32") {
|
|
197
|
+
entry = await writeWindowsShortcut(directory, name, `"${directory}"`, repository, icon);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
const configured = process.env.XDG_DATA_HOME;
|
|
201
|
+
const data = configured && (0, node_path_1.isAbsolute)(configured) ? configured : (0, node_path_1.join)(home, ".local", "share");
|
|
202
|
+
entry = (0, node_path_1.join)(data, "applications", `local.morka.project.${config.profile}.desktop`);
|
|
203
|
+
await (0, text_file_1.writeTextAtomically)(entry, desktopEntry(name, executable, directory, icon));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
throw new Error("App installation is available on macOS, Windows, and Linux.");
|
|
208
|
+
}
|
|
209
|
+
console.log(`Installed app at ${entry}`);
|
|
210
|
+
if (!open)
|
|
211
|
+
return;
|
|
212
|
+
if (process.platform === "darwin") {
|
|
213
|
+
// LaunchServices starts the installed bundle as its own application, as Finder does.
|
|
214
|
+
await (0, node_util_1.promisify)(node_child_process_1.execFile)("/usr/bin/open", [entry]);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const child = (0, node_child_process_1.spawn)(executable, args, { cwd: repository, detached: true, stdio: "ignore", windowsHide: true });
|
|
218
|
+
await new Promise((resolve, reject) => {
|
|
219
|
+
child.once("spawn", resolve);
|
|
220
|
+
child.once("error", reject);
|
|
221
|
+
});
|
|
222
|
+
child.unref();
|
|
223
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setBundleIdentity = setBundleIdentity;
|
|
4
|
+
exports.signBundle = signBundle;
|
|
5
|
+
exports.prepareMacProjectExecutable = prepareMacProjectExecutable;
|
|
6
|
+
exports.signNativeFiles = signNativeFiles;
|
|
7
|
+
exports.buildMacBundle = buildMacBundle;
|
|
8
|
+
exports.buildMacRelease = buildMacRelease;
|
|
9
|
+
const node_child_process_1 = require("node:child_process");
|
|
10
|
+
const node_crypto_1 = require("node:crypto");
|
|
11
|
+
const promises_1 = require("node:fs/promises");
|
|
12
|
+
const node_fs_1 = require("node:fs");
|
|
13
|
+
const node_module_1 = require("node:module");
|
|
14
|
+
const node_path_1 = require("node:path");
|
|
15
|
+
const node_util_1 = require("node:util");
|
|
16
|
+
const files_1 = require("../project/files");
|
|
17
|
+
const bundle_toolchain_1 = require("../project/bundle-toolchain");
|
|
18
|
+
const project_1 = require("../project/project");
|
|
19
|
+
const packages_1 = require("../project/packages");
|
|
20
|
+
const repository_1 = require("./repository");
|
|
21
|
+
const run = (0, node_util_1.promisify)(node_child_process_1.execFile);
|
|
22
|
+
async function copyDependencies(source, target, dependencies, parents = new Set()) {
|
|
23
|
+
const resolve = (0, node_module_1.createRequire)((0, node_path_1.join)(source, "package.json")).resolve;
|
|
24
|
+
for (const dependency of dependencies) {
|
|
25
|
+
const locations = resolve.paths(dependency) ?? [];
|
|
26
|
+
let directory;
|
|
27
|
+
for (const location of locations) {
|
|
28
|
+
const candidate = (0, node_path_1.join)(location, dependency);
|
|
29
|
+
if ((await (0, files_1.info)((0, node_path_1.join)(candidate, "package.json")))?.isFile()) {
|
|
30
|
+
directory = candidate;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (!directory)
|
|
35
|
+
throw new Error(`Install the dependencies first. Missing ${dependency}.`);
|
|
36
|
+
if (parents.has(directory))
|
|
37
|
+
continue;
|
|
38
|
+
const destination = (0, node_path_1.join)(target, "node_modules", dependency);
|
|
39
|
+
const metadata = JSON.parse(await (0, promises_1.readFile)((0, node_path_1.join)(directory, "package.json"), "utf8"));
|
|
40
|
+
await (0, promises_1.cp)(directory, destination, {
|
|
41
|
+
recursive: true, dereference: true,
|
|
42
|
+
filter: path => path !== (0, node_path_1.join)(directory, "node_modules"),
|
|
43
|
+
});
|
|
44
|
+
await copyDependencies(directory, destination, Object.keys(metadata.dependencies ?? {}), new Set([...parents, directory]));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async function setBundleIdentity(plist, values) {
|
|
48
|
+
for (const [key, value] of Object.entries(values)) {
|
|
49
|
+
await run("/usr/bin/plutil", ["-replace", key, "-string", value, plist]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function signBundle(bundle, deep = false) {
|
|
53
|
+
await run("/usr/bin/codesign", [
|
|
54
|
+
"--force", ...(deep ? ["--deep"] : []), "--sign", "-", "--preserve-metadata=entitlements,flags", bundle,
|
|
55
|
+
]);
|
|
56
|
+
await run("/usr/bin/codesign", ["--verify", "--deep", "--strict", bundle]);
|
|
57
|
+
}
|
|
58
|
+
async function prepareMacProjectExecutable(executable, appData, repository, spec) {
|
|
59
|
+
const source = (0, node_path_1.resolve)(executable, "../../..");
|
|
60
|
+
const contents = (0, node_path_1.join)(source, "Contents");
|
|
61
|
+
const [infoPlist, resources] = await Promise.all([
|
|
62
|
+
(0, promises_1.readFile)((0, node_path_1.join)(contents, "Info.plist")),
|
|
63
|
+
(0, promises_1.readFile)((0, node_path_1.join)(contents, "_CodeSignature", "CodeResources")).catch((error) => {
|
|
64
|
+
if (error.code !== "ENOENT")
|
|
65
|
+
throw error;
|
|
66
|
+
return undefined;
|
|
67
|
+
}),
|
|
68
|
+
]);
|
|
69
|
+
const project = (0, node_crypto_1.createHash)("sha256").update(spec.id + "\0" + repository).digest("hex").slice(0, 32);
|
|
70
|
+
const revision = (0, node_crypto_1.createHash)("sha256").update(spec.name + "\0").update(infoPlist).update(resources ?? await (0, promises_1.readFile)(executable))
|
|
71
|
+
.digest("hex").slice(0, 24);
|
|
72
|
+
const directory = (0, node_path_1.join)((0, repository_1.appsDirectory)(appData), "macOS", project, revision);
|
|
73
|
+
const bundleName = `${spec.name}.app`;
|
|
74
|
+
const destination = (0, node_path_1.join)(directory, bundleName);
|
|
75
|
+
const binary = (0, node_path_1.join)("Contents", "MacOS", (0, node_path_1.basename)(executable));
|
|
76
|
+
const result = (0, node_path_1.join)(destination, binary);
|
|
77
|
+
if ((await (0, files_1.info)(result))?.isFile())
|
|
78
|
+
return result;
|
|
79
|
+
await (0, promises_1.mkdir)(directory, { recursive: true, mode: 0o700 });
|
|
80
|
+
const stage = await (0, promises_1.mkdtemp)((0, node_path_1.join)(directory, ".build-"));
|
|
81
|
+
const bundle = (0, node_path_1.join)(stage, bundleName);
|
|
82
|
+
try {
|
|
83
|
+
await (0, promises_1.cp)(source, bundle, { recursive: true, verbatimSymlinks: true, mode: node_fs_1.constants.COPYFILE_FICLONE });
|
|
84
|
+
await setBundleIdentity((0, node_path_1.join)(bundle, "Contents", "Info.plist"), {
|
|
85
|
+
CFBundleName: spec.name,
|
|
86
|
+
CFBundleDisplayName: spec.name,
|
|
87
|
+
CFBundleIdentifier: `local.morka.project.${project}`,
|
|
88
|
+
});
|
|
89
|
+
await signBundle(bundle, !resources);
|
|
90
|
+
try {
|
|
91
|
+
await (0, promises_1.rename)(bundle, destination);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
if (!["EEXIST", "ENOTEMPTY"].includes(error.code ?? "") ||
|
|
95
|
+
!(await (0, files_1.info)(result))?.isFile())
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
await (0, promises_1.rm)(stage, { recursive: true, force: true });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function signNativeFiles(directory) {
|
|
105
|
+
for (const entry of await (0, promises_1.readdir)(directory, { withFileTypes: true })) {
|
|
106
|
+
const path = (0, node_path_1.join)(directory, entry.name);
|
|
107
|
+
if (entry.isDirectory())
|
|
108
|
+
await signNativeFiles(path);
|
|
109
|
+
else if (entry.isFile() && (entry.name.endsWith(".node") || entry.name.endsWith(".dylib") || ((await (0, promises_1.stat)(path)).mode & 0o111))) {
|
|
110
|
+
const file = await (0, promises_1.open)(path, "r");
|
|
111
|
+
const header = Buffer.alloc(4);
|
|
112
|
+
try {
|
|
113
|
+
await file.read(header, 0, 4, 0);
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
await file.close();
|
|
117
|
+
}
|
|
118
|
+
if ([0xfeedface, 0xfeedfacf, 0xcefaedfe, 0xcffaedfe, 0xcafebabe, 0xbebafeca].includes(header.readUInt32BE())) {
|
|
119
|
+
await run("/usr/bin/codesign", ["--force", "--sign", "-", "--preserve-metadata=entitlements,flags", path]);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async function keepEnglishLocalizations(directory) {
|
|
125
|
+
const entries = await (0, promises_1.readdir)(directory, { withFileTypes: true });
|
|
126
|
+
await Promise.all(entries
|
|
127
|
+
.filter(entry => entry.isDirectory() && entry.name.endsWith(".lproj") && !/^en(?:_|\.lproj$)/.test(entry.name))
|
|
128
|
+
.map(entry => (0, promises_1.rm)((0, node_path_1.join)(directory, entry.name), { recursive: true })));
|
|
129
|
+
}
|
|
130
|
+
async function buildMacBundle(engine, bundle, kit, release, releaseVersion, toolchain = (0, node_path_1.join)(engine, "dist", "toolchain")) {
|
|
131
|
+
if (process.platform !== "darwin")
|
|
132
|
+
throw new Error("This release currently supports building on macOS.");
|
|
133
|
+
const spec = release?.spec;
|
|
134
|
+
const project = release && await (0, files_1.snapshot)(await (0, repository_1.repositoryProject)(release.repository));
|
|
135
|
+
if (project)
|
|
136
|
+
await (0, project_1.compileProject)(project);
|
|
137
|
+
const metadata = JSON.parse(await (0, promises_1.readFile)((0, node_path_1.join)(engine, "package.json"), "utf8"));
|
|
138
|
+
const local = (0, node_module_1.createRequire)((0, node_path_1.join)(engine, "package.json"));
|
|
139
|
+
const electron = (0, node_path_1.join)(local("electron"), "../../..");
|
|
140
|
+
const contents = (0, node_path_1.join)(bundle, "Contents");
|
|
141
|
+
const resources = (0, node_path_1.join)(contents, "Resources");
|
|
142
|
+
const app = (0, node_path_1.join)(resources, "app");
|
|
143
|
+
const name = spec?.name ?? "Morka";
|
|
144
|
+
await run("/usr/bin/ditto", [electron, bundle]);
|
|
145
|
+
await Promise.all([
|
|
146
|
+
keepEnglishLocalizations(resources),
|
|
147
|
+
keepEnglishLocalizations((0, node_path_1.join)(contents, "Frameworks", "Electron Framework.framework", "Resources")),
|
|
148
|
+
]);
|
|
149
|
+
await (0, promises_1.mkdir)(app);
|
|
150
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(app, "package.json"), (0, project_1.jsonFile)({
|
|
151
|
+
name: "morka",
|
|
152
|
+
productName: name,
|
|
153
|
+
version: metadata.version,
|
|
154
|
+
main: "dist/electron/main.js",
|
|
155
|
+
}));
|
|
156
|
+
const dist = (0, node_path_1.join)(engine, "dist");
|
|
157
|
+
await (0, promises_1.cp)(dist, (0, node_path_1.join)(app, "dist"), { recursive: true, filter: path => ![(0, node_path_1.join)(dist, "npm"), (0, node_path_1.join)(dist, "toolchain")].includes(path) });
|
|
158
|
+
await (0, promises_1.cp)(toolchain, (0, node_path_1.join)(app, "dist", "toolchain"), { recursive: true });
|
|
159
|
+
await copyDependencies(engine, app, Object.keys(metadata.dependencies ?? {}).filter(name => name !== "electron"));
|
|
160
|
+
await (0, promises_1.cp)(kit, (0, node_path_1.join)(resources, repository_1.bundledKit), { recursive: true });
|
|
161
|
+
await (0, promises_1.rm)((0, node_path_1.join)(resources, "default_app.asar"), { force: true });
|
|
162
|
+
await (0, promises_1.rename)((0, node_path_1.join)(contents, "MacOS", "Electron"), (0, node_path_1.join)(contents, "MacOS", "Morka"));
|
|
163
|
+
await (0, promises_1.copyFile)((0, node_path_1.join)(dist, "branding", "Morka.icns"), (0, node_path_1.join)(resources, repository_1.appIcon));
|
|
164
|
+
if (release && project) {
|
|
165
|
+
const seed = (0, node_path_1.join)(resources, repository_1.releaseProject);
|
|
166
|
+
await (0, promises_1.mkdir)(seed);
|
|
167
|
+
await (0, files_1.applyFiles)(seed, new Map(), project);
|
|
168
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(resources, repository_1.releaseFile), (0, project_1.jsonFile)(release.spec));
|
|
169
|
+
await (0, promises_1.copyFile)((0, repository_1.repositoryFile)(release.repository, "icons", repository_1.appIcon), (0, node_path_1.join)(resources, repository_1.appIcon));
|
|
170
|
+
const manager = new packages_1.AppPackages(release.packagesHome, toolchain);
|
|
171
|
+
const prepared = await manager.prepare(project);
|
|
172
|
+
const destination = (0, node_path_1.join)(resources, repository_1.preparedRelease);
|
|
173
|
+
await (0, promises_1.cp)((0, node_path_1.dirname)(prepared.directory), destination, { recursive: true, verbatimSymlinks: true, mode: node_fs_1.constants.COPYFILE_FICLONE });
|
|
174
|
+
await (0, packages_1.writableTree)(destination);
|
|
175
|
+
await signNativeFiles((0, node_path_1.join)(destination, "app"));
|
|
176
|
+
if ((await (0, files_1.info)((0, node_path_1.join)(destination, "home")))?.isDirectory())
|
|
177
|
+
await signNativeFiles((0, node_path_1.join)(destination, "home"));
|
|
178
|
+
await (0, packages_1.sealArtifactDirectory)((0, node_path_1.join)(destination, "app"));
|
|
179
|
+
}
|
|
180
|
+
await signNativeFiles((0, node_path_1.join)(app, "dist", "toolchain"));
|
|
181
|
+
await setBundleIdentity((0, node_path_1.join)(contents, "Info.plist"), {
|
|
182
|
+
CFBundleExecutable: "Morka",
|
|
183
|
+
CFBundleName: name,
|
|
184
|
+
CFBundleDisplayName: name,
|
|
185
|
+
CFBundleDevelopmentRegion: "en",
|
|
186
|
+
CFBundleIdentifier: spec ? `local.morka.app.${spec.id}` : "local.morka",
|
|
187
|
+
CFBundleShortVersionString: releaseVersion ?? metadata.version,
|
|
188
|
+
CFBundleVersion: (releaseVersion ?? metadata.version).split("-")[0],
|
|
189
|
+
CFBundleIconFile: repository_1.appIcon,
|
|
190
|
+
});
|
|
191
|
+
await signBundle(bundle, true);
|
|
192
|
+
}
|
|
193
|
+
async function buildMacRelease(engine, repository) {
|
|
194
|
+
if (process.platform !== "darwin")
|
|
195
|
+
throw new Error("Build the macOS package on a Mac.");
|
|
196
|
+
const spec = (0, repository_1.readRelease)((0, repository_1.repositoryFile)(repository, "release.json"));
|
|
197
|
+
const metadata = JSON.parse(await (0, promises_1.readFile)((0, node_path_1.join)(repository, "package.json"), "utf8"));
|
|
198
|
+
const output = (0, node_path_1.join)(repository, "dist");
|
|
199
|
+
const destination = (0, node_path_1.join)(output, `${spec.name}.app`);
|
|
200
|
+
await (0, promises_1.mkdir)(output, { recursive: true });
|
|
201
|
+
const stage = await (0, promises_1.mkdtemp)((0, node_path_1.join)(output, ".morka-build-"));
|
|
202
|
+
const bundle = (0, node_path_1.join)(stage, `${spec.name}.app`);
|
|
203
|
+
const previous = (0, node_path_1.join)(stage, "previous.app");
|
|
204
|
+
let savedPrevious = false;
|
|
205
|
+
let keepStage = false;
|
|
206
|
+
try {
|
|
207
|
+
const toolchain = (0, node_path_1.join)(stage, "toolchain");
|
|
208
|
+
await (0, bundle_toolchain_1.bundleToolchain)(toolchain);
|
|
209
|
+
await buildMacBundle(engine, bundle, (0, repository_1.repositoryFile)(repository, "npm"), { spec, repository, packagesHome: (0, node_path_1.join)(stage, "packages") }, metadata.version, toolchain);
|
|
210
|
+
if (await (0, files_1.info)(destination)) {
|
|
211
|
+
const existing = (0, repository_1.readRelease)((0, node_path_1.join)(destination, "Contents", "Resources", repository_1.releaseFile));
|
|
212
|
+
if (existing.id !== spec.id)
|
|
213
|
+
throw new Error("The build destination belongs to another app.");
|
|
214
|
+
await (0, promises_1.rename)(destination, previous);
|
|
215
|
+
savedPrevious = true;
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
await (0, promises_1.rename)(bundle, destination);
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
if (savedPrevious) {
|
|
222
|
+
try {
|
|
223
|
+
await (0, promises_1.rename)(previous, destination);
|
|
224
|
+
}
|
|
225
|
+
catch (restoreError) {
|
|
226
|
+
keepStage = true;
|
|
227
|
+
throw new AggregateError([error, restoreError], `The previous package is still at ${previous}.`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
return destination;
|
|
233
|
+
}
|
|
234
|
+
finally {
|
|
235
|
+
if (!keepStage) {
|
|
236
|
+
await (0, packages_1.writableTree)(stage);
|
|
237
|
+
await (0, promises_1.rm)(stage, { recursive: true, force: true });
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.projectIcon = projectIcon;
|
|
4
|
+
exports.makeIcon = makeIcon;
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const electron_1 = require("electron");
|
|
7
|
+
const iconColors = [
|
|
8
|
+
[84, 2, 198], // Violet
|
|
9
|
+
[42, 87, 196], // Cobalt
|
|
10
|
+
[0, 129, 132], // Teal
|
|
11
|
+
[52, 126, 71], // Fern
|
|
12
|
+
[185, 122, 18], // Amber
|
|
13
|
+
[214, 82, 38], // Persimmon
|
|
14
|
+
[188, 48, 100], // Raspberry
|
|
15
|
+
[65, 88, 117], // Slate
|
|
16
|
+
];
|
|
17
|
+
function iconChunk(type, data) {
|
|
18
|
+
const header = Buffer.alloc(8);
|
|
19
|
+
header.write(type, 0, "ascii");
|
|
20
|
+
header.writeUInt32BE(data.length + header.length, 4);
|
|
21
|
+
return Buffer.concat([header, data]);
|
|
22
|
+
}
|
|
23
|
+
function projectIcon(color) {
|
|
24
|
+
let icon = electron_1.nativeImage.createFromPath((0, node_path_1.join)(__dirname, "../branding/generated-app-icon.png"));
|
|
25
|
+
if (icon.isEmpty())
|
|
26
|
+
throw new Error("The generated app icon is missing.");
|
|
27
|
+
if (color !== 0) {
|
|
28
|
+
const pixels = icon.toBitmap();
|
|
29
|
+
const [red, green, blue] = iconColors[color];
|
|
30
|
+
const [paperRed, paperGreen, paperBlue] = [251, 244, 235];
|
|
31
|
+
// The green channel falls from cream to violet across both the mark and its glow.
|
|
32
|
+
// This coverage includes alpha because NativeImage stores premultiplied BGRA.
|
|
33
|
+
const greenRange = paperGreen - iconColors[0][1];
|
|
34
|
+
for (let i = 0; i < pixels.length; i += 4) {
|
|
35
|
+
const opacity = pixels[i + 3] / 255;
|
|
36
|
+
const coverage = Math.max(0, Math.min(opacity, (paperGreen * opacity - pixels[i + 1]) / greenRange));
|
|
37
|
+
pixels[i] = Math.round(paperBlue * opacity + (blue - paperBlue) * coverage);
|
|
38
|
+
pixels[i + 1] = Math.round(paperGreen * opacity + (green - paperGreen) * coverage);
|
|
39
|
+
pixels[i + 2] = Math.round(paperRed * opacity + (red - paperRed) * coverage);
|
|
40
|
+
}
|
|
41
|
+
icon = electron_1.nativeImage.createFromBitmap(pixels, icon.getSize());
|
|
42
|
+
}
|
|
43
|
+
return icon;
|
|
44
|
+
}
|
|
45
|
+
function makeIcon(color) {
|
|
46
|
+
const icon = projectIcon(color);
|
|
47
|
+
const sizes = [
|
|
48
|
+
["icp4", 16], ["icp5", 32], ["icp6", 64], ["ic07", 128],
|
|
49
|
+
["ic08", 256], ["ic09", 512], ["ic10", 1024],
|
|
50
|
+
["ic11", 32], ["ic12", 64], ["ic13", 256], ["ic14", 512],
|
|
51
|
+
];
|
|
52
|
+
const pngs = new Map();
|
|
53
|
+
const chunks = sizes.map(([type, size]) => {
|
|
54
|
+
let png = pngs.get(size);
|
|
55
|
+
if (!png) {
|
|
56
|
+
png = icon.resize({ width: size, height: size, quality: "best" }).toPNG();
|
|
57
|
+
pngs.set(size, png);
|
|
58
|
+
}
|
|
59
|
+
return iconChunk(type, png);
|
|
60
|
+
});
|
|
61
|
+
return iconChunk("icns", Buffer.concat(chunks));
|
|
62
|
+
}
|