Skip to content

Commit

Permalink
FAT-299 parsing FtData into instantAds initially working
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenny Arehart committed Apr 19, 2018
1 parent 10eee7b commit 138cef5
Show file tree
Hide file tree
Showing 6 changed files with 288 additions and 172 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ switch (argv.cmd) {
log('targets:', targets)
const folders = JSON.parse(argv.folders)
log('folders:', folders)
packager.createVendorPackage(argv.profile, folders, targets)
packager.createVendorPackage(argv.profile, argv.context, folders, targets)
break
}

Expand Down
10 changes: 9 additions & 1 deletion lib/filter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const excludedFilesList = ['.gitignore', '.DS_Store', '*.txt', 'manifest.js']
const excludedFoldersList = ['instantAssets']

function excludedFiles(filename) {
for (let str of excludedFilesList) {
Expand All @@ -15,6 +16,13 @@ function excludedFiles(filename) {
return false
}

function excludedFolders() {
return {
filters: excludedFoldersList
}
}

module.exports = {
excludedFiles
excludedFiles,
excludedFolders
}
128 changes: 128 additions & 0 deletions lib/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
const fs = require('fs-extra')
const RegEx = require('./regex')
const debug = require('@ff0000-ad-tech/debug')
let log = debug('cs-plugin-vendor-ft:manifest')

let storedFtData = null
let storedImageMap = null

function parseFtData(context, build) {
log('parseFtData()', context, build)
storedFtData = []
storedImageMap = null
return new Promise((resolve, reject) => {
const pathFtData = context + '/' + build + '/common/js/data/FtData.js'
log('pathFtData:', pathFtData)
fs.readFile(pathFtData, 'utf8', (err, data) => {
const labelMatches = data.match(RegEx.ftDataTypes)
// log('labelMatches:', labelMatches.length)
// log(labelMatches)

const dataMatches = data.split(RegEx.ftDataTypes)
dataMatches.shift()
// log('dataMatches:', dataMatches.length)
// log(dataMatches)

for (let i = 0; i < labelMatches.length; i++) {
const labelType = labelMatches[i].slice(labelMatches[i].indexOf('-') + 1)
// log(' -> labelType:', labelType)

if (labelType == 'end-keys') {
// skip
} else if (labelType == 'image-map') {
// strip comments
const singleData = dataMatches[i].replace(RegEx.lineComments, '')
const stripVar = singleData.substr(singleData.indexOf('{'))
// store for later use on a per size basis
storedImageMap = JSON.parse(stripVar)
} else {
let value = RegEx.ftDataValue.exec(dataMatches[i])[3]
value = value.slice(0, value.length - 1) // removes a trailing ' or "
storedFtData.push({
type: labelType,
name: RegEx.ftDataNames.exec(dataMatches[i])[1],
default: value
})
}
}
log(storedFtData)

resolve()
})
})
}

function parseFtDataImageMap(json, size) {
for (let key in storedImageMap) {
let val = ''
if (size in storedImageMap[key]) {
val = storedImageMap[key][size]
} else if ('default' in storedImageMap[key]) {
val = storedImageMap['default']
}
json['instantAds'].push({
type: 'image',
name: key,
default: val
})
}
}

function transform(dataRaw, buildData) {
// remove comments, TF.manifest(

// UPDATE to use dotAll [\s\S]
let toStringJSON = dataRaw.replace(/\/\/.+/g, '').replace(/FT\.manifest\(/g, '')

let index = toStringJSON.lastIndexOf('})')
log('index:', index)
toStringJSON = toStringJSON.substring(0, index + 1)
log('toStringJSON:', toStringJSON)

let manifestJSON = JSON.parse(toStringJSON)
log(manifestJSON)

// ----------------------------------------
// update base properties
// if (adlabelType == TYPE_STANDARD || (adlabelType == TYPE_EXPANDABLE && self.is_collapsed(size['build_size'])):
// manifest_json['width'] = self.build_data['dimensions']['width']
// manifest_json['height'] = self.build_data['dimensions']['height']
// manifest_json['clickTagCount'] = len(self.settings.clicktags[size['deploy_size']])

// add rich-loads
manifestJSON['richLoads'].push({
name: 'richloadBase',
src: buildData.directories.name['rich']
})

// set instandAds-reference to richLoads
manifestJSON['instantAds'].push({
name: 'richloadBase',
type: 'richLoad'
})

// if expandable, create a manifest node for the expanded params
// if (adlabelType == TYPE_EXPANDABLE && self.is_expanded(size['build_size'])) {
manifestJSON['expand'] = {
width: buildData['dimensions'][0],
height: buildData['dimensions'][1],
indentAcross: 0,
indentDown: 0
}
// }

// apply the FtData
storedFtData.forEach(target => {
manifestJSON['instantAds'].push(target)
})

// apply the imageMap
parseFtDataImageMap(manifestJSON, buildData['dimensions'].join('x'))

return manifestJSON
}

module.exports = {
parseFtData,
transform
}
Loading

0 comments on commit 138cef5

Please sign in to comment.