Giter Club home page Giter Club logo

pkg-upgrader's Introduction

pkg-upgrader

Forked from lib-upgrader props to @jfmengels for starting this cool tool.

Codemods, or jscodeshift transforms, are small programs that help automate changes in a codebase. Think of them as search and replace on steroids. This tool helps you to create a simple CLI to apply the codemods that you wrote, so that users can easily upgrade their code between various releases of your library.

Install

$ yarn add pkg-upgrader jscodeshift

Usage

Create a cli.js file at the root of your project that will serve as your upgrader executable, and add this sample code (sample available here):

#!/usr/bin/env node

import upgrader from 'pkg-upgrader';
import pkg from './package.json';
import releases from './releases.json';

var settings = {
	libraryName: 'Your library name',
	releases: releases,
	pkg: pkg,
	dirname: __dirname
};

upgrader.handleCliArgs(settings)
	.then(upgrader.checkForUpdates)
	.then(upgrader.checkGitIsClean)
	.then(upgrader.prompt)
	.then(upgrader.applyCodemods)
	.then(upgrader.printTip)
	.catch(function (err) {
		console.error(err.message);
		process.exit(1);
	});

and create a releases.json file next to cli.js, which looks like the following (sample available here):

[{
	"version": "0.14.0",
	"transforms": [
		"path/to/transform/a.js",
		"path/to/transform/b.js"
	]
}, {
	"version": "0.15.0",
	"transforms": [
		"path/to/transform/c.js",
		"path/to/transform/d.js"
	]
}, {
	"version": "1.0.0",
	"transforms": [
		"path/to/transform/e.js",
		"path/to/transform/f.js"
	]
}, {
	"version": "2.0.0",
	"transforms": [
		"path/to/transform/g.js",
		"path/to/transform/h.js"
	]
}]

Give execution right to your script

chmod +x script

and you should now be able to run the cli using

./cli.js

Unless you committed your changes and your directory is clean, when you run it, the program will exit and ask you to either commit or stash your changes. You can force through it by adding --force to the command line.

License

MIT © Ben Monro MIT © Jeroen Engels

pkg-upgrader's People

Contributors

benmonro avatar greg-a-smith avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.