Alexander b4d33beada
fix CLI asset sync (#355)
* fix CLI asset sync

* fix(cli): normalize line endings in asset sync/check

check:assets hashed raw bytes, so identical CSV/JSON/py content with
CRLF vs LF (git autocrlf on checkout) was reported as stale drift,
blocking the release guard on Windows/mixed checkouts.

- fileHash now normalizes CRLF->LF before hashing, so check:assets
  compares content, not line endings.
- sync:assets writes LF-normalized copies instead of a raw byte copy,
  so re-syncing is deterministic across platforms.

All synced assets are text (csv/json/md/py); no binaries affected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* ci: enforce CLI asset sync on PRs

Adds a Check asset sync workflow that runs `npm run check:assets` on any
PR touching src/ui-ux-pro-max/** or cli/assets/**, so the bundled CLI
assets can't silently drift from the source of truth.

The check uses only node builtins (no install step) and normalizes
line endings before hashing, so it hard-fails on real content drift
without the CRLF/LF soft-fail hack other approaches needed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 12:54:58 +07:00

64 lines
2.0 KiB
TypeScript

import { readFile } from 'node:fs/promises';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import chalk from 'chalk';
import ora from 'ora';
import { getLatestRelease } from '../utils/github.js';
import { logger } from '../utils/logger.js';
import { initCommand } from './init.js';
import type { AIType } from '../types/index.js';
const __dirname = dirname(fileURLToPath(import.meta.url));
interface UpdateOptions {
ai?: AIType;
token?: string;
}
async function getPackageVersion(): Promise<string> {
const packagePath = join(__dirname, '..', 'package.json');
const pkg = JSON.parse(await readFile(packagePath, 'utf-8')) as { version: string };
return pkg.version;
}
function normalizeTagVersion(tagName: string): string {
return tagName.replace(/^v/i, '');
}
export async function updateCommand(options: UpdateOptions): Promise<void> {
logger.title('UI/UX Pro Max Updater');
const spinner = ora('Checking for updates...').start();
try {
const release = await getLatestRelease(options.token);
const currentVersion = await getPackageVersion();
const latestVersion = normalizeTagVersion(release.tag_name);
spinner.succeed(`Latest version: ${chalk.cyan(release.tag_name)}`);
if (currentVersion !== latestVersion) {
console.log();
logger.warn(`Installed CLI package is ${chalk.cyan(currentVersion)}, but latest release is ${chalk.cyan(release.tag_name)}.`);
logger.info(`Update the CLI package first: ${chalk.cyan(`npm install -g uipro-cli@${latestVersion}`)}`);
logger.info('Then rerun: uipro init --ai <platform>');
return;
}
console.log();
logger.info('Refreshing installed skill files from this CLI package...');
console.log();
await initCommand({
ai: options.ai,
force: true,
token: options.token,
});
} catch (error) {
spinner.fail('Update check failed');
if (error instanceof Error) {
logger.error(error.message);
}
process.exit(1);
}
}