Skip to content

Commit

Permalink
feat: support libraries, via @videojs/babel-config (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored Nov 2, 2020
1 parent c2cf32c commit 5dddda0
Show file tree
Hide file tree
Showing 13 changed files with 5,596 additions and 6,383 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
dist: xenial
language: node_js
node_js:
- 10
- 12
- 14
# node version is specified using the .nvmrc file
cache: npm
before_install:
Expand Down
1 change: 1 addition & 0 deletions generators/app/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = {
prepush: false,
precommit: true,
lang: true,
library: false,
license: LICENSE_DEFAULT,
pluginType: 'advanced',
name: path.basename(process.cwd()).replace(/^videojs-/, '')
Expand Down
12 changes: 6 additions & 6 deletions generators/app/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ module.exports = class extends Generator {
name: 'lang',
message: 'Do you need video.js language file infrastructure for internationalized strings?',
default: defaults.lang
}, {
type: 'confirm',
name: 'library',
message: 'Do you want to every file in ./src available for use as ./cjs and ./es in other packages?',
default: defaults.library
}, {
type: 'confirm',
name: 'precommit',
Expand Down Expand Up @@ -349,12 +354,7 @@ module.exports = class extends Generator {
return;
}

// if we are on npm greater than 6
// save time by updating package-lock-only
// and then running npm ci
spawnSync('npm', ['i', '--package-lock-only'], {stdio: 'inherit', cwd: this.destinationRoot()});
spawnSync('npm', ['ci'], {stdio: 'inherit', cwd: this.destinationRoot()});

spawnSync('npm', ['i', '--prefer-offline', '--no-audit', '--progress=false'], {stdio: 'inherit', cwd: this.destinationRoot()});
}

/**
Expand Down
37 changes: 26 additions & 11 deletions generators/app/package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const packageJSON = (current, context) => {
'description': context.description,
'main': scriptify('dist/%s.cjs.js'),
'module': scriptify('dist/%s.es.js'),

'browser': scriptify('dist/%s.js'),
'generator-videojs-plugin': {
version: generatorVersion()
},
Expand All @@ -129,7 +129,7 @@ const packageJSON = (current, context) => {
'build-prod': "cross-env-shell NO_TEST_BUNDLE=1 'npm run build'",
'build': 'npm-run-all -s clean -p build:*',
'build:js': 'rollup -c scripts/rollup.config.js',
'clean': 'shx rm -rf ./dist ./test/dist && shx mkdir -p ./dist ./test/dist',
'clean': 'shx rm -rf ./dist ./test/dist ./cjs ./es && shx mkdir -p ./dist ./test/dist ./cjs ./es',
'lint': 'vjsstandard',
'prepublishOnly': 'npm-run-all build-prod && vjsverify --verbose',
'start': 'npm-run-all -p server watch',
Expand Down Expand Up @@ -157,6 +157,8 @@ const packageJSON = (current, context) => {

'vjsstandard': {
ignore: [
'es',
'cjs',
'dist',
'docs',
'test/dist'
Expand All @@ -166,6 +168,8 @@ const packageJSON = (current, context) => {
'files': [
'CONTRIBUTING.md',
'dist/',
'es/',
'cjs/',
'docs/',
'index.html',
'scripts/',
Expand All @@ -179,14 +183,8 @@ const packageJSON = (current, context) => {
}
},
'lint-staged': {
'*.js': [
'vjsstandard --fix',
'git add'
],
'README.md': [
'doctoc --notitle',
'git add'
]
'*.js': 'vjsstandard --fix',
'README.md': 'doctoc --notitle'
},

'dependencies': _.assign({}, current.dependencies, DEFAULTS.dependencies),
Expand Down Expand Up @@ -221,7 +219,7 @@ const packageJSON = (current, context) => {

_.assign(result.scripts, {
'docs': 'npm-run-all docs:*',
'docs:api': 'jsdoc src -g plugins/markdown -r -d docs/api',
'docs:api': 'jsdoc src -r -d docs/api',
'docs:toc': 'doctoc --notitle README.md'
});

Expand Down Expand Up @@ -249,6 +247,23 @@ const packageJSON = (current, context) => {
_.assign(result.devDependencies, getGeneratorVersions(['videojs-languages']));
}

if (context.library) {
result.main = 'cjs/plugin.js';
result.module = 'es/plugin.js';

_.assign(result.devDependencies, getGeneratorVersions([
'@babel/cli',
'@videojs/babel-config'
]));

_.assign(result.scripts, {
'build:cjs': 'babel-config-cjs -d ./cjs ./src',
'build:es': 'babel-config-es -d ./es ./src',
'watch:cjs': 'npm run build:cjs -- -w',
'watch:es': 'npm run build:es -- -w'
});
}

result.files.sort();
result.scripts = alphabetizeScripts(result.scripts);
result.dependencies = alphabetizeObject(result.dependencies);
Expand Down
2 changes: 2 additions & 0 deletions generators/app/templates/_.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ node_modules/

# Build-related directories
dist/
es/
cjs/
docs/api/
test/dist/
.eslintcache
Expand Down
8 changes: 7 additions & 1 deletion generators/app/templates/scripts/_rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ const options = {};
const config = generate(options);

// Add additonal builds/customization here!

<% if (library) { %>
// do not build module dists with rollup
// this is handled by build:es and build:cjs
if (config.builds.module) {
delete config.builds.module;
}
<% } %>
// export the builds to rollup
export default Object.values(config.builds);
Loading

0 comments on commit 5dddda0

Please sign in to comment.