From 6fbe956653d35f5352ed27212c2402c55c91cbe8 Mon Sep 17 00:00:00 2001 From: Josep Boix Requesens Date: Mon, 29 Apr 2024 14:55:52 +0200 Subject: [PATCH] feat: add element type prompt and adapt templates - Added a new prompt in the `create` script to enable users to specify whether they want to generate a new component, plugin, or button. - Adapted the existing templates to correctly produce the type of element selected by the user. - Migrated the functionality of the skip-button-plugin into a simpler component format. --- docs/README.md | 2 +- package.json | 2 +- .../src/skip-button-plugin.js | 28 --------- .../test/skip-button-plugin.spec.js | 31 ---------- .../.babelrc | 0 .../README.md | 15 +++-- .../index.html | 10 +-- .../package.json | 14 ++--- .../rollup.config.js | 24 +++---- .../scss/skip-button.scss} | 0 .../src/lang/de.json | 0 .../src/lang/en.json | 0 .../src/lang/fr.json | 0 .../src/lang/index.js | 0 .../src/lang/it.json | 0 .../src/lang/rm.json | 0 .../src/skip-button.js | 0 .../test/skip-button.spec.js | 0 .../vitest.config.js | 0 scripts/create-plugin.js | 26 -------- scripts/create.js | 45 ++++++++++++++ .../src/{{kebabCase name}}.js.hbs | 27 -------- .../{plugin-template => template}/.babelrc | 0 .../README.md.hbs | 10 ++- .../index.html.hbs | 10 ++- .../package.json.hbs | 0 .../rollup.config.js.hbs | 0 .../scss/{{kebabCase name}}.scss.hbs | 0 .../src/lang/de.json | 0 .../src/lang/en.json | 0 .../src/lang/fr.json | 0 .../src/lang/index.js | 0 .../src/lang/it.json | 0 .../src/lang/rm.json | 0 .../template/src/{{kebabCase name}}.js.hbs | 62 +++++++++++++++++++ .../test/{{kebabCase name}}.spec.js.hbs | 10 +++ .../vitest.config.js | 0 37 files changed, 164 insertions(+), 152 deletions(-) delete mode 100644 plugins/skip-button-plugin/src/skip-button-plugin.js delete mode 100644 plugins/skip-button-plugin/test/skip-button-plugin.spec.js rename plugins/{skip-button-plugin => skip-button}/.babelrc (100%) rename plugins/{skip-button-plugin => skip-button}/README.md (81%) rename plugins/{skip-button-plugin => skip-button}/index.html (82%) rename plugins/{skip-button-plugin => skip-button}/package.json (59%) rename plugins/{skip-button-plugin => skip-button}/rollup.config.js (70%) rename plugins/{skip-button-plugin/scss/skip-button-plugin.scss => skip-button/scss/skip-button.scss} (100%) rename plugins/{skip-button-plugin => skip-button}/src/lang/de.json (100%) rename plugins/{skip-button-plugin => skip-button}/src/lang/en.json (100%) rename plugins/{skip-button-plugin => skip-button}/src/lang/fr.json (100%) rename plugins/{skip-button-plugin => skip-button}/src/lang/index.js (100%) rename plugins/{skip-button-plugin => skip-button}/src/lang/it.json (100%) rename plugins/{skip-button-plugin => skip-button}/src/lang/rm.json (100%) rename plugins/{skip-button-plugin => skip-button}/src/skip-button.js (100%) rename plugins/{skip-button-plugin => skip-button}/test/skip-button.spec.js (100%) rename plugins/{skip-button-plugin => skip-button}/vitest.config.js (100%) delete mode 100644 scripts/create-plugin.js create mode 100644 scripts/create.js delete mode 100644 scripts/plugin-template/src/{{kebabCase name}}.js.hbs rename scripts/{plugin-template => template}/.babelrc (100%) rename scripts/{plugin-template => template}/README.md.hbs (87%) rename scripts/{plugin-template => template}/index.html.hbs (88%) rename scripts/{plugin-template => template}/package.json.hbs (100%) rename scripts/{plugin-template => template}/rollup.config.js.hbs (100%) rename scripts/{plugin-template => template}/scss/{{kebabCase name}}.scss.hbs (100%) rename scripts/{plugin-template => template}/src/lang/de.json (100%) rename scripts/{plugin-template => template}/src/lang/en.json (100%) rename scripts/{plugin-template => template}/src/lang/fr.json (100%) rename scripts/{plugin-template => template}/src/lang/index.js (100%) rename scripts/{plugin-template => template}/src/lang/it.json (100%) rename scripts/{plugin-template => template}/src/lang/rm.json (100%) create mode 100644 scripts/template/src/{{kebabCase name}}.js.hbs rename scripts/{plugin-template => template}/test/{{kebabCase name}}.spec.js.hbs (77%) rename scripts/{plugin-template => template}/vitest.config.js (100%) diff --git a/docs/README.md b/docs/README.md index 95dd7ac..a0c4865 100644 --- a/docs/README.md +++ b/docs/README.md @@ -45,7 +45,7 @@ npm install Open your terminal and execute the following command: ```bash -npm run create:plugin +npm run create ``` After running the command, you will be prompted to enter the name of your plugin. A new plugin diff --git a/package.json b/package.json index 86ec182..c5b2e8b 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "themes/*" ], "scripts": { - "create:plugin": "plop --plopfile scripts/create-plugin.js", + "create": "plop --plopfile scripts/create.js", "eslint": "eslint {plugins/**/{src,test}/**/*.{js,jsx},scripts/*.{js,jsx}}", "outdated": "npm outdated", "prepare": "husky", diff --git a/plugins/skip-button-plugin/src/skip-button-plugin.js b/plugins/skip-button-plugin/src/skip-button-plugin.js deleted file mode 100644 index 6d766dd..0000000 --- a/plugins/skip-button-plugin/src/skip-button-plugin.js +++ /dev/null @@ -1,28 +0,0 @@ -import pillarbox from '@srgssr/pillarbox-web'; -import SkipButton from './skip-button.js'; - -/** - * @ignore - * @type {typeof import('video.js/dist/types/plugin').default} - */ -const Plugin = pillarbox.getPlugin('plugin'); - -/** - * Represents a SkipButtonPlugin plugin for the pillarbox player. - */ -class SkipButtonPlugin extends Plugin { - /** - * Creates an instance of a SkipButtonPlugin. - * - * @param {import('@srgssr/pillarbox-web').Player} player The player instance. - * @param {Object} options Configuration options for the plugin. - */ - constructor(player, options) { - super(player, options); - this.player.addChild('SkipButton'); - } -} - -pillarbox.registerPlugin('skipButtonPlugin', SkipButtonPlugin); - -export { SkipButtonPlugin, SkipButton }; diff --git a/plugins/skip-button-plugin/test/skip-button-plugin.spec.js b/plugins/skip-button-plugin/test/skip-button-plugin.spec.js deleted file mode 100644 index f69abc9..0000000 --- a/plugins/skip-button-plugin/test/skip-button-plugin.spec.js +++ /dev/null @@ -1,31 +0,0 @@ -import { afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest'; -import pillarbox from '@srgssr/pillarbox-web'; -import { SkipButtonPlugin } from '../src/skip-button-plugin.js'; - -window.HTMLMediaElement.prototype.load = () => {}; - -describe('SkipButtonPlugin', () => { - let player, videoElement; - - beforeAll(() => { - document.body.innerHTML = ''; - videoElement = document.querySelector('#test-video'); - }); - - beforeEach(() => { - player = pillarbox(videoElement, { - plugins: { - skipButtonPlugin: true - } - }); - }); - - afterEach(() => { - player.dispose(); - }); - - it('should be registered and attached to the player', () => { - expect(pillarbox.getPlugin('skipButtonPlugin')).toBe(SkipButtonPlugin); - expect(player.skipButtonPlugin).toBeDefined(); - }); -}); diff --git a/plugins/skip-button-plugin/.babelrc b/plugins/skip-button/.babelrc similarity index 100% rename from plugins/skip-button-plugin/.babelrc rename to plugins/skip-button/.babelrc diff --git a/plugins/skip-button-plugin/README.md b/plugins/skip-button/README.md similarity index 81% rename from plugins/skip-button-plugin/README.md rename to plugins/skip-button/README.md index be013a3..c4eff9c 100644 --- a/plugins/skip-button-plugin/README.md +++ b/plugins/skip-button/README.md @@ -1,7 +1,6 @@ -# Pillarbox Web: SkipButtonPlugin +# Pillarbox Web: SkipButton -> Introduce your plugin with a clear overview of its goals, providing -> essential context and addressing fundamental questions. +A button that allow skipp ## Requirements @@ -11,7 +10,7 @@ To use this component, you need the following installed on your system: ## Quick Start -To get started with this plugin, follow these steps: +To get started with this component, follow these steps: Add the `@srgssr` registry to your `.npmrc` file: @@ -26,18 +25,18 @@ guide: [Authenticating with a personal access token][generate-token] You can now install it through `npm` the following command: ```bash -npm install --save @srgssr/pillarbox-web @srgssr/skip-button-plugin +npm install --save @srgssr/pillarbox-web @srgssr/skip-button ``` For instructions on setting up Pillarbox, see the [Quick Start guide](SRGSSR/pillarbox-web#quick-start). -Once the player is installed you can activate the plugin as follows: +Once the player is installed you can activate the button as follows: ```javascript import Pillarbox from '@srgssr/pillarbox-web'; -import '@srgssr/skip-button-plugin'; +import '@srgssr/skip-button'; -const player = new Pillarbox('my-player', { plugins: { 'skipButtonPlugin': true } }); +const player = new Pillarbox('my-player', { SkipButton: true }); player.src({ src: 'urn:swi:video:48115940', type: 'srgssr/urn' diff --git a/plugins/skip-button-plugin/index.html b/plugins/skip-button/index.html similarity index 82% rename from plugins/skip-button-plugin/index.html rename to plugins/skip-button/index.html index 6d54e1c..361f9fd 100644 --- a/plugins/skip-button-plugin/index.html +++ b/plugins/skip-button/index.html @@ -4,9 +4,9 @@ - SkipButtonPlugin Demo + SkipButton Demo - +