Converts namespaced JavaScript code to CommonJS modules.
This:
caplin.grid.GridView = function() {
this._scrollView = new caplin.grid.ScrollPane();
}will be converted to:
'use strict';
var ScrollPane = require('caplin/grid/ScrollPane');
function GridView() {
this._scrollView = new ScrollPane();
}
module.exports = GridView;Also adds requires for specified globals i.e. jQuery.on(...) will add a
var jQuery = require('jQuery') statement if not already present in the code.
node v6 or higher.
Either install it globally:
$ npm i -g caplin/gc-clior clone this repository, cd into it and run
$ npm linkOnce installed cd into a directory with a src subdirectory (a blade,
bladeset, lib or aspect) and run.
$ gc-cliThis will format all *.js files in the src directory.
Convert one blade, bladeset, lib, aspect src at a time, then run tests, verify
the application is working and perform smoke tests. git checkout . will revert
the changes. Don't get bogged down on one conversion too long, move to another
one if the conversion is not straightforward. Do not work on converted code
without commiting the code locally or it will be difficult to keep track of your
own changes versus the automated ones. The tests do not need to be converted
namespaced tests can still test converted CJS code. Perform a code diff to
verify the conversion looks reasonable.
To convert JS patches cd into js-patches and run
$ gc-cli --outputDirectory=. "**/*.js"You can modify the default options using these options:
--namespacesor-ncomma separated list of namespace roots to convert to CJS.
$ gc-cli --namespaces caplin,caplinx,br,yournamespaceroot--compileTestFilesor-tconverttests, use a transform pipeline configured for tests.
$ gc-cli --compileTestFilesRaise any issues, feature requests in this repository or create a PR for them.
Inside this repo
$ npm t
