The PlayKit JS Plugin Generator
creates the files and folders needed to create a conventional plugin. It includes a test environment so that you can easily see your changes as you develop your plugin. It even generates the final plugin files that you can use when you are ready to release it.
PlayKit JS Plugin Generator
uses the playkit-js
repos conventions:
- Written in
ECMAScript6
. - Statically analysed using
Flow
. - Transpiled in
ECMAScript5
usingBabel
. - Bundled using
Webpack
. - Runs tests using
Karma
&Mocha
. - Using
Yarn
as a package manager for your code. - Using
standard-version
to release and automate versions releases.
PlayKit JS Plugin Generator
generates the following project structure:
- src
- index.html
- index.js
- plugin.js
- test
- setup
- karma.js
- load-specs.js
- prepare-test-environment.js
- src
- plugin.spec.js
- .eslintrc.json
- .babelrc
- .editorconfig
- .eslintrc.json
- .flowconfig
- .gitignore
- .travis.yml
- karma.conf.js
- package.json
- README.md
- webpack.config.js
- Create a local folder on your computer. For this example, we will create one named playkit-js-my-plugin. This is where the generator files and your plugin files will go.
- Install Yeoman and
generator-playkit-js-plugin
using npm (we assume you have pre-installed node.js).
npm install -g yo
npm install -g generator-playkit-js-plugin
- Install Yarn globally on your machine.
- Open the Terminal app in the folder you created in a previous step. For this example, open the Terminal app in the playkit-js-my-plugin folder.
- In the Terminal app, run the following command:
yo playkit-js-plugin
- You will see the following output:
Dans-MacBook-Pro:playkit-js-my-plugin dan.ziv$ yo playkit-js-plugin
? Your plugin name? (my-plugin-name)
- Enter a comma separated plugin name. For example, if you want to call your plugin class MyPlugin, enter my-plugin. Finally click Enter.
Dans-MacBook-Pro:playkit-js-my-plugin dan.ziv$ yo playkit-js-plugin
? Your plugin name? my-plugin
create package.json
create .babelrc
create .editorconfig
create .eslintrc.json
create .flowconfig
create .gitignore
create karma.conf.js
create .travis.yml
create test/setup/karma.js
create test/setup/load-specs.js
create test/setup/prepare-test-environment.js
create test/.eslintrc.json
create README.md
create webpack.config.js
create src/my-plugin.js
create src/index.js
create test/src/my-plugin.spec.js
yarn install v1.3.2
info No lockfile found.
[1/4] 🔍 Resolving packages...
Yarn
installation of project dependencies will start automatically.
Now your environment is ready to go and you can start develop your plugin!
In terminal app, under your project path, run the following command:
yarn run test
Note that if you're using an IDE such as WebStorm or VSCode you can simply run this scripts via there.
In terminal app, under your project path, run the following command:
yarn run flow
In terminal app, under your project path, run the following command:
yarn run eslint
In terminal app, under your project path, run the following command:
yarn run build
In the test/src/plugin.spec.js file.
Of course you can add and use any other files that you wish.
Note that depends on our Karma config the test files should postfix with .spec so that Karma will include them when running the tests.
- Build your project as explained above (Observe a /dist folder has been created in your project).
- Open the src/index.html file.
- In index.html, add a script tag referring to your player library.
...
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="PATH/TO/PLAYER/LIB/FILENAME.js"></script>
<script src="./playkit-my-plugin.js"></script>
</head>
....
- In terminal app, under your project path, run the following command:
yarn run dev
- Observe on which port the webpack-dev-server is opened (usually on 8080).
- Open browser on localhost:XXXX
If your player file is locally on your machine, you'll need to manipulate and edit the webpack.config.js file.
- Copy & paste your player file to wherever you want in your project. Let's say we paste it under /src folder.
- In index.html, add a script tag referring to your player library. Set the path as
src='./FILENAME.js'
.
...
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="./FILENAME.js"></script>
<script src="./playkit-my-plugin.js"></script>
</head>
....
- Go to webpack.config.js file, and observe the following code in line 16:
if (PROD) {
plugins.push(new webpack.optimize.UglifyJsPlugin({sourceMap: true}));
} else {
plugins.push(new CopyWebpackPlugin([{
from: '',
to: '.'
}]));
}
Change it to:
if (PROD) {
plugins.push(new webpack.optimize.UglifyJsPlugin({sourceMap: true}));
} else {
plugins.push(new CopyWebpackPlugin([{
from: '../src/FILENAME.js',
to: '.'
}]));
}
- In terminal app, under your project path, run the following command:
yarn run dev
- Observe on which port the webpack-dev-server is opened (usually on 8080).
- Open browser on localhost:XXXX