* 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:
Harvey Zhao authored and GitHub committed 2024-06-02 12:28:17 +08:00
1 parent b398749ef8
commit fac7d15726
24 files changed
+703 -296

No files matched your search

+65
View File
@@ -0,0 +1,65 @@
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
// Get the current file path
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];
if (!pluginName) {
console.error('Please provide a plugin name, e.g., npm run create:plugin somePluginName');
process.exit(1);
}
// Define paths
const templateDir = path.join(__dirname, 'template');
const destDir = path.join(__dirname, '../../packages', `artplayer-plugin-${pluginName}`);
// 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);
}
// Create the destination directory
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);
files.forEach((file) => {
const templateFilePath = path.join(templateDir, file);
let destFilePath = path.join(destDir, file);
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);
let content = fs.readFileSync(templateFilePath, 'utf8');
// Replace placeholders in the file content
content = content.replace(/{{name}}/g, pluginName);
content = content.replace(
/{{export}}/g,
`artplayerPlugin${pluginName.charAt(0).toUpperCase() + pluginName.slice(1)}`,
);
fs.writeFileSync(destFilePath, content);
}
});
}
// Start copying template files
copyTemplateFiles(templateDir, destDir);
console.log(`Plugin ${pluginName} has been successfully created at ${destDir}`);
+11
View File
@@ -0,0 +1,11 @@
# artplayer-plugin-{{name}}
{{name}} plugin for ArtPlayer
## Demo
[https://artplayer.org](https://artplayer.org/?libs=./uncompiled/artplayer-plugin-{{name}}/index.js&example={{name}})
## License
MIT © Harvey Zack
+24
View File
@@ -0,0 +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"
]
}
+26
View File
@@ -0,0 +1,26 @@
import style from 'bundle-text:./style.less';
export default function {{export}}(option) {
return (art) => {
return {
name: '{{export}}',
};
};
}
if (typeof document !== 'undefined') {
const id = 'artplayer-plugin-{{name}}';
const $style = document.getElementById(id);
if ($style) {
$style.textContent = style;
} else {
const $style = document.createElement('style');
$style.id = id;
$style.textContent = style;
document.head.appendChild($style);
}
}
if (typeof window !== 'undefined') {
window['{{export}}'] = {{export}};
}
+3
View File
@@ -0,0 +1,3 @@
.artplayer-plugin-{{name}} {
//
}
@@ -0,0 +1,14 @@
import type Artplayer from 'artplayer';
export = {{export}};
export as namespace {{export}};
type Option = {
//
};
type Result = {
name: '{{export}}';
};
declare const {{export}}: (option: Option) => (art: Artplayer) => Result;