@acryldev/blends 1.7.11 → 1.7.13
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/dist/index.d.ts +16 -4
- package/dist/index.js +79 -17
- package/dist/index.js.map +1 -1
- package/pack/lib/create-source.mjs +24 -0
- package/pack/pack-blank-mac.mjs +698 -0
- package/package.json +3 -2
- package/plugins/desktop-shell/frame.ts +7 -2
- package/plugins/desktop-shell/inherited.ts +26 -0
- package/plugins/desktop-shell/main.ts +19 -1
- package/plugins/desktop-shell/menu.ts +32 -0
- package/plugins/desktop-shell/package.json +1 -1
- package/plugins/plugin-share/package.json +1 -1
- package/plugins/plugin-share/plugin.json +1 -1
- package/plugins/save/package.json +1 -1
- package/plugins/save/plugin.json +2 -4
- package/plugins/save/share.ts +151 -37
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acryldev/blends",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.13",
|
|
4
4
|
"description": "The Acryl web framework (import { Acryl } from \"acrylblends\") and the acrylblends command that scaffolds Cordis apps.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -407,7 +407,8 @@
|
|
|
407
407
|
"templates",
|
|
408
408
|
"shared",
|
|
409
409
|
"plugins",
|
|
410
|
-
"docs"
|
|
410
|
+
"docs",
|
|
411
|
+
"pack"
|
|
411
412
|
],
|
|
412
413
|
"engines": {
|
|
413
414
|
"node": ">=22.19.0"
|
|
@@ -7,8 +7,9 @@ import { type ChildProcess, spawn, spawnSync } from 'node:child_process'
|
|
|
7
7
|
import { existsSync, readFileSync } from 'node:fs'
|
|
8
8
|
import { connect } from 'node:net'
|
|
9
9
|
import { join, resolve } from 'node:path'
|
|
10
|
-
import { fileURLToPath
|
|
10
|
+
import { fileURLToPath } from 'node:url'
|
|
11
11
|
import { appDataHome, PROGRAM_ENV } from '@acryldev/instance'
|
|
12
|
+
import { withoutInheritedDescriptors } from './inherited.ts'
|
|
12
13
|
|
|
13
14
|
/** The launcher every frame app has; without it the app runs on its own server (made before the frame). */
|
|
14
15
|
export const HOST_SCRIPT = join('scripts', 'ide-host.mjs')
|
|
@@ -234,8 +235,12 @@ export function startFrameHost(
|
|
|
234
235
|
launch.runtime === undefined
|
|
235
236
|
? hostCommand(env, platform)
|
|
236
237
|
: { file: launch.runtime, args: packagedHostArgs(program, root), shell: false }
|
|
238
|
+
// Nothing of Electron's own descriptors (its DevTools port) goes on to the host (inherited.ts); a command that needs the Windows shell is left as it is.
|
|
239
|
+
const start = command.shell
|
|
240
|
+
? { program: command.file, args: command.args }
|
|
241
|
+
: withoutInheritedDescriptors(command.file, command.args, platform)
|
|
237
242
|
// The host leads its own process group on macOS and Linux, so a stop reaches npm, the host and every terminal it runs; Windows stops the tree with taskkill.
|
|
238
|
-
const child: ChildProcess = spawn(
|
|
243
|
+
const child: ChildProcess = spawn(start.program, [...start.args], {
|
|
239
244
|
cwd: root,
|
|
240
245
|
env: {
|
|
241
246
|
...env,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a child of the Electron main process inherits. On Linux Chromium opens its DevTools port (`--remote-debugging-port`), its sockets and its files without
|
|
3
|
+
* close-on-exec, and Node's spawn passes every such descriptor on: a started app's host kept the port bound after the app that was started with it had quit
|
|
4
|
+
* (found on Linux: a `sleep` started from Electron main held 20 descriptors, among them Chromium's sockets). macOS closes everything but the standard streams
|
|
5
|
+
* when it starts a process, and a Windows socket is not inherited, so only Linux needs this. The same text is in plugins/launcher-desktop/src/runner.ts (the
|
|
6
|
+
* two packages share no code); keep them equal.
|
|
7
|
+
*/
|
|
8
|
+
import { existsSync } from 'node:fs'
|
|
9
|
+
|
|
10
|
+
/** bash's `exec 12>&-` closes a descriptor of any number (dash accepts one digit only); the command then replaces bash, so the process id and group stay the child's own. */
|
|
11
|
+
const CLOSE_AND_RUN =
|
|
12
|
+
// biome-ignore lint/suspicious/noTemplateCurlyInString: shell parameter expansion, not a JavaScript template
|
|
13
|
+
'for f in /proc/self/fd/*; do n=${f##*/}; if [ "$n" -gt 2 ]; then eval "exec $n>&-"; fi; done; exec "$@"'
|
|
14
|
+
|
|
15
|
+
export const BASH = '/bin/bash'
|
|
16
|
+
|
|
17
|
+
/** The program and arguments to spawn so the child holds no descriptor above 2: the command itself where that is already so, or where bash is not there. */
|
|
18
|
+
export function withoutInheritedDescriptors(
|
|
19
|
+
program: string,
|
|
20
|
+
args: readonly string[],
|
|
21
|
+
platform: NodeJS.Platform = process.platform,
|
|
22
|
+
hasBash: boolean = existsSync(BASH),
|
|
23
|
+
): { readonly program: string; readonly args: readonly string[] } {
|
|
24
|
+
if (platform !== 'linux' || !hasBash) return { program, args }
|
|
25
|
+
return { program: BASH, args: ['-c', CLOSE_AND_RUN, 'acryl-spawn', program, ...args] }
|
|
26
|
+
}
|
|
@@ -39,7 +39,7 @@ import {
|
|
|
39
39
|
} from './frame.ts'
|
|
40
40
|
import { productGit, withGitFirst } from './git.ts'
|
|
41
41
|
import { appendHostLog, hostCrashed, hostRestarting, nextRestart } from './host-supervisor.ts'
|
|
42
|
-
import { hasSettings, settingsPlacement } from './menu.ts'
|
|
42
|
+
import { aboutPlacement, aboutText, hasSettings, settingsPlacement } from './menu.ts'
|
|
43
43
|
import { openProductApp, seedSource } from './product.ts'
|
|
44
44
|
import { createDesktopShutdown, installShutdownRequests } from './shutdown.ts'
|
|
45
45
|
import { offerUpdates } from './update-menu.ts'
|
|
@@ -472,6 +472,24 @@ if (!app.requestSingleInstanceLock()) {
|
|
|
472
472
|
}
|
|
473
473
|
if (product?.releases !== undefined)
|
|
474
474
|
offerUpdates(product.releases, () => live()[0], join(userData, 'updates'))
|
|
475
|
+
// Windows and Linux: Help > About <name> shows the version (macOS has the About panel).
|
|
476
|
+
const helpMenu = Menu.getApplicationMenu()
|
|
477
|
+
const aboutAt = helpMenu === null ? undefined : aboutPlacement(helpMenu.items, process.platform)
|
|
478
|
+
if (helpMenu !== null && aboutAt !== undefined) {
|
|
479
|
+
helpMenu.items[aboutAt]?.submenu?.append(
|
|
480
|
+
new MenuItem({
|
|
481
|
+
label: `About ${app.getName()}`,
|
|
482
|
+
click: () => {
|
|
483
|
+
const about = aboutText(app.getName(), app.getVersion(), process.versions)
|
|
484
|
+
const owner = BrowserWindow.getFocusedWindow() ?? live()[0]
|
|
485
|
+
const options = { type: 'info' as const, buttons: ['OK'], ...about }
|
|
486
|
+
if (owner === undefined) void dialog.showMessageBox(options)
|
|
487
|
+
else void dialog.showMessageBox(owner, options)
|
|
488
|
+
},
|
|
489
|
+
}),
|
|
490
|
+
)
|
|
491
|
+
Menu.setApplicationMenu(helpMenu)
|
|
492
|
+
}
|
|
475
493
|
stopDoorShell = startDoorShell(chosen.root, { desktop, log: console.log })
|
|
476
494
|
|
|
477
495
|
if (appPage && storage !== undefined && product !== undefined) {
|
|
@@ -58,3 +58,35 @@ export function hasSettings(items: readonly MenuNode[]): boolean {
|
|
|
58
58
|
(item.submenu?.items !== undefined && hasSettings(item.submenu.items)),
|
|
59
59
|
)
|
|
60
60
|
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Windows and Linux have no application menu, so nothing there says which version runs (macOS has the About panel). Returns the index of the Help menu, where
|
|
64
|
+
* "About <name>" goes last, or nothing on macOS, in a menu with no Help, or in one that already has an About item.
|
|
65
|
+
*/
|
|
66
|
+
export function aboutPlacement(
|
|
67
|
+
items: readonly MenuNode[],
|
|
68
|
+
platform: NodeJS.Platform,
|
|
69
|
+
): number | undefined {
|
|
70
|
+
if (platform === 'darwin') return undefined
|
|
71
|
+
const help = items.findIndex((item) => item.role === 'help' || /^&?help$/iu.test(item.label))
|
|
72
|
+
if (help === -1 || items[help]?.submenu == null) return undefined
|
|
73
|
+
const entries = items[help].submenu.items
|
|
74
|
+
return entries.some((item) => item.role === 'about' || /^about\b/iu.test(item.label))
|
|
75
|
+
? undefined
|
|
76
|
+
: help
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** What the About dialog says: the product and its version first, then the runtime it runs on (what a bug report needs). */
|
|
80
|
+
export function aboutText(
|
|
81
|
+
name: string,
|
|
82
|
+
version: string,
|
|
83
|
+
versions: Readonly<Record<string, string | undefined>>,
|
|
84
|
+
): { readonly message: string; readonly detail: string } {
|
|
85
|
+
const runtime = (['electron', 'chrome', 'node'] as const)
|
|
86
|
+
.filter((key) => versions[key] !== undefined)
|
|
87
|
+
.map(
|
|
88
|
+
(key) =>
|
|
89
|
+
`${key === 'chrome' ? 'Chromium' : key === 'node' ? 'Node.js' : 'Electron'} ${versions[key]}`,
|
|
90
|
+
)
|
|
91
|
+
return { message: name, detail: [`Version ${version}`, ...runtime].join('\n') }
|
|
92
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acryldev/desktop-shell",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Run the app as a desktop app: an Electron window on the app's own server. `npm run desktop`; the app's code never imports electron.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acryldev/plugin-share",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Share plugins between people. Pull one someone released into the running app: fetched without running anything, checked by digest and for every OS, then installed live. Publish one, only as a plan a person confirmed.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acryldev/save",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Save the app to its own git repository, and share it: a repository of its own on GitHub, created and pushed only after a person confirms the plan. Refuses a file that holds a secret, and a private app going to a public remote.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/plugins/save/plugin.json
CHANGED
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
"name": "save",
|
|
3
3
|
"description": "Save the app to its own git repository, and share it: a repository of its own on GitHub, created and pushed only after a person confirms the plan. Refuses a file that holds a secret, and a private app going to a public remote.",
|
|
4
4
|
"requires": [],
|
|
5
|
-
"inject": [
|
|
6
|
-
"appInstance"
|
|
7
|
-
],
|
|
5
|
+
"inject": ["appInstance"],
|
|
8
6
|
"provides": [],
|
|
9
7
|
"dependencies": {
|
|
10
8
|
"@deepseek-ai/cordis": "4.0.4",
|
|
11
|
-
"@acryldev/app-persistence": "0.1.
|
|
9
|
+
"@acryldev/app-persistence": "0.1.6"
|
|
12
10
|
},
|
|
13
11
|
"mount": "mount the plugin to give the agent a save_app tool; its scripts (npm run save, npm run share) are added to package.json with it",
|
|
14
12
|
"entries": {
|
package/plugins/save/share.ts
CHANGED
|
@@ -11,8 +11,8 @@ import {
|
|
|
11
11
|
type AppIdentity,
|
|
12
12
|
type CatalogCategory,
|
|
13
13
|
connectRemote,
|
|
14
|
-
type GitPort,
|
|
15
14
|
GITHUB_VIA_GH,
|
|
15
|
+
type GitPort,
|
|
16
16
|
gitCli,
|
|
17
17
|
githubHosting,
|
|
18
18
|
type HostingPort,
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
type Visibility,
|
|
28
28
|
withId,
|
|
29
29
|
withLicense,
|
|
30
|
+
withVersion,
|
|
30
31
|
withPlacement,
|
|
31
32
|
withVisibility,
|
|
32
33
|
} from '@acryldev/app-persistence'
|
|
@@ -82,7 +83,11 @@ export interface ShareOptions {
|
|
|
82
83
|
/** Who may see a new repository; blend.yaml's metadata.visibility when absent. A share with it records it there, so later saves agree. */
|
|
83
84
|
readonly visibility?: Visibility
|
|
84
85
|
/** List it in the Blends store. Any part not given is taken from the app: its earlier listing, else its starter's category; licence MIT. */
|
|
85
|
-
readonly list?: {
|
|
86
|
+
readonly list?: {
|
|
87
|
+
readonly category?: string
|
|
88
|
+
readonly subcategory?: string
|
|
89
|
+
readonly license?: string
|
|
90
|
+
}
|
|
86
91
|
/** The published category list (acrylblends.github.io/categories.json), to check the place against; unchecked when absent. */
|
|
87
92
|
readonly categories?: readonly CatalogCategory[]
|
|
88
93
|
}
|
|
@@ -97,6 +102,8 @@ export interface SharePorts {
|
|
|
97
102
|
pending(): number
|
|
98
103
|
/** Label `owner/repo` for the Blends store and push the tag; false when the tag already existed (it is never moved). */
|
|
99
104
|
list(repository: string, tag: string): boolean
|
|
105
|
+
/** Whether release `tag` exists here: `none`, `current` (it is this commit), or `older` (versions were saved since). */
|
|
106
|
+
released(tag: string): 'none' | 'current' | 'older'
|
|
100
107
|
}
|
|
101
108
|
|
|
102
109
|
/** The person's own git and gh, in the app's folder. */
|
|
@@ -116,15 +123,30 @@ export function sharePorts(appRoot: string): SharePorts {
|
|
|
116
123
|
const result = run('git', ['status', '--porcelain'])
|
|
117
124
|
return result.status === 0 ? result.stdout.split('\n').filter(Boolean).length : 0
|
|
118
125
|
},
|
|
126
|
+
released: (tag) => {
|
|
127
|
+
const tagged = run('git', ['rev-parse', '-q', '--verify', `refs/tags/${tag}^{commit}`])
|
|
128
|
+
if (tagged.status !== 0) return 'none'
|
|
129
|
+
const head = run('git', ['rev-parse', '-q', '--verify', 'HEAD'])
|
|
130
|
+
return head.status === 0 && head.stdout.trim() === tagged.stdout.trim() ? 'current' : 'older'
|
|
131
|
+
},
|
|
119
132
|
list: (repository, tag) => {
|
|
120
133
|
const must = (command: string, args: readonly string[], what: string) => {
|
|
121
134
|
const result = run(command, args)
|
|
122
|
-
if (result.status !== 0)
|
|
135
|
+
if (result.status !== 0)
|
|
136
|
+
throw new PersistenceError(`${what}: ${(result.stderr || result.stdout).trim()}`)
|
|
123
137
|
}
|
|
124
|
-
must(
|
|
138
|
+
must(
|
|
139
|
+
'gh',
|
|
140
|
+
['repo', 'edit', repository, '--add-topic', BLEND_TOPIC],
|
|
141
|
+
'could not label the repository for the Blends store',
|
|
142
|
+
)
|
|
125
143
|
if (run('git', ['rev-parse', '-q', '--verify', `refs/tags/${tag}`]).status === 0) return false
|
|
126
144
|
must('git', ['tag', tag], `could not tag ${tag}`)
|
|
127
|
-
must(
|
|
145
|
+
must(
|
|
146
|
+
'git',
|
|
147
|
+
[...GITHUB_VIA_GH, 'push', '--quiet', 'origin', `refs/tags/${tag}`],
|
|
148
|
+
`could not push ${tag}`,
|
|
149
|
+
)
|
|
128
150
|
return true
|
|
129
151
|
},
|
|
130
152
|
}
|
|
@@ -145,10 +167,23 @@ const repositoryName = (name: string): string =>
|
|
|
145
167
|
export const githubRepository = (remote: string): string | undefined =>
|
|
146
168
|
/github\.com[/:]([^/]+\/[^/]+?)(?:\.git)?\/?$/u.exec(remote)?.[1]
|
|
147
169
|
|
|
148
|
-
const INSTALL_SCRIPTS = [
|
|
170
|
+
const INSTALL_SCRIPTS = [
|
|
171
|
+
'preinstall',
|
|
172
|
+
'install',
|
|
173
|
+
'postinstall',
|
|
174
|
+
'prepublish',
|
|
175
|
+
'preprepare',
|
|
176
|
+
'prepare',
|
|
177
|
+
'postprepare',
|
|
178
|
+
]
|
|
149
179
|
const LICENSE_ID = /^[A-Za-z0-9][A-Za-z0-9.+-]*$/u
|
|
150
180
|
|
|
151
|
-
interface PackageJson {
|
|
181
|
+
interface PackageJson {
|
|
182
|
+
version?: unknown
|
|
183
|
+
keywords?: unknown
|
|
184
|
+
scripts?: Record<string, unknown>
|
|
185
|
+
[key: string]: unknown
|
|
186
|
+
}
|
|
152
187
|
const packageOf = (appRoot: string): PackageJson | undefined => {
|
|
153
188
|
try {
|
|
154
189
|
return JSON.parse(readFileSync(join(appRoot, 'package.json'), 'utf8')) as PackageJson
|
|
@@ -157,27 +192,62 @@ const packageOf = (appRoot: string): PackageJson | undefined => {
|
|
|
157
192
|
}
|
|
158
193
|
}
|
|
159
194
|
|
|
195
|
+
/** `1.2.0` -> `1.2.1`; a version that is not three numbers gets `.1` added, so it still moves on. */
|
|
196
|
+
export const nextPatch = (version: string): string => {
|
|
197
|
+
const parts = /^(\d+)\.(\d+)\.(\d+)$/u.exec(version)
|
|
198
|
+
return parts === null ? `${version}.1` : `${parts[1]}.${parts[2]}.${Number(parts[3]) + 1}`
|
|
199
|
+
}
|
|
200
|
+
|
|
160
201
|
/** The store listing a share asked for, as the person will read it, or why it cannot be listed. */
|
|
161
|
-
function planListing(
|
|
202
|
+
function planListing(
|
|
203
|
+
appRoot: string,
|
|
204
|
+
identity: AppIdentity,
|
|
205
|
+
visibility: Visibility,
|
|
206
|
+
repository: string | undefined,
|
|
207
|
+
options: ShareOptions,
|
|
208
|
+
ports: SharePorts,
|
|
209
|
+
): StoreListing | ShareRefused | undefined {
|
|
162
210
|
const asked = options.list
|
|
163
211
|
if (asked === undefined) return undefined
|
|
164
|
-
if (visibility !== 'public')
|
|
165
|
-
|
|
166
|
-
if (
|
|
212
|
+
if (visibility !== 'public')
|
|
213
|
+
return refused('only a public app can be listed in the Blends store: choose public')
|
|
214
|
+
if (repository === undefined)
|
|
215
|
+
return refused('only an app on GitHub can be listed in the Blends store')
|
|
216
|
+
if (identity.description === undefined)
|
|
217
|
+
return refused(
|
|
218
|
+
'the store lists an app with its description: add one to blend.yaml (metadata.description)',
|
|
219
|
+
)
|
|
167
220
|
const pkg = packageOf(appRoot)
|
|
168
221
|
if (pkg === undefined) return refused('the app has no readable package.json')
|
|
169
|
-
const script = INSTALL_SCRIPTS.find(name => typeof pkg.scripts?.[name] === 'string')
|
|
170
|
-
if (script !== undefined)
|
|
222
|
+
const script = INSTALL_SCRIPTS.find((name) => typeof pkg.scripts?.[name] === 'string')
|
|
223
|
+
if (script !== undefined)
|
|
224
|
+
return refused(
|
|
225
|
+
`package.json defines the install script "${script}", which a listed app may not`,
|
|
226
|
+
)
|
|
171
227
|
const categories = options.categories ?? []
|
|
172
|
-
const placement: Placement | undefined =
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
228
|
+
const placement: Placement | undefined =
|
|
229
|
+
asked.category !== undefined
|
|
230
|
+
? {
|
|
231
|
+
category: asked.category,
|
|
232
|
+
...(asked.subcategory === undefined ? {} : { subcategory: asked.subcategory }),
|
|
233
|
+
}
|
|
234
|
+
: (placementOf(pkg.keywords) ?? suggestPlacement(identity.category, categories))
|
|
235
|
+
if (placement === undefined)
|
|
236
|
+
return refused(
|
|
237
|
+
'choose its category, one of acrylblends.github.io/blends (for example --category gaming)',
|
|
238
|
+
)
|
|
176
239
|
const problem = categories.length > 0 ? placementProblem(placement, categories) : undefined
|
|
177
240
|
if (problem !== undefined) return refused(problem)
|
|
178
241
|
const license = asked.license ?? identity.license ?? 'MIT'
|
|
179
|
-
if (!LICENSE_ID.test(license))
|
|
180
|
-
|
|
242
|
+
if (!LICENSE_ID.test(license))
|
|
243
|
+
return refused(`"${license}" is not a licence id (such as MIT or Apache-2.0)`)
|
|
244
|
+
// A release is never moved: when this version is already tagged and the app changed since, the share releases the next patch version.
|
|
245
|
+
let version = typeof pkg.version === 'string' ? pkg.version : (identity.version ?? '0.1.0')
|
|
246
|
+
for (let guard = 0; guard < 100; guard += 1) {
|
|
247
|
+
const released = ports.released(`v${version}`)
|
|
248
|
+
if (released === 'none' || (released === 'current' && ports.pending() === 0)) break
|
|
249
|
+
version = nextPatch(version)
|
|
250
|
+
}
|
|
181
251
|
const name = (identity.id ?? '').split('.').slice(1).join('.') || repository.split('/')[1] || ''
|
|
182
252
|
const id = `${(repository.split('/')[0] ?? '').toLowerCase()}.${name.toLowerCase()}`
|
|
183
253
|
return { id, placement, license, tag: `v${version}` }
|
|
@@ -210,20 +280,48 @@ SOFTWARE.
|
|
|
210
280
|
* The files the store reads, written into the app before it is saved: the licence in blend.yaml (and an MIT LICENSE file when it has none),
|
|
211
281
|
* the marker and placement keywords in package.json, and the acryl.template.json that lets people start an app from it. Returns blend.yaml's text.
|
|
212
282
|
*/
|
|
213
|
-
function writeListing(
|
|
283
|
+
function writeListing(
|
|
284
|
+
appRoot: string,
|
|
285
|
+
manifestText: string,
|
|
286
|
+
listing: StoreListing,
|
|
287
|
+
repository: string,
|
|
288
|
+
): string {
|
|
214
289
|
const identity = readAppIdentity(manifestText)
|
|
215
290
|
let text = manifestText
|
|
216
291
|
if (identity.id !== listing.id) text = withId(text, listing.id)
|
|
217
292
|
if (identity.license !== listing.license) text = withLicense(text, listing.license)
|
|
218
|
-
if (text !== manifestText) writeFileSync(join(appRoot, 'blend.yaml'), text)
|
|
219
293
|
const pkg = packageOf(appRoot) ?? {}
|
|
220
|
-
|
|
221
|
-
const
|
|
222
|
-
|
|
294
|
+
// The release this share tags: when planListing moved past an existing tag, the app carries the new version in both files.
|
|
295
|
+
const version = listing.tag.replace(/^v/u, '')
|
|
296
|
+
const bumped = typeof pkg.version === 'string' && pkg.version !== version
|
|
297
|
+
if (bumped || (pkg.version === undefined && identity.version !== version)) text = withVersion(text, version)
|
|
298
|
+
if (text !== manifestText) writeFileSync(join(appRoot, 'blend.yaml'), text)
|
|
299
|
+
const before = Array.isArray(pkg.keywords)
|
|
300
|
+
? pkg.keywords.filter((word): word is string => typeof word === 'string')
|
|
301
|
+
: []
|
|
302
|
+
const keywords = withPlacement(
|
|
303
|
+
before.includes(BLEND_TOPIC) ? before : [...before, BLEND_TOPIC],
|
|
304
|
+
listing.placement,
|
|
305
|
+
)
|
|
306
|
+
if (bumped || JSON.stringify(keywords) !== JSON.stringify(pkg.keywords))
|
|
307
|
+
writeFileSync(
|
|
308
|
+
join(appRoot, 'package.json'),
|
|
309
|
+
`${JSON.stringify({ ...pkg, ...(bumped ? { version } : {}), keywords }, null, 2)}\n`,
|
|
310
|
+
)
|
|
223
311
|
const template = join(appRoot, 'acryl.template.json')
|
|
224
|
-
if (!existsSync(template))
|
|
225
|
-
|
|
226
|
-
|
|
312
|
+
if (!existsSync(template))
|
|
313
|
+
writeFileSync(
|
|
314
|
+
template,
|
|
315
|
+
`${JSON.stringify({ name: identity.name ?? basename(appRoot), description: identity.description ?? '' }, null, 2)}\n`,
|
|
316
|
+
)
|
|
317
|
+
if (
|
|
318
|
+
listing.license === 'MIT' &&
|
|
319
|
+
!['LICENSE', 'LICENSE.md', 'LICENSE.txt'].some((file) => existsSync(join(appRoot, file)))
|
|
320
|
+
)
|
|
321
|
+
writeFileSync(
|
|
322
|
+
join(appRoot, 'LICENSE'),
|
|
323
|
+
MIT(new Date().getFullYear(), repository.split('/')[0] ?? ''),
|
|
324
|
+
)
|
|
227
325
|
return text
|
|
228
326
|
}
|
|
229
327
|
|
|
@@ -235,12 +333,23 @@ export function planShare(
|
|
|
235
333
|
): SharePlan | ShareRefused {
|
|
236
334
|
const plan = planRepository(appRoot, options, ports)
|
|
237
335
|
if ('ok' in plan) return plan
|
|
238
|
-
const listing = planListing(
|
|
336
|
+
const listing = planListing(
|
|
337
|
+
appRoot,
|
|
338
|
+
readAppIdentity(manifestOf(appRoot)),
|
|
339
|
+
plan.visibility,
|
|
340
|
+
plan.create ? plan.repository : githubRepository(plan.repository),
|
|
341
|
+
options,
|
|
342
|
+
ports,
|
|
343
|
+
)
|
|
239
344
|
if (listing !== undefined && 'ok' in listing) return listing
|
|
240
345
|
return listing === undefined ? plan : { ...plan, listing }
|
|
241
346
|
}
|
|
242
347
|
|
|
243
|
-
function planRepository(
|
|
348
|
+
function planRepository(
|
|
349
|
+
appRoot: string,
|
|
350
|
+
options: ShareOptions,
|
|
351
|
+
ports: SharePorts,
|
|
352
|
+
): SharePlan | ShareRefused {
|
|
244
353
|
const identity = readAppIdentity(manifestOf(appRoot))
|
|
245
354
|
const visibility = options.visibility ?? identity.visibility
|
|
246
355
|
const changes = ports.pending()
|
|
@@ -301,7 +410,8 @@ export function shareApp(
|
|
|
301
410
|
}
|
|
302
411
|
const repository = now.create ? now.repository : githubRepository(now.repository)
|
|
303
412
|
try {
|
|
304
|
-
if (now.listing !== undefined && repository !== undefined)
|
|
413
|
+
if (now.listing !== undefined && repository !== undefined)
|
|
414
|
+
manifestText = writeListing(appRoot, manifestText, now.listing, repository)
|
|
305
415
|
let remote = now.repository
|
|
306
416
|
if (now.create) {
|
|
307
417
|
const connected = connectRemote(
|
|
@@ -321,9 +431,10 @@ export function shareApp(
|
|
|
321
431
|
}
|
|
322
432
|
// Nothing new to save: the versions already saved still have to reach the remote.
|
|
323
433
|
if (saved.status === 'nothing-to-save') ports.git.push()
|
|
324
|
-
const listed =
|
|
325
|
-
|
|
326
|
-
|
|
434
|
+
const listed =
|
|
435
|
+
now.listing !== undefined && repository !== undefined
|
|
436
|
+
? { tag: now.listing.tag, created: ports.list(repository, now.listing.tag) }
|
|
437
|
+
: undefined
|
|
327
438
|
return {
|
|
328
439
|
ok: true,
|
|
329
440
|
remote,
|
|
@@ -346,11 +457,14 @@ export function renderSharePlan(plan: SharePlan): string {
|
|
|
346
457
|
plan.changes === 0
|
|
347
458
|
? 'the versions saved so far'
|
|
348
459
|
: `${String(plan.changes)} changed ${plan.changes === 1 ? 'file' : 'files'}, saved first, and the versions saved so far`
|
|
349
|
-
const listed =
|
|
350
|
-
|
|
351
|
-
|
|
460
|
+
const listed =
|
|
461
|
+
plan.listing === undefined
|
|
462
|
+
? ''
|
|
463
|
+
: ` Listed in the Blends store as ${plan.listing.id}, Community, under ${placementWords(plan.listing.placement)} (licence ${plan.listing.license}, people start from ${plan.listing.tag}).`
|
|
352
464
|
return `Share this app to ${where}: ${what}.${listed}`
|
|
353
465
|
}
|
|
354
466
|
|
|
355
467
|
const placementWords = (placement: Placement): string =>
|
|
356
|
-
placement.subcategory === undefined
|
|
468
|
+
placement.subcategory === undefined
|
|
469
|
+
? placement.category
|
|
470
|
+
: `${placement.category} › ${placement.subcategory}`
|