Skip to content

Commit

Permalink
Create a script for publishing (fabricjs#5786)
Browse files Browse the repository at this point in the history
The script temporarily overrides package.json contents with `optionalDependencies: {}` and `version: 'FABRIC_VERSION-browser'`, publishes it, restores the original package.json and publishes the main version. 
It can be run with `node publish` and it also supports original `npm publish` parameters: `node publish --dry-run`. 
The file is eslinted with .eslintrc.json. Closes fabricjs#5735.
  • Loading branch information
finom authored and asturur committed Jul 2, 2019
1 parent 2038c72 commit bc29917
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions publish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var cp = require('child_process');
var path = require('path');
var fs = require('fs');

// eslint-disable-next-line no-undef
var pkgPath = path.resolve(__dirname, './package.json');
var pkgText = fs.readFileSync(pkgPath); // get original pkg text to restore it later
var pkgObject = JSON.parse(pkgText); // parsed pkg to override its fields
var args = process.argv.slice(2).join(' '); // args will be passed to npm publish (like --dry-run)

// override package.json with updated fields
fs.writeFileSync(
pkgPath,
JSON.stringify(Object.assign(pkgObject, {
optionalDependencies: {},
version: pkgObject.version + '-browser',
}), null, '\t')
);

// publish -browser version
cp.execSync('npm publish ' + args);

console.log('Browser package is published');

// restore the original package.json contents
fs.writeFileSync(pkgPath, pkgText);

// publish the main version (the package is published "above" the -browser version)
cp.execSync('npm publish ' + args);

console.log('Main package is published');

0 comments on commit bc29917

Please sign in to comment.