ant-app-builder
Advanced tools
Comparing version 1.2.8 to 1.3.0
@@ -10,2 +10,3 @@ | ||
const buildFileLimit = 1024 * 1024 * 5 | ||
const ant_require_rx = /ant_require\(['"](.+?)['"]\)/g | ||
@@ -19,2 +20,59 @@ | ||
const buildTasks = async (appXmlDom, appPath, id, namespace, uglify) => { | ||
const xApp = appXmlDom.Application | ||
if (!xApp.Build || !xApp.Build.task) return | ||
let buildTasks = xApp.Build.task | ||
if (buildTasks.constructor !== Array) buildTasks = [buildTasks] | ||
return Promise.all(buildTasks.map(async task => { | ||
let input = FS.path.join(appPath, task._attributes.source) | ||
let dest = FS.path.join(appPath, task._attributes.destination) | ||
let destDir = FS.path.dirname(dest) | ||
let ant_require = async function(baseDir, reqStr, exclude) { | ||
let reqPath = FS.path.join(baseDir, reqStr.slice(13,-2)) | ||
if (!await FS.fileExists(reqPath)) return | ||
let reqFile = await FS.readFile(reqPath) | ||
let rx = new RegExp(reqStr.replace(/(\(|\))/g, "\\$1"), "i") | ||
code = code.replace(rx, reqFile) | ||
let requires = code.match(ant_require_rx) || [] | ||
if (exclude) { | ||
requires = requires.filter(i => exclude.indexOf(i)) | ||
} | ||
if (requires.length) { | ||
let reqDir = FS.path.dirname(reqPath) | ||
await Promise.all(requires.map(async item => ant_require(reqDir, item, requires))) | ||
} | ||
} | ||
// rollup.js | ||
let bundle = await rollup.rollup({ input, treeshake: false }) | ||
let { output } = await bundle.generate({ format: "esm" }) | ||
// custom require-parser | ||
let code = output[0].code | ||
let requires = code.match(ant_require_rx) || [] | ||
let reqDir = FS.path.dirname(input) | ||
await Promise.all(requires.map(async item => ant_require(reqDir, item))) | ||
// fix paths to app public folder | ||
code = code.replace(/(['"])~\/(.+?)(['"])/g, `$1/app/${namespace}/${id}/$2$3`) | ||
// terser.js | ||
const options = { compress: true, module: true } | ||
const parsed = terser.minify(code, options) | ||
// create destination dir, if it doesnt exist | ||
if (!await FS.fileExists(destDir)) { | ||
await FS.mkDir(destDir) | ||
} | ||
await FS.writeFile(dest, uglify ? parsed.code : code) | ||
})) | ||
} | ||
// ** Compiles javascript | ||
@@ -26,7 +84,8 @@ const compileScript = async (meta, appPath, uglify) => { | ||
const dirPath = FS.path.dirname(filePath) | ||
const regexp = /require\(['"](.+?)['"]\)/g | ||
// reqursive file "require" | ||
// reqursive file "ant_require" | ||
const requireFile = async function(baseDir, reqStr, exclude) { | ||
let reqPath = FS.path.join(baseDir, reqStr.slice(9,-2)) | ||
let reqPath = FS.path.join(baseDir, reqStr.slice(13,-2)) | ||
if (!await FS.fileExists(reqPath)) return | ||
let reqFile = await FS.readFile(reqPath) | ||
@@ -36,3 +95,3 @@ let rx = new RegExp(reqStr.replace(/(\(|\))/g, "\\$1"), "i") | ||
let requires = code.match(regexp) || [] | ||
let requires = code.match(ant_require_rx) || [] | ||
if (exclude) { | ||
@@ -48,8 +107,8 @@ requires = requires.filter(i => exclude.indexOf(i)) | ||
// rollup.js | ||
const bundle = await rollup.rollup({ input: filePath, treeshake: false }) | ||
const { output } = await bundle.generate({ format: "esm" }) | ||
let bundle = await rollup.rollup({ input: filePath, treeshake: false }) | ||
let { output } = await bundle.generate({ format: "esm" }) | ||
// custom require-parser | ||
let code = output[0].code | ||
let requires = code.match(regexp) || [] | ||
let requires = code.match(ant_require_rx) || [] | ||
// loop all requires | ||
@@ -212,3 +271,4 @@ await Promise.all(requires.map(async item => requireFile(dirPath, item))) | ||
const appJson = convert.xml2json(appXml, { compact: true }) | ||
const meta = JSON.parse(appJson).Application.Head.meta | ||
const appXmlDom = JSON.parse(appJson) | ||
const meta = appXmlDom.Application.Head.meta | ||
const appId = getMetaValue(meta, "id") | ||
@@ -218,3 +278,7 @@ const name = getMetaValue(meta, "title") | ||
const buildInclude = (getMetaValue(meta, "build", "include") || "").split(",") | ||
const namespace = getMetaValue(meta, "author", "namespace") | ||
// perform build tasks - if any | ||
await buildTasks(appXmlDom, srcDir, appId, namespace, uglify); | ||
return; | ||
let scriptCompiled = await compileScript(meta, srcDir, uglify) || "" | ||
@@ -221,0 +285,0 @@ let styleCompiled = await compileStyle(meta, srcDir) || "" |
{ | ||
"name": "ant-app-builder", | ||
"version": "1.2.8", | ||
"version": "1.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./lib", |
@@ -7,3 +7,3 @@ | ||
let destDir = path.join(__dirname, "temp/_build") | ||
let uglify = true | ||
let uglify = false | ||
@@ -10,0 +10,0 @@ let runIt = async() => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49939
377