mirror of
https://github.com/nexu-io/openmotion.git
synced 2026-12-02 04:50:19 +08:00
* fix(install): consolidate setup and public Skill instructions in docs * docs(install): use the public Motion guide short link * feat(dsh): add interactive template recommendation cards * feat(onboarding): share three-card welcomes across hosts and DSH * fix(dsh): automate setup and complete native onboarding * fix(dsh): preserve native shell and panel controls * fix(dsh): enlarge card videos without prompting the agent * fix(dsh): align template cards with Codex presentation --------- Co-authored-by: lefarcen <935902669@qq.com> Co-authored-by: lefarcen <lefarcen@users.noreply.github.com>
63 lines
4.9 KiB
JavaScript
63 lines
4.9 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { mkdir, readFile } from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { runFile, sha256, writeAtomic, writeJSON } from './runtime-assets.mjs';
|
|
import { installationInstructions } from './install-onboarding.mjs';
|
|
import { checkReleaseVersion, releaseTemplateEnvironment } from './release-version.mjs';
|
|
|
|
export function validateGuideSpec(name, version) {
|
|
assert.match(name || '', /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/, 'Require an npm package name');
|
|
assert(name.length <= 214, 'npm package name is too long');
|
|
checkReleaseVersion(version);
|
|
return version.includes('-test.') ? 'test' : 'stable';
|
|
}
|
|
|
|
export function validateGuideIdentity(pkg, manifest) {
|
|
validateGuideSpec(pkg.name, pkg.version);
|
|
assert.equal(pkg.private, false, 'Only public release candidates may have a public installation guide');
|
|
assert.equal(pkg.version, manifest.version, 'Package and embedded manifest versions differ');
|
|
assert.equal(manifest.schemaVersion, 1, 'Unsupported release manifest');
|
|
assert.equal(manifest.templateEnvironment, releaseTemplateEnvironment(pkg.version), 'Template defaults must match the release channel');
|
|
assert.equal(pkg.bin?.openmotion, 'scripts/npm-installer.mjs', 'Missing OpenMotion entry point');
|
|
assert.match(manifest.commit || '', /^[a-f0-9]{40}$/, 'Require the built source SHA');
|
|
for (const hash of [manifest.application?.sha256, manifest.locks?.npm, manifest.locks?.native]) assert.match(hash || '', /^[a-f0-9]{64}$/, 'Require release checksums');
|
|
const targets = Object.values(manifest.runtime?.targets || {});
|
|
assert(targets.length > 0 && targets.every(t => t.platform && t.arch && (t.platform === 'darwin' || t.minimumOS)), 'Require native target declarations (minimum system version required outside macOS)');
|
|
return pkg.version.includes('-test.') ? 'test' : 'stable';
|
|
}
|
|
|
|
export async function generateInstallGuide(tgz, output, candidate = false) {
|
|
const readEntry = async entry => JSON.parse(await runFile('tar', ['-xOf', path.resolve(tgz), entry]));
|
|
const pkg = await readEntry('package/package.json'), manifest = await readEntry('package/payload/release-npm.json');
|
|
const channel = validateGuideIdentity(pkg, manifest);
|
|
const digest = await sha256(tgz), packageSpec = `${pkg.name}@${pkg.version}`;
|
|
await installationInstructions(fileURLToPath(new URL('../', import.meta.url)));
|
|
const values = { VERSION: pkg.version, PACKAGE_SPEC: packageSpec, CHANNEL: channel, COMMIT: manifest.commit,
|
|
TEMPLATE_ENVIRONMENT: manifest.templateEnvironment, TGZ_SHA256: digest,
|
|
TARGETS: Object.values(manifest.runtime.targets).map(t => `${t.platform}/${t.arch}${t.minimumOS ? ` (${t.minimumOS}+)` : ''}`).join(', '),
|
|
DETAILS_URL: `https://github.com/nexu-io/openmotion/blob/${manifest.commit}/docs/npm-installation.md` };
|
|
const guide = await readFile(new URL('../docs/install.md', import.meta.url), 'utf8');
|
|
// Source checkout commands never belong to a published npm installation.
|
|
const template = guide.replace(/<!-- source-only:start -->[\s\S]*?<!-- source-only:end -->\s*/g, '')
|
|
.replace(/^# Install OpenMotion$/m, '# Install OpenMotion {{VERSION}}')
|
|
.replace('skills@1.9.0 add nexu-io/openmotion ', `skills@1.9.0 add https://github.com/nexu-io/openmotion/tree/${manifest.commit} `);
|
|
assert(!template.includes('<!-- source-only:'), 'Installation guide has unmatched source-only markers');
|
|
// The repository warning is unnecessary after all release placeholders are resolved.
|
|
const text = (candidate ? '> Build preview only: this candidate is not an approved registry installation entry.\n\n' : '') + template.replace(/^If you are reading this file.*\n\n/m, '').replace(/\{\{([A-Z0-9_]+)\}\}/g, (_, key) => {
|
|
assert(Object.hasOwn(values, key), 'Unknown installation placeholder: ' + key); return values[key];
|
|
});
|
|
assert(!text.includes('{{'), 'Installation guide has unresolved placeholders');
|
|
await mkdir(output, { recursive: true });
|
|
await writeAtomic(path.join(output, 'install.md'), text);
|
|
const record = { schemaVersion: 1, candidate, packageName: pkg.name, version: pkg.version, packageSpec, channel,
|
|
templateEnvironment: manifest.templateEnvironment, commit: manifest.commit, tgzSHA256: digest,
|
|
applicationSHA256: manifest.application.sha256, locks: manifest.locks, guideSHA256: await sha256(path.join(output, 'install.md')) };
|
|
await writeJSON(path.join(output, 'install-record.json'), record);
|
|
return record;
|
|
}
|
|
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
assert([4, 5].includes(process.argv.length) && (process.argv[4] === undefined || process.argv[4] === '--candidate'), 'Usage: install-guide.mjs <complete-npm.tgz> <output-directory> [--candidate]');
|
|
console.log(JSON.stringify(await generateInstallGuide(process.argv[2], path.resolve(process.argv[3]), process.argv[4] === '--candidate')));
|
|
}
|