extendscript-bundlr
Version:
a tool for bundling Adobe ExtendScripts that use the `#include 'path/to/file'` statement
103 lines (85 loc) • 3.34 kB
JavaScript
;
var _fs = require('fs');
var fs = _interopRequireWildcard(_fs);
var _path = require('path');
var path = _interopRequireWildcard(_path);
var _package = require('./../package.json');
var _package2 = _interopRequireDefault(_package);
var _reporter = require('./lib/reporter');
var _defaults = require('./lib/defaults');
var _messages = require('./lib/messages');
var _lineWalker = require('./lib/line-walker');
var _osDetect = require('./lib/os-detect');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
var program = require('commander');
var fileExists = require('file-exists');
// const chalk = require('chalk');
var sourcefile = void 0; // will hold the source file path
var targetfile = void 0; // will hold the target file path
// let usesdtout = false; // should output go to stdout
var verbose = false; // write report
global.verbose = false;
global.missing = false;
// let includePaths = [];
// let outputContent = null;
var prefix = '';
// handle input
var input = function input(val) {
// console.log(val);
sourcefile = val;
};
// handle output
var output = function output(val) {
// console.log(val);
targetfile = val;
};
var pre = function pre(val) {
prefix = val;
};
// commander programm
program.version(_package2.default.version).option('-i --input <input>', 'define the source file where the #includes happen', input).option('-o --ouput <ouput>', 'define the target file in which to bundle', output)
// .option('-s --stdout', 'should output to stdout')
.option('-r --report', 'outputs report about the process').option('-m --missing', 'outputs report only for missing files').option('-p --prefix <prefix>', 'add a prefix to your script', pre).parse(process.argv);
// check if the user provided a source file
// if not error end exit
if (!sourcefile) {
console.log((0, _reporter.error)(_messages.messages.nosource));
process.exit();
}
// check if the provided source file exists
if (!fileExists(path.resolve(process.cwd(), sourcefile))) {
console.log((0, _reporter.error)(_messages.messages.sourceDoesNotExist(sourcefile)));
process.exit();
}
// check if there is a target file path
if (!targetfile) {
console.log((0, _reporter.warn)(_messages.messages.notarget));
targetfile = _defaults.defaults.targetfile;
}
// does the user want the report?
if (program.report) {
verbose = true;
global.verbose = true;
}
// does the user want the report mssing files?
if (program.missing) {
// verbose = true;
global.missing = true;
}
// should it go to stdout?
// if (program.stdout) {
// verbose = false;
// usesdtout = true;
// }
if (program.prefix) {
// console.log(prefix);
}
if (fileExists(path.resolve(process.cwd(), targetfile))) {
if (global.verbose) {
console.log((0, _reporter.warn)(_messages.messages.targetexists));
}
}
fs.writeFileSync(path.resolve(process.cwd(), targetfile), '' + prefix + _osDetect.delimiter); // clear the file
(0, _lineWalker.walker)(sourcefile, path.resolve(process.cwd(), targetfile), verbose);