build: add precompiled CLI distribution
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
import { mkdir, writeFile } from 'node:fs/promises';
|
||||
import { createRequire } from 'node:module';
|
||||
import path from 'node:path';
|
||||
const require = createRequire(import.meta.url);
|
||||
const engineVersion = String(require('../package.json').version);
|
||||
const args = process.argv.slice(2);
|
||||
const engineIndex = args.indexOf('--engine');
|
||||
const engineSpec = engineIndex >= 0 ? args[engineIndex + 1] : `^${engineVersion}`;
|
||||
if (!engineSpec)
|
||||
throw new Error('--engine 需要 npm 版本、Git URL 或本地路径');
|
||||
const targetInput = args.find((argument, index) => !argument.startsWith('-') && index !== engineIndex + 1) ?? '.';
|
||||
const target = path.resolve(targetInput);
|
||||
await mkdir(path.join(target, 'slides', 'welcome', 'assets'), { recursive: true });
|
||||
await mkdir(path.join(target, '.github', 'workflows'), { recursive: true });
|
||||
await writeNew('package.json', `${JSON.stringify({
|
||||
name: path.basename(target),
|
||||
private: true,
|
||||
scripts: {
|
||||
dev: 'easy-slides dev',
|
||||
present: 'easy-slides present',
|
||||
build: 'easy-slides build',
|
||||
check: 'easy-slides check',
|
||||
export: 'easy-slides export',
|
||||
},
|
||||
devDependencies: {
|
||||
'@easy-slides/cli': engineSpec,
|
||||
},
|
||||
}, null, 2)}\n`);
|
||||
await writeNew('easy-slides.config.mjs', `export default {
|
||||
title: '${escapeJavaScript(path.basename(target))}',
|
||||
description: 'Markdown presentations',
|
||||
slidesDir: 'slides',
|
||||
outDir: 'dist',
|
||||
}
|
||||
`);
|
||||
await writeNew(path.join('slides', 'welcome', 'slides.md'), `---
|
||||
title: Welcome
|
||||
description: Your first easy-slides deck
|
||||
date: ${new Date().toISOString().slice(0, 10)}
|
||||
tags: [Markdown]
|
||||
---
|
||||
|
||||
# Welcome
|
||||
|
||||
> Edit slides/welcome/slides.md and push to deploy.
|
||||
|
||||
<!--
|
||||
Speaker notes are written in HTML comments.
|
||||
-->
|
||||
|
||||
---
|
||||
|
||||
## Content lives here
|
||||
|
||||
- The engine is an npm dependency
|
||||
- This repository owns slides and assets
|
||||
- The static build can deploy anywhere
|
||||
`);
|
||||
await writeNew('.gitignore', `node_modules/
|
||||
dist/
|
||||
exports/
|
||||
.env
|
||||
.DS_Store
|
||||
`);
|
||||
await writeNew('pnpm-workspace.yaml', `allowBuilds:
|
||||
playwright-chromium: false
|
||||
`);
|
||||
await writeNew(path.join('.github', 'workflows', 'deploy-pages.yml'), `name: Deploy slides
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pages: write
|
||||
id-token: write
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
environment:
|
||||
name: github-pages
|
||||
url: \${{ steps.deployment.outputs.page_url }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: 11.19.0
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
cache: pnpm
|
||||
- run: pnpm install --frozen-lockfile
|
||||
- run: pnpm check
|
||||
env:
|
||||
PRESENTER_TOKEN: \${{ secrets.PRESENTER_TOKEN }}
|
||||
- run: pnpm build
|
||||
env:
|
||||
SITE_BASE: /\${{ github.event.repository.name }}/
|
||||
PRESENTER_TOKEN: \${{ secrets.PRESENTER_TOKEN }}
|
||||
- uses: actions/configure-pages@v5
|
||||
- uses: actions/upload-pages-artifact@v4
|
||||
with:
|
||||
path: dist
|
||||
- id: deployment
|
||||
uses: actions/deploy-pages@v4
|
||||
`);
|
||||
console.log(`内容项目已创建:${target}`);
|
||||
console.log('下一步:pnpm install && pnpm dev -- welcome');
|
||||
async function writeNew(relative, content) {
|
||||
const filename = path.join(target, relative);
|
||||
await mkdir(path.dirname(filename), { recursive: true });
|
||||
await writeFile(filename, content, { encoding: 'utf8', flag: 'wx' }).catch((error) => {
|
||||
if (error.code === 'EEXIST')
|
||||
throw new Error(`拒绝覆盖已有文件:${filename}`);
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
function escapeJavaScript(value) {
|
||||
return value.replaceAll('\\', '\\\\').replaceAll("'", "\\'");
|
||||
}
|
||||
//# sourceMappingURL=init.js.map
|
||||
Reference in New Issue
Block a user