mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
- Simplified version display in context menu and template by directly importing version from package.json. - Removed static version and environment methods from Artplayer class, replacing them with dynamic imports. - Eliminated placeholder injection logic from build and dev scripts, streamlining the build process. - Cleaned up build and dev scripts for better readability and maintainability.
93 lines
2.5 KiB
JavaScript
93 lines
2.5 KiB
JavaScript
import path from 'path';
|
|
import servor from 'servor';
|
|
import prompts from 'prompts';
|
|
import { Parcel } from '@parcel/core';
|
|
import { fileURLToPath } from 'url';
|
|
import { getProjects } from './utils.js';
|
|
import openBrowser from 'servor/utils/openBrowser.js';
|
|
|
|
const projects = getProjects();
|
|
|
|
async function develop(name) {
|
|
const projectPath = projects[name];
|
|
const uncompiledPath = path.resolve(`docs/uncompiled/${name}`);
|
|
const entryFile = path.join(projectPath, 'src/index.js');
|
|
|
|
let isOpenBrowser = false;
|
|
|
|
const { url } = await servor({
|
|
root: 'docs',
|
|
fallback: 'index.html',
|
|
reload: true,
|
|
port: 8082,
|
|
});
|
|
|
|
process.chdir(projectPath);
|
|
|
|
const bundler = new Parcel({
|
|
entries: entryFile,
|
|
defaultConfig: '@parcel/config-default',
|
|
mode: 'development',
|
|
targets: {
|
|
main: {
|
|
distDir: uncompiledPath,
|
|
outputFormat: 'global',
|
|
isLibrary: true,
|
|
engines: {
|
|
browsers: ['last 1 Chrome version'],
|
|
},
|
|
},
|
|
},
|
|
env: {
|
|
NODE_ENV: 'development',
|
|
},
|
|
additionalReporters: [
|
|
{
|
|
packageName: '@parcel/reporter-cli',
|
|
resolveFrom: fileURLToPath(import.meta.url),
|
|
},
|
|
],
|
|
});
|
|
|
|
bundler.watch((error, event) => {
|
|
if (error) {
|
|
console.error(`[${name}] ❌ Build error:`, error);
|
|
return;
|
|
}
|
|
|
|
if (event.type === 'buildSuccess') {
|
|
const bundles = event.bundleGraph.getBundles();
|
|
console.log(`[${name}] ✅ Built ${bundles.length} bundles in ${event.buildTime}ms`);
|
|
if (!isOpenBrowser) {
|
|
isOpenBrowser = true;
|
|
openBrowser(url);
|
|
}
|
|
}
|
|
|
|
if (event.type === 'buildFailure') {
|
|
console.error(`[${name}] ❌ Build failure:`, event.diagnostics);
|
|
}
|
|
});
|
|
}
|
|
|
|
(async () => {
|
|
try {
|
|
const response = await prompts({
|
|
type: 'select',
|
|
name: 'value',
|
|
message: 'Which project do you want to develop?',
|
|
choices: Object.keys(projects).map((name) => ({
|
|
title: name,
|
|
value: name,
|
|
})),
|
|
initial: 0,
|
|
});
|
|
|
|
if (response.value) {
|
|
await develop(response.value);
|
|
}
|
|
} catch (error) {
|
|
console.error(`❌ Prompt error: ${error.message}`);
|
|
}
|
|
})();
|