From 924c3513e845914b867a19f725f1c982c3e0ff19 Mon Sep 17 00:00:00 2001 From: Harvey Zack Date: Sun, 2 Jun 2024 12:45:54 +0800 Subject: [PATCH] Update create.js --- scripts/plugin/create.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/scripts/plugin/create.js b/scripts/plugin/create.js index ab37846f0..399946d7b 100644 --- a/scripts/plugin/create.js +++ b/scripts/plugin/create.js @@ -18,6 +18,8 @@ if (!pluginName) { // 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 exampleFile = path.join(exampleDir, `${pluginName}.js`); // Check if a plugin with the same name already exists if (fs.existsSync(destDir)) { @@ -59,7 +61,34 @@ function copyTemplateFiles(templateDir, destDir) { }); } -// Start copying template files +// Create the example file +function createExampleFile() { + const exportName = `artplayerPlugin${pluginName.charAt(0).toUpperCase() + pluginName.slice(1)}`; + const exampleContent = ` +// npm i artplayer-plugin-${pluginName} +// import ${exportName} from 'artplayer-plugin-${pluginName}'; + +var art = new Artplayer({ + container: '.artplayer-app', + url: '/assets/sample/video.mp4', + plugins: [ + ${exportName}({ + // + }), + ], +}); + `.trim(); + + if (!fs.existsSync(exampleDir)) { + fs.mkdirSync(exampleDir, { recursive: true }); + } + + fs.writeFileSync(exampleFile, exampleContent); + console.log(`Example file created at ${exampleFile}`); +} + +// Start copying template files and creating example file copyTemplateFiles(templateDir, destDir); +createExampleFile(); console.log(`Plugin ${pluginName} has been successfully created at ${destDir}`);