-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from sbcgua/apack-deep
Apack deep, to #1 parsing of apack dependencies
- Loading branch information
Showing
17 changed files
with
507 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
node_modules | ||
jspm_packages | ||
|
||
# artifacts | ||
coverage | ||
|
||
# Serverless directories | ||
.serverless | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
testMatch: [ | ||
'**/?(*.)+(e2e).(test).[jt]s?(x)', | ||
], | ||
// "testPathIgnorePatterns": [ | ||
// "/node_modules/", | ||
// ] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const fetch = require('node-fetch'); | ||
const pick = require('lodash.pick'); | ||
|
||
const PREFIX = (process.env.E2E_DEV === '1') ? 'dev.' : ''; | ||
const HOST = PREFIX + 'shield.abap.space'; | ||
const functionName = 'version-shield-json'; | ||
const versionRe = /^v\d{1,3}\.\d{1,3}(\.\d{1,3})?$/i; | ||
console.log('Host:', HOST); | ||
|
||
const getUrl = (params) => `https://${HOST}/${functionName}/${params}`; | ||
|
||
async function validateExpectations(resp) { | ||
expect(resp.ok).toBeTruthy(); | ||
const json = await resp.json(); | ||
expect(typeof json).toBe('object'); | ||
expect(pick(json, ['schemaVersion', 'label', 'color'])).toEqual({ | ||
schemaVersion: 1, | ||
label: 'abap package version', | ||
color: 'orange' | ||
}); | ||
expect(typeof json.message).toBe('string'); | ||
expect(json.message).toMatch(versionRe); | ||
} | ||
|
||
test('should process abap constant', async () => { | ||
const resp = await fetch(getUrl('github/sbcgua/mockup_loader/src/zif_mockup_loader_constants.intf.abap')); | ||
await validateExpectations(resp); | ||
}); | ||
|
||
test('should process apack', async () => { | ||
const resp = await fetch(getUrl('github/SAP-samples/abap-platform-jak/.apack-manifest.xml')); | ||
await validateExpectations(resp); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,48 @@ | ||
const xml = require('xml-parse'); | ||
var parser = require('fast-xml-parser'); | ||
const APACK_FILENAME = '.apack-manifest.xml'; | ||
const { xmlGetChildrenOf } = require('./utils'); | ||
|
||
function getVersionFromApack(str) { | ||
let parsedXML; | ||
function parseXml(xmlStr) { | ||
try { | ||
parsedXML = xml.parse(str); | ||
return parser.parse(xmlStr, { | ||
parseNodeValue : false, | ||
arrayMode: false, | ||
}); | ||
} catch (error) { | ||
throw Error('apack xml parsing error'); | ||
} | ||
} | ||
|
||
function getVersionFromApack(xmlStr) { | ||
const parsedXML = parseXml(xmlStr); | ||
const versionNode = xmlGetChildrenOf(parsedXML, 'asx:abap/asx:values/DATA/VERSION'); | ||
if (!versionNode || typeof versionNode !== 'string') throw Error('wrong apack xml structure'); | ||
return versionNode; | ||
} | ||
|
||
function getDependencyVersionFromApack(xmlStr, depName) { | ||
if (!depName || typeof depName !== 'string') throw Error('Incorrect dependency name'); | ||
depName = depName.toLowerCase(); | ||
const parsedXML = parseXml(xmlStr); | ||
|
||
// Get deps node | ||
const data = xmlGetChildrenOf(parsedXML, 'asx:abap/asx:values/DATA'); | ||
if (!data.DEPENDENCIES | ||
|| !data.DEPENDENCIES.item | ||
|| typeof data.DEPENDENCIES.item !== 'object' ) throw Error('dependency not found'); | ||
if (!Array.isArray(data.DEPENDENCIES.item)) data.DEPENDENCIES.item = [data.DEPENDENCIES.item]; // for a case of one item | ||
const dependencies = data.DEPENDENCIES.item.filter(i => typeof i === 'object'); | ||
|
||
// Find target | ||
const target = dependencies.find(i => [i.GROUP_ID, i.ARTIFACT_ID].join('/').toLowerCase() === depName); | ||
if (!target) throw Error('dependency not found'); | ||
if (!target.VERSION) throw Error('dependency version not found'); | ||
|
||
const versionNodeChildren = xmlGetChildrenOf(parsedXML, 'DATA/VERSION'); | ||
if (!versionNodeChildren) throw Error('wrong apack xml structure'); | ||
const versionText = versionNodeChildren.find(node => node.type === 'text'); | ||
if (!versionText) throw Error('wrong apack xml structure'); | ||
return versionText.text; | ||
return target.VERSION; | ||
} | ||
|
||
module.exports = { | ||
APACK_FILENAME, | ||
getVersionFromApack, | ||
getDependencyVersionFromApack, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.