refactor: update version handling and remove placeholder injection

- 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.
This commit is contained in:
Harvey Zack committed 2025-06-20 11:04:29 +08:00
1 parent e2e8e83e63
commit e8a7e050c4
16 files changed
+233 -287

No files matched your search

+45 -63
View File
@@ -1,10 +1,9 @@
import fs from 'fs';
import path from 'path';
import servor from 'servor';
import prompts from 'prompts';
import { Parcel } from '@parcel/core';
import { fileURLToPath } from 'url';
import { getProjects, injectPlaceholders } from './utils.js';
import { getProjects } from './utils.js';
import openBrowser from 'servor/utils/openBrowser.js';
const projects = getProjects();
@@ -13,79 +12,62 @@ async function develop(name) {
const projectPath = projects[name];
const uncompiledPath = path.resolve(`docs/uncompiled/${name}`);
const entryFile = path.join(projectPath, 'src/index.js');
const projectPackageJson = path.join(projectPath, 'package.json');
const { version } = JSON.parse(fs.readFileSync(projectPackageJson, 'utf-8'));
const restore = injectPlaceholders(entryFile, {
__APP_VERSION__: `"${version}"`,
__NODE_ENV__: `"development"`,
});
process.on('SIGINT', () => {
restore();
process.exit();
});
let isOpenBrowser = false;
try {
const { url } = await servor({
root: 'docs',
fallback: 'index.html',
reload: true,
port: 8082,
});
const { url } = await servor({
root: 'docs',
fallback: 'index.html',
reload: true,
port: 8082,
});
process.chdir(projectPath);
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'],
},
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',
},
env: {
NODE_ENV: 'development',
},
additionalReporters: [
{
packageName: '@parcel/reporter-cli',
resolveFrom: fileURLToPath(import.meta.url),
},
additionalReporters: [
{
packageName: '@parcel/reporter-cli',
resolveFrom: fileURLToPath(import.meta.url),
},
],
});
],
});
bundler.watch((error, event) => {
if (error) {
console.error(`[${name}] ❌ Build error:`, error);
return;
}
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 === '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);
}
});
} catch (error) {
console.error(`❌ Failed to start dev server for ${name}: ${error.message}`);
restore();
}
if (event.type === 'buildFailure') {
console.error(`[${name}] ❌ Build failure:`, event.diagnostics);
}
});
}
(async () => {