build: add precompiled CLI distribution
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { spawn } from 'node:child_process';
|
||||
import { createRequire } from 'node:module';
|
||||
import { hashPresenterToken } from "./token.js";
|
||||
const require = createRequire(import.meta.url);
|
||||
const slidevCli = require.resolve('@slidev/cli/bin/slidev.mjs');
|
||||
export function startSlidev(args, options = {}) {
|
||||
const token = options.env?.PRESENTER_TOKEN ?? process.env.PRESENTER_TOKEN;
|
||||
const presenterHash = token?.trim() ? hashPresenterToken(token) : '';
|
||||
return spawn(process.execPath, [slidevCli, ...args], {
|
||||
cwd: process.cwd(),
|
||||
env: {
|
||||
...process.env,
|
||||
...options.env,
|
||||
VITE_EASY_SLIDES_PRESENTER_HASH: presenterHash,
|
||||
},
|
||||
stdio: 'inherit',
|
||||
});
|
||||
}
|
||||
export async function waitForSlidev(child) {
|
||||
await new Promise((resolve, reject) => {
|
||||
child.once('error', reject);
|
||||
child.once('exit', (code, signal) => {
|
||||
if (code === 0)
|
||||
resolve();
|
||||
else
|
||||
reject(new Error(`Slidev 退出:${signal ?? `code ${code}`}`));
|
||||
});
|
||||
});
|
||||
}
|
||||
export async function runSlidev(args, options = {}) {
|
||||
await waitForSlidev(startSlidev(args, options));
|
||||
}
|
||||
//# sourceMappingURL=run-slidev.js.map
|
||||
Reference in New Issue
Block a user