refactor: update import statements to use node built-in modules

chore: update lerna configuration formatting

chore: bump version in package.json to 6.0.0

fix: modify build scripts for improved readability and consistency

feat: enhance translation scripts with better error handling and progress tracking

chore: improve plugin creation script for better user experience

style: format svgo configuration for consistency
This commit is contained in:
Harvey Zack committed 2025-08-03 18:34:30 +08:00
1 parent 3540cd0cce
commit fa755b5f61
11 files changed
+509 -496

No files matched your search

+54 -52
View File
@@ -1,81 +1,83 @@
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import fs from 'node:fs'
import path from 'node:path'
import process from 'node:process'
import { fileURLToPath } from 'node:url'
// Get the current file path
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
// Get the plugin name from command line arguments
const args = process.argv.slice(2);
const pluginName = args[0];
const args = process.argv.slice(2)
const pluginName = args[0]
if (!pluginName) {
console.error('Please provide a plugin name, e.g., npm run create:plugin somePluginName');
process.exit(1);
console.error('Please provide a plugin name, e.g., npm run create:plugin somePluginName')
process.exit(1)
}
// Validate plugin name
const pluginNameRegex = /^[a-z-]+$/;
const pluginNameRegex = /^[a-z-]+$/
if (!pluginNameRegex.test(pluginName)) {
console.error('Invalid plugin name. Only lowercase letters and hyphens are allowed.');
process.exit(1);
console.error('Invalid plugin name. Only lowercase letters and hyphens are allowed.')
process.exit(1)
}
// Convert plugin name to export name (PascalCase)
const exportName = pluginName
.split('-')
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join('');
const exportNameFull = `artplayerPlugin${exportName}`;
.split('-')
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
.join('')
const exportNameFull = `artplayerPlugin${exportName}`
// Define paths
const templateDir = path.join(__dirname, 'template');
const destDir = path.join(__dirname, '../../packages', `artplayer-plugin-${pluginName}`);
const exampleDir = path.join(__dirname, '../../docs/assets/example');
const exampleFileName = `${pluginName.replace(/-/g, '.')}.js`;
const exampleFile = path.join(exampleDir, exampleFileName);
const templateDir = path.join(__dirname, 'template')
const destDir = path.join(__dirname, '../../packages', `artplayer-plugin-${pluginName}`)
const exampleDir = path.join(__dirname, '../../docs/assets/example')
const exampleFileName = `${pluginName.replace(/-/g, '.')}.js`
const exampleFile = path.join(exampleDir, exampleFileName)
// Check if a plugin with the same name already exists
if (fs.existsSync(destDir)) {
console.error(`Plugin ${pluginName} already exists. Please choose another name.`);
process.exit(1);
console.error(`Plugin ${pluginName} already exists. Please choose another name.`)
process.exit(1)
}
// Create the destination directory
fs.mkdirSync(destDir, { recursive: true });
fs.mkdirSync(destDir, { recursive: true })
// Read files from the template directory and copy them to the destination directory
function copyTemplateFiles(templateDir, destDir) {
const files = fs.readdirSync(templateDir);
const files = fs.readdirSync(templateDir)
files.forEach((file) => {
const templateFilePath = path.join(templateDir, file);
let destFilePath = path.join(destDir, file);
files.forEach((file) => {
const templateFilePath = path.join(templateDir, file)
let destFilePath = path.join(destDir, file)
const stats = fs.statSync(templateFilePath);
const stats = fs.statSync(templateFilePath)
if (stats.isDirectory()) {
fs.mkdirSync(destFilePath, { recursive: true });
copyTemplateFiles(templateFilePath, destFilePath);
} else {
// Replace placeholders in the file name
destFilePath = destFilePath.replace(/{{name}}/g, pluginName);
if (stats.isDirectory()) {
fs.mkdirSync(destFilePath, { recursive: true })
copyTemplateFiles(templateFilePath, destFilePath)
}
else {
// Replace placeholders in the file name
destFilePath = destFilePath.replace(/\{\{name\}\}/g, pluginName)
let content = fs.readFileSync(templateFilePath, 'utf8');
let content = fs.readFileSync(templateFilePath, 'utf8')
// Replace placeholders in the file content
content = content.replace(/{{name}}/g, pluginName);
content = content.replace(/{{export}}/g, exportNameFull);
// Replace placeholders in the file content
content = content.replace(/\{\{name\}\}/g, pluginName)
content = content.replace(/\{\{export\}\}/g, exportNameFull)
fs.writeFileSync(destFilePath, content);
}
});
fs.writeFileSync(destFilePath, content)
}
})
}
// Create the example file
function createExampleFile() {
const exampleContent = `
const exampleContent = `
// npm i artplayer-plugin-${pluginName}
// import ${exportNameFull} from 'artplayer-plugin-${pluginName}';
@@ -88,18 +90,18 @@ var art = new Artplayer({
}),
],
});
`.trim();
`.trim()
if (!fs.existsSync(exampleDir)) {
fs.mkdirSync(exampleDir, { recursive: true });
}
if (!fs.existsSync(exampleDir)) {
fs.mkdirSync(exampleDir, { recursive: true })
}
fs.writeFileSync(exampleFile, exampleContent);
console.log(`Example file created at ${exampleFile}`);
fs.writeFileSync(exampleFile, exampleContent)
console.log(`Example file created at ${exampleFile}`)
}
// Start copying template files and creating example file
copyTemplateFiles(templateDir, destDir);
createExampleFile();
copyTemplateFiles(templateDir, destDir)
createExampleFile()
console.log(`Plugin ${pluginName} has been successfully created at ${destDir}`);
console.log(`Plugin ${pluginName} has been successfully created at ${destDir}`)
+22 -22
View File
@@ -1,24 +1,24 @@
{
"license": "MIT",
"version": "1.0.0",
"name": "artplayer-plugin-{{name}}",
"types": "types/artplayer-plugin-{{name}}.d.ts",
"description": "{{name}} plugin for ArtPlayer",
"main": "dist/artplayer-plugin-{{name}}.js",
"legacy": "dist/artplayer-plugin-{{name}}.legacy.js",
"author": "Harvey Zack <laozhaochaguan@gmail.com>",
"browserslist": "last 1 Chrome version",
"homepage": "https://artplayer.org",
"repository": {
"type": "git",
"url": "git+https://github.com/zhw2590582/ArtPlayer.git"
},
"bugs": {
"url": "https://github.com/zhw2590582/ArtPlayer/issues"
},
"keywords": [
"html5",
"video",
"player"
]
"name": "artplayer-plugin-{{name}}",
"version": "1.0.0",
"description": "{{name}} plugin for ArtPlayer",
"author": "Harvey Zack <laozhaochaguan@gmail.com>",
"license": "MIT",
"homepage": "https://artplayer.org",
"repository": {
"type": "git",
"url": "git+https://github.com/zhw2590582/ArtPlayer.git"
},
"bugs": {
"url": "https://github.com/zhw2590582/ArtPlayer/issues"
},
"keywords": [
"html5",
"video",
"player"
],
"main": "dist/artplayer-plugin-{{name}}.js",
"types": "types/artplayer-plugin-{{name}}.d.ts",
"legacy": "dist/artplayer-plugin-{{name}}.legacy.js",
"browserslist": "last 1 Chrome version"
}