Skip to content

Instantly share code, notes, and snippets.

@unlocomqx
Created July 30, 2018 12:28
Show Gist options
  • Save unlocomqx/ee0de6e6b3f03dfd64f2938da0b8de4f to your computer and use it in GitHub Desktop.
Save unlocomqx/ee0de6e6b3f03dfd64f2938da0b8de4f to your computer and use it in GitHub Desktop.
/* Angular lib automated publish to git remote */
// the dist/new-lib folder is your git repo
// git init && git remote add origin <remote_url>
// add the following scripts to the package.json inside lib folder projects/new-lib
/*
"scripts": {
"publish": "npm version patch && npm run clean && npm run build && npm run release",
"clean": "cd ../../dist/new-lib && ls -a -I \".git\" | xargs rm -rf || true",
"build": "ng build --prod new-lib",
"release": "node publish.js"
},
*/
// add "deleteDestPath": false, to projects/new-lib/ng-package.prod.json
// remove dist from .gitignore
// copy the following script to projects/new-lib/publish.js
// add this script to the package.json file in the root
/*
"publish": "cd projects/new-lib && npm run publish"
*/
// npm install -D simple-git
// npm run publish
const path = require('path');
const dist_dir = '../../dist/new-lib';
const root_dir = '../../';
const simpleGit = require('simple-git')(dist_dir);
// simpleGit.add(`${dist_dir}/*`); // add only dist/new-lib/*
simpleGit.add('.'); // add all files
const package = require(path.join(dist_dir, 'package.json'));
const version = package.version;
simpleGit.commit(`version ${version}`);
simpleGit.addTag(`v${version}`);
console.log(`Pushing version ${version} to remote`);
simpleGit.push();
simpleGit.pushTags();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment