extendscript-bundlr
Version:
a tool for bundling Adobe ExtendScripts that use the `#include 'path/to/file'` statement
89 lines (78 loc) • 2.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.matcher = matcher;
exports.cleaner = cleaner;
exports.tildetest = tildetest;
exports.detectEdgecase = detectEdgecase;
var _reporter = require('./reporter');
var regexIncludepath = /^.*?[\/\/.*?@|#].*?includepath["|']?(.+)["|']?/;
var regexInclude = /^.*?[\/\/.*?@|#].*?include(?!path)["|']?(.+)["|']?/;
var basilEdgeCase = /^.*?;.*?\%/;
function matcher(str) {
var regexes = [regexIncludepath, regexInclude];
var obj = { path: null, isIncludePath: null, src: str };
var foundSomething = false;
for (var i = 0; i < regexes.length; i++) {
var res = str.match(regexes[i]);
if (res !== null) {
foundSomething = true;
if (i === 0) {
if (global.verbose) console.log((0, _reporter.woohoo)('\n------ INCLUDEPATHS ------'));
obj.isIncludePath = true;
} else {
if (global.verbose) console.log((0, _reporter.woohoo)('\n------ INCLUDES ------'));
}
if (global.verbose) console.log((0, _reporter.say)('[MATCH RESULT]:'), (0, _reporter.say)(JSON.stringify(res, null, 2)));
obj.path = res[1];
}
}
return foundSomething === true ? obj : null;
}
function cleaner(str) {
str = str.replace(/["|\\"|\'|\\'|;]/g, '');
return str.trim();
}
function tildetest(str) {
var res = cleaner(str).match(/\~/g);
return res !== null ? true : false;
}
function detectEdgecase(str) {
var res = str.match(basilEdgeCase);
return res !== null ? true : false;
}
// let verex = require('verbal-expressions');
// export const includepathRegExp = /([\/\/.*?@|#].*?includepath.*?)[\\n|\\r]/i;
// export let testerAT = verex()
// .then('//')
// .maybe(' ')
// .then('@include')
// .maybe(' ')
// .then('\'')
// .or('"')
// .anything()
// .then('\'')
// .or('"')
// .maybe(';')
// .anything();
// export let testerHASH = verex()
// .then('#')
// .then('include')
// .maybe(' ')
// .then('\'')
// .or('"')
// .anything()
// .then('\'')
// .or('"')
// .maybe(';')
// .anything();
// export let testerIncludeAT = verex()
// .then('//')
// .maybe(' ')
// .then('@includepath')
// .anything();
// export let testerIncludeHASH = verex()
// .then('#')
// .then('includepath')
// .anything();