Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: svg sprite generation #1

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
vjs-sprite-tmp_*

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to include dist in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, yes, in order to replace the player.js import with the file generated by this project. A bit like videojs-icons.css

1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm run lint
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.20.3
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright Brightcove, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
86 changes: 86 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#! /usr/bin/env node

import process from 'process';
import path from 'path';
import fs from 'fs';
// meh https://github.com/yargs/yargs/issues/1854#issuecomment-787509517
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { generateSvgSprite, parseConfigFile } from '../src/vjs-sprite.js';
import svgConfigTemplate from '../template/svg.config.file.js';

// eslint-disable-next-line no-unused-expressions
yargs(hideBin(process.argv))
.scriptName('vjs-svg-sprite')
.usage('$0 <command> [argument]')

.command({
command: 'create [configFile]',
describe: 'create a config file',
builder: {
configFile: {
type: 'string',
describe: 'the config file used to build the svg sprite',
default: 'vjs-icons-config.json'
}
},
handler: (argv) => {
const configFile = path.join(process.cwd(), argv.configFile);
const configTemplate = JSON.stringify(svgConfigTemplate, null, 2);

fs.writeFileSync(configFile, configTemplate);
}
})

.command({
command: 'generate [configFile]',
describe: 'generate the svg sprite',
builder: {
configFile: {
type: 'string',
demandOption: true,
describe: 'the config file used build the svg sprite'
},
svgSpriteConfigFile: {
type: 'string',
describe: 'the config file that overrides the default svg-sprite configuration'
},
svgoConfigFile: {
type: 'string',
describe: 'the config file that overrides the default svgo configuration applied to each icon'
},
svgoCleanSpriteConfigFile: {
type: 'string',
describe: 'the config file that overrides the default svgo configuration applied to the sprite'
},
debug: {
type: 'boolean',
default: false,
describe: 'activate the debug mode'
}
},
handler: (argv) => {
if (argv.svgSpriteConfigFile) {
throw new Error('svgSpriteConfigFile is not implemented yet');
}

if (argv.svgoConfigFile) {
throw new Error('svgoConfigFile is not implemented yet');
}

if (argv.svgoCleanSpriteConfigFile) {
throw new Error('svgoCleanSpriteConfigFile is not implemented yet');
}

if (argv.debug) {
throw new Error('debug is not implemented yet');
}

const configFile = path.join(process.cwd(), argv.configFile);
const svgIconsConfig = parseConfigFile(configFile);

generateSvgSprite(process.cwd(), svgIconsConfig);
}
})
.help()
.argv;
560 changes: 560 additions & 0 deletions dist/index.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/vjs-sprite-icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading