@medable/mdctl-import-adapter
Advanced tools
Comparing version 1.0.59 to 1.0.60
69
index.js
@@ -178,6 +178,17 @@ const EventEmitter = require('events'), | ||
readPackageFile() { | ||
let packageData, | ||
script | ||
const { input } = privatesAccessor(this), | ||
location = globby.sync([KNOWN_FILES.package], { cwd: input }), | ||
paths = [] | ||
let packageData | ||
paths = [], | ||
getScript = (...params) => { | ||
for (const param of params) { | ||
if (packageData.scripts[param]) { | ||
return packageData.scripts[param] | ||
} | ||
} | ||
return null | ||
} | ||
@@ -190,21 +201,33 @@ if (location.length > 0 && fs.existsSync(`${input}/${location[0]}`)) { | ||
if (packageData.scripts) { | ||
if (packageData.scripts.preimport) { | ||
privatesAccessor(this, 'preImport', packageData.scripts.preimport) | ||
script = getScript('preImport', 'preimport') | ||
if (script) { | ||
privatesAccessor(this, 'preImport', script) | ||
} | ||
if (packageData.scripts.postimport) { | ||
privatesAccessor(this, 'postImport', packageData.scripts.postimport) | ||
script = getScript('postImport', 'postimport') | ||
if (script) { | ||
privatesAccessor(this, 'postImport', script) | ||
} | ||
if (packageData.scripts.preinstall) { | ||
const preInstall = path.join(input, packageData.scripts.preinstall) | ||
if (fs.existsSync(preInstall)) { | ||
packageData.scripts.preinstall = fs.readFileSync(preInstall).toString() | ||
script = getScript('beforeimport', 'beforeImport', 'preinstall', 'preInstall') | ||
if (script) { | ||
const beforeImport = path.join(input, script) | ||
if (fs.existsSync(beforeImport)) { | ||
packageData.scripts.beforeImport = fs.readFileSync(beforeImport).toString() | ||
} | ||
} | ||
if (packageData.scripts.postinstall) { | ||
const postInstall = path.join(input, packageData.scripts.postinstall) | ||
if (fs.existsSync(postInstall)) { | ||
packageData.scripts.postinstall = fs.readFileSync(postInstall).toString() | ||
script = getScript('afterimport', 'afterImport', 'postinstall', 'postInstall') | ||
if (script) { | ||
const afterImport = path.join(input, script) | ||
if (fs.existsSync(afterImport)) { | ||
packageData.scripts.afterImport = fs.readFileSync(afterImport).toString() | ||
} | ||
} | ||
} | ||
if (packageData.pipes) { | ||
if (_.isString(packageData.pipes.ingest)) { | ||
const ingestPipe = path.join(input, packageData.pipes.ingest) | ||
if (fs.existsSync(ingestPipe)) { | ||
packageData.pipes.ingest = fs.readFileSync(ingestPipe).toString() | ||
} | ||
} | ||
} | ||
if (packageData.manifest) { | ||
@@ -229,3 +252,3 @@ const manifestData = parseString(fs.readFileSync(`${input}/${packageData.manifest}`)) | ||
} else { | ||
throw Fault.from({ code: 'kManifestNotFound', reason: 'There is no manifest defined neither found in directory' }) | ||
throw Fault.create('mdctl.kManifestNotFound.error', { reason: 'There is no manifest set as parameter neither found in directory' }) | ||
} | ||
@@ -299,11 +322,11 @@ } | ||
getParentFromPath(chunk, path) { | ||
getParentFromPath(chunk, value) { | ||
const { content } = privatesAccessor(chunk), | ||
parent = jp.parent(content, jp.stringify(path)) | ||
parent = jp.parent(content, jp.stringify(value)) | ||
if (parent.code || parent.name || parent.label || parent.resource) { | ||
return parent | ||
} | ||
path.pop() | ||
value.pop() | ||
return path.length > 1 ? this.getParentFromPath(chunk, path) : {} | ||
return value.length > 1 ? this.getParentFromPath(chunk, value) : {} | ||
} | ||
@@ -347,9 +370,11 @@ | ||
if (chunk.key === 'package') { | ||
const { preInstall, postInstall } = chunk.content.scripts, | ||
const { content: { scripts } } = chunk, | ||
{ preInstall, postInstall } = scripts, | ||
{ input } = privatesAccessor(this) | ||
if (preInstall) { | ||
chunk.content.scripts.preInstall = fs.readFileSync(path.join(input, preInstall)).toString() | ||
scripts.preInstall = fs.readFileSync(path.join(input, preInstall)).toString() | ||
} | ||
if (postInstall) { | ||
chunk.content.scripts.postInstall = fs.readFileSync(path.join(input, postInstall)).toString() | ||
scripts.postInstall = fs.readFileSync(path.join(input, postInstall)).toString() | ||
} | ||
@@ -356,0 +381,0 @@ } else { |
{ | ||
"name": "@medable/mdctl-import-adapter", | ||
"version": "1.0.59", | ||
"version": "1.0.60", | ||
"description": "Medable Developer Client Tools :: Import Adapter", | ||
@@ -28,9 +28,9 @@ "repository": { | ||
"dependencies": { | ||
"@medable/mdctl-core": "^1.0.59", | ||
"@medable/mdctl-core-utils": "^1.0.59", | ||
"@medable/mdctl-node-utils": "^1.0.59", | ||
"@medable/mdctl-core": "^1.0.60", | ||
"@medable/mdctl-core-utils": "^1.0.60", | ||
"@medable/mdctl-node-utils": "^1.0.60", | ||
"clone": "^2.1.2", | ||
"globby": "^9.1.0", | ||
"jsonpath": "^1.0.2", | ||
"lodash": "^4.17.14", | ||
"jsonpath": "^1.1.1", | ||
"lodash": "^4.17.21", | ||
"lodash.isplainobject": "^4.0.6", | ||
@@ -54,3 +54,3 @@ "mime-types": "^2.1.21", | ||
}, | ||
"gitHead": "16fc2744e02340795babcdf657ccf63743940a38" | ||
"gitHead": "f3b858251d9114a9ae4ff86b26297f23b00f176b" | ||
} |
16314
379
Updated@medable/mdctl-core@^1.0.60
Updatedjsonpath@^1.1.1
Updatedlodash@^4.17.21