mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 23:51:20 -08:00
Vast (#762)
* add artplayer-plugin-vast
* chore: Add create:plugin script to package.json
* chore: Remove deprecated artplayer-plugin-{{name}} and artplayer-plugin-vast types
* chore: Update artplayer-plugin-vast package description
* chore: Update Prettier configuration and dependencies
This commit is contained in:
1 parent
b398749ef8
commit
fac7d15726
24 files changed
+703
-296
No files matched your search
+60
-52
@@ -6,25 +6,26 @@ import { Parcel } from '@parcel/core';
|
||||
import { formatDate, getProjects } from './utils.js';
|
||||
|
||||
const projects = getProjects();
|
||||
const compiledPath = path.resolve(`docs/compiled`);
|
||||
const compiledPath = path.resolve('docs/compiled');
|
||||
|
||||
function compressString(input) {
|
||||
const compressedHtmlString = input.replace(/\s*(<[^>]+>)\s*/g, '$1');
|
||||
const compressedCssString = compressedHtmlString
|
||||
return input
|
||||
.replace(/\s*(<[^>]+>)\s*/g, '$1')
|
||||
.replace(/(\r\n|\n|\r)/gm, ' ')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim();
|
||||
return compressedCssString;
|
||||
}
|
||||
|
||||
async function build(name, targetName) {
|
||||
const { version } = JSON.parse(fs.readFileSync(`${projects[name]}/package.json`, 'utf-8'));
|
||||
const projectPackageJson = path.join(projects[name], 'package.json');
|
||||
const { version } = JSON.parse(fs.readFileSync(projectPackageJson, 'utf-8'));
|
||||
|
||||
process.chdir(projects[name]);
|
||||
|
||||
const targets = {
|
||||
main: {
|
||||
context: 'browser',
|
||||
distDir: `${projects[name]}/dist`,
|
||||
distDir: path.join(projects[name], 'dist'),
|
||||
sourceMap: false,
|
||||
outputFormat: 'global',
|
||||
engines: {
|
||||
@@ -33,7 +34,7 @@ async function build(name, targetName) {
|
||||
},
|
||||
legacy: {
|
||||
context: 'browser',
|
||||
distDir: `${projects[name]}/dist`,
|
||||
distDir: path.join(projects[name], 'dist'),
|
||||
sourceMap: false,
|
||||
outputFormat: 'global',
|
||||
engines: {
|
||||
@@ -48,7 +49,7 @@ async function build(name, targetName) {
|
||||
};
|
||||
|
||||
const bundler = new Parcel({
|
||||
entries: `${projects[name]}/src/index.js`,
|
||||
entries: path.join(projects[name], 'src/index.js'),
|
||||
defaultConfig: '@parcel/config-default',
|
||||
mode: 'production',
|
||||
targets: {
|
||||
@@ -61,58 +62,57 @@ async function build(name, targetName) {
|
||||
},
|
||||
});
|
||||
|
||||
const banner =
|
||||
'/*!\n' +
|
||||
` * ${name}.js v${version}\n` +
|
||||
` * Github: https://github.com/zhw2590582/ArtPlayer\n` +
|
||||
` * (c) 2017-${new Date().getFullYear()} Harvey Zack\n` +
|
||||
' * Released under the MIT License.\n' +
|
||||
' */\n';
|
||||
const banner = `
|
||||
/*!
|
||||
* ${name}.js v${version}
|
||||
* Github: https://github.com/zhw2590582/ArtPlayer
|
||||
* (c) 2017-${new Date().getFullYear()} Harvey Zack
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
`;
|
||||
|
||||
const { bundleGraph, buildTime } = await bundler.run();
|
||||
const bundles = bundleGraph.getBundles();
|
||||
try {
|
||||
const { bundleGraph, buildTime } = await bundler.run();
|
||||
const bundles = bundleGraph.getBundles();
|
||||
|
||||
const filePath = `${projects[name]}/dist/index.js`;
|
||||
const newFilePath = `${projects[name]}/dist/${names[targetName]}.js`;
|
||||
const code = String(fs.readFileSync(filePath));
|
||||
fs.writeFileSync(filePath, banner + compressString(code));
|
||||
fs.renameSync(filePath, newFilePath);
|
||||
await cpy(newFilePath, compiledPath);
|
||||
const size = fs.statSync(newFilePath).size / 1024;
|
||||
console.log(
|
||||
`✨ Built@${targetName} ${name}@${version}`,
|
||||
`Bundles@${bundles.length}`,
|
||||
`Time@${buildTime}ms`,
|
||||
`Size@${size}kb`,
|
||||
);
|
||||
const filePath = path.join(projects[name], 'dist/index.js');
|
||||
const newFilePath = path.join(projects[name], `dist/${names[targetName]}.js`);
|
||||
const code = fs.readFileSync(filePath, 'utf-8');
|
||||
fs.writeFileSync(filePath, banner + compressString(code));
|
||||
fs.renameSync(filePath, newFilePath);
|
||||
await cpy(newFilePath, compiledPath);
|
||||
const size = fs.statSync(newFilePath).size / 1024;
|
||||
|
||||
console.log(
|
||||
`✨ Built@${targetName} ${name}@${version}`,
|
||||
`Bundles@${bundles.length}`,
|
||||
`Time@${buildTime}ms`,
|
||||
`Size@${size.toFixed(2)}kb`,
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(`Failed to build ${name}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
function runPromisesInSeries(ps) {
|
||||
return ps.reduce((p, next) => p.then(next), Promise.resolve());
|
||||
}
|
||||
async function runBuild() {
|
||||
if (process.argv.pop() === 'all') {
|
||||
const bundles = Object.keys(projects).map((name) => async () => {
|
||||
await build(name, 'main');
|
||||
await build(name, 'legacy');
|
||||
});
|
||||
|
||||
if (process.argv.pop() === 'all') {
|
||||
const bundles = Object.keys(projects).map((name) => async () => {
|
||||
await build(name, 'main');
|
||||
await build(name, 'legacy');
|
||||
});
|
||||
|
||||
runPromisesInSeries(bundles).then(() => {
|
||||
console.log(`✨ Finished building all packages!`);
|
||||
});
|
||||
} else {
|
||||
(async () => {
|
||||
await runPromisesInSeries(bundles);
|
||||
console.log('✨ Finished building all packages!');
|
||||
} else {
|
||||
const response = await prompts({
|
||||
type: 'select',
|
||||
name: 'value',
|
||||
message: 'Which project do you want to build?',
|
||||
choices: Object.keys(projects).map((name) => {
|
||||
return {
|
||||
title: name,
|
||||
value: name,
|
||||
description: projects[name],
|
||||
};
|
||||
}),
|
||||
choices: Object.keys(projects).map((name) => ({
|
||||
title: name,
|
||||
value: name,
|
||||
description: projects[name],
|
||||
})),
|
||||
initial: 0,
|
||||
});
|
||||
|
||||
@@ -120,5 +120,13 @@ if (process.argv.pop() === 'all') {
|
||||
await build(response.value, 'main');
|
||||
await build(response.value, 'legacy');
|
||||
}
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
function runPromisesInSeries(ps) {
|
||||
return ps.reduce((p, next) => p.then(next), Promise.resolve());
|
||||
}
|
||||
|
||||
runBuild().catch((error) => {
|
||||
console.error('Build script encountered an error:', error);
|
||||
});
|
||||
Reference in new issue
Block a user