defiant-builder
Advanced tools
Comparing version 1.5.7 to 1.5.8
@@ -320,3 +320,5 @@ | ||
// ** Builds def-ant application | ||
const Build = (srcDir, destDir, uglify) => { | ||
const Build = options => { | ||
let destDir = options.destination | ||
return new Promise(async (resolve, reject) => { | ||
@@ -329,3 +331,3 @@ let parsed = FS.path.parse(destDir) | ||
let appXml = await FS.readFile(`${srcDir}/index.xml`) | ||
let appXml = await FS.readFile(`${options.source}/index.xml`) | ||
appXml = appXml.toString() | ||
@@ -345,10 +347,10 @@ appXml = appXml.replace(/<Application/, `<Application mDate="${Date.now()}"`) | ||
// perform build tasks - if any | ||
await buildTasks(appXmlDom, srcDir, appId, namespace, uglify); | ||
await buildTasks(appXmlDom, options.source, appId, namespace, options.uglify) | ||
let scriptCompiled = await compileScript(meta, srcDir, uglify) || "" | ||
let styleCompiled = await compileStyle(meta, srcDir) || "" | ||
let xslCompiled = await compileXsl(meta, srcDir) || "" | ||
let contentStores = await getContentStores(meta, srcDir, uglify) || "" | ||
let contentCompiled = await compileContent(meta, srcDir, uglify) || "" | ||
let iconsCompiled = await compileIcons(meta, srcDir) || "" | ||
let scriptCompiled = await compileScript(meta, options.source, options.uglify) || "" | ||
let styleCompiled = await compileStyle(meta, options.source) || "" | ||
let xslCompiled = await compileXsl(meta, options.source) || "" | ||
let contentStores = await getContentStores(meta, options.source, options.uglify) || "" | ||
let contentCompiled = await compileContent(meta, options.source, options.uglify) || "" | ||
let iconsCompiled = await compileIcons(meta, options.source) || "" | ||
@@ -358,3 +360,3 @@ let regexp = /@import ['"](.+?)['"]/mg | ||
await Promise.all(imports.map(async item => { | ||
let importPath = FS.path.join(srcDir, item.slice(9,-1)) | ||
let importPath = FS.path.join(options.source, item.slice(9,-1)) | ||
let importFile = await FS.readFile(importPath) | ||
@@ -376,3 +378,3 @@ let rx = new RegExp(item, "im") | ||
appXml = appXml.replace(/<\/Head>/, replaceHtml) | ||
if (uglify) appXml = appXml.replace(/\n|\t/g, "") | ||
if (options.uglify) appXml = appXml.replace(/\n|\t/g, "") | ||
@@ -387,3 +389,3 @@ // create destination dir, if it doesnt exist | ||
// copy public folder fontent | ||
let srcPublic = FS.path.join(srcDir, "public") | ||
let srcPublic = FS.path.join(options.source, "public") | ||
if (await FS.fileExists(srcPublic)) { | ||
@@ -401,3 +403,3 @@ let exclude = { ext: [".psd", ".ai"], size: buildFileLimit } | ||
// copy license to public | ||
let srcLicense = FS.path.join(srcDir, "LICENSE") | ||
let srcLicense = FS.path.join(options.source, "LICENSE") | ||
if (await FS.fileExists(srcLicense)) { | ||
@@ -415,35 +417,40 @@ let destLicense = FS.path.join(destDir, "LICENSE") | ||
// compress files | ||
let JSZip = require("jszip")() | ||
await Promise.all(files.map(async entry => { | ||
let filePath = FS.path.join(destDir, entry) | ||
let fileData = await FS.readFile(filePath) | ||
return JSZip.file(entry, fileData) | ||
})) | ||
let size = appXml.length | ||
// generate zip file | ||
let buffer = await JSZip.generateAsync({ | ||
type: "nodebuffer", | ||
compression: "DEFLATE", | ||
compressionOptions: { level: 9 }, | ||
mimetype: "application/defiant-x", | ||
}) | ||
if (options.compress) { | ||
// compress files | ||
let JSZip = require("jszip")() | ||
await Promise.all(files.map(async entry => { | ||
let filePath = FS.path.join(destDir, entry) | ||
let fileData = await FS.readFile(filePath) | ||
return JSZip.file(entry, fileData) | ||
})) | ||
// write to disk | ||
let zipDest = FS.path.join(destDir, appId +".app") | ||
await FS.writeFile(zipDest, buffer) | ||
// generate zip file | ||
let buffer = await JSZip.generateAsync({ | ||
type: "nodebuffer", | ||
compression: "DEFLATE", | ||
compressionOptions: { level: 9 }, | ||
mimetype: "application/defiant-x", | ||
}) | ||
size = buffer.length | ||
// clean up build files + folders | ||
let folders = [] | ||
await Promise.all(files.map(entry => { | ||
if (entry.includes("/")) { | ||
let name = entry.slice(0, entry.lastIndexOf("/")) | ||
if (!folders.includes(name)) { | ||
folders.push(name) | ||
return FS.deleteDir(FS.path.join(destDir, name)) | ||
// write to disk | ||
let zipDest = FS.path.join(destDir, appId +".app") | ||
await FS.writeFile(zipDest, buffer) | ||
// clean up build files + folders | ||
let folders = [] | ||
await Promise.all(files.map(entry => { | ||
if (entry.includes("/")) { | ||
let name = entry.slice(0, entry.lastIndexOf("/")) | ||
if (!folders.includes(name)) { | ||
folders.push(name) | ||
return FS.deleteDir(FS.path.join(destDir, name)) | ||
} | ||
} else { | ||
return FS.unlink(FS.path.join(destDir, entry)) | ||
} | ||
} else { | ||
return FS.unlink(FS.path.join(destDir, entry)) | ||
} | ||
})) | ||
})) | ||
} | ||
@@ -453,5 +460,5 @@ resolve({ | ||
name, | ||
size, | ||
id: appId, | ||
uglified: uglify || false, | ||
size: buffer.length, | ||
uglified: options.uglify || false, | ||
buildPath: destDir, | ||
@@ -458,0 +465,0 @@ buildDir: destDir.slice(process.cwd().length + 1), |
{ | ||
"name": "defiant-builder", | ||
"version": "1.5.7", | ||
"version": "1.5.8", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./lib", |
@@ -5,8 +5,9 @@ | ||
let srcDir = path.join(__dirname, "temp/solitaire") | ||
let destDir = path.join(__dirname, "temp/_build") | ||
let source = path.join(__dirname, "temp/solitaire") | ||
let destination = path.join(__dirname, "temp/_build") | ||
let uglify = false | ||
let compress = true | ||
let runIt = async () => { | ||
let b = await Build(srcDir, destDir, uglify) | ||
let b = await Build({ source, destination, uglify, compress }) | ||
// console.log(b) | ||
@@ -13,0 +14,0 @@ } |
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
53863
477