Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async pack() {
let shims = []
let inputDirPath = this.code
if (isArray(this.code)) {
inputDirPath = this.code[0] // first item is path to code dir
shims = this.code.slice() // clone array
shims.shift() // remove first item since it's the path to code dir
}
const outputFileName = `${this.instanceId}-${Date.now()}.zip`
const outputFilePath = path.join(tmpdir(), outputFileName)
await packDir(inputDirPath, outputFilePath, shims)
this.zip = readFileSync(outputFilePath)
return this.zip
}
const hashCode = async (code) => {
// TODO BRN: Upgrade this to hash all code references in the array. Need to redeploy in the event that the shim changes.
const options = {
folders: { exclude: ['node_modules'] }
}
let folderToHash = code
if (isArray(code)) {
folderToHash = code[0]
}
const hashObj = await hashElement(folderToHash, options)
return hashObj.hash
}
forEach((item) => {
const { type, data, children } = item
const title = item.title || data.title
log(`|- ${title} - ${type}`)
const subLog = (line) => log(` ${line}`)
if (isArray(data)) {
printArray(compact(data), subLog, level + 1)
} else {
// TODO BRN: Fix this...
// eslint-disable-next-line no-use-before-define
printObj(compact(data), subLog, level + 1)
}
if (children && level <= 1) {
if (isArray(children)) {
printArray(compact(children), subLog)
} else {
// TODO BRN: Fix this...
// eslint-disable-next-line no-use-before-define
printObj(compact(children), subLog)
}
}
}, arr)
async pack() {
let inputDirPath = this.content
if (isArray(this.content)) {
inputDirPath = this.content[0] // first item is path to content dir
}
const outputFileName = `${this.instanceId}-${Date.now()}.zip`
const outputFilePath = path.join(tmpdir(), outputFileName)
await packDir(inputDirPath, outputFilePath)
this.zip = await readFile(outputFilePath)
return this.zip
}
forEach((item) => {
const { type, data, children } = item
const title = item.title || data.title
log(`|- ${title} - ${type}`)
const subLog = (line) => log(` ${line}`)
if (isArray(data)) {
printArray(compact(data), subLog, level + 1)
} else {
// TODO BRN: Fix this...
// eslint-disable-next-line no-use-before-define
printObj(compact(data), subLog, level + 1)
}
if (children && level <= 1) {
if (isArray(children)) {
printArray(compact(children), subLog)
} else {
// TODO BRN: Fix this...
// eslint-disable-next-line no-use-before-define
printObj(compact(children), subLog)
}
}
}, arr)
const visitVariables = (value, visited) => {
value = resolve(value)
if (value && !visited.has(value)) {
if (isArray(value)) {
visited.add(value)
forEachIndexed((aValue, index) => (value[index] = visitVariables(aValue, visited)), value)
visited.delete(value)
} else if (isObject(value)) {
visited.add(value)
forEachObjIndexed((oValue, key) => {
if (key !== 'children' && key !== 'inputTypes') {
value[key] = visitVariables(oValue, visited)
}
}, value)
visited.delete(value)
}
}
return value
}
const printObj = (obj, log, level = 0) => {
if (!obj) {
return
}
const subLog = (line) => log(` ${line}`)
if (
(keys(obj).length === 3 || (keys(obj).length === 4 && obj.children)) &&
obj.title &&
obj.type &&
obj.data
) {
if (isArray(obj.data)) {
printArray(compact(obj.data), subLog, level + 1)
} else {
printObj(compact(obj.data), subLog, level)
}
if (obj.children && level <= 1) {
if (isArray(obj.children)) {
printArray(compact(obj.children), subLog)
} else {
printObj(compact(obj.children), subLog)
}
}
} else {
forEach((val, key) => {
if (isArray(val)) {
printArray(val, subLog, level + 1)
} else if (isObject(val)) {
forEach((val, key) => {
if (isArray(val)) {
printArray(val, subLog, level + 1)
} else if (isObject(val)) {
log(`${key}:`)
printObj(val, subLog, level + 1)
} else {
log(`${key}: ${val}`)
}
}, obj)
}
return (accum, value, keys, iteratee, recur) => {
let result = accum
if (isObject(value) && !visited.has(value)) {
if (isVariable(value)) {
visited.add(value)
result = iteratee(result, value, keys)
} else if (isArray(value) || !isNativeObject(value)) {
visited.add(value)
forEach((childValue, childKdx) => {
if (!isComponent(childValue)) {
const newKeys = concat(keys, [childKdx])
result = recur(result, childValue, newKeys, iteratee)
}
}, value)
}
}
return result
}
}