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: support libraries, via @videojs/babel-config #306

Merged
merged 9 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
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 consumption in other packages?',
brandonocasey marked this conversation as resolved.
Show resolved Hide resolved
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()});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the speed of npm i with all of these options is ~20s faster then npm ci

}

/**
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