Skip to content

Commit

Permalink
FAT-299 setting expandable manifest working
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenny Arehart committed Apr 20, 2018
1 parent f4a32ab commit 3746806
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 19 deletions.
7 changes: 7 additions & 0 deletions lib/adType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const STANDARD = 'standard'
const EXPANDABLE = 'expandable'

module.exports = {
STANDARD,
EXPANDABLE
}
19 changes: 14 additions & 5 deletions lib/manifest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs-extra')
const RegEx = require('./regex')
const AdType = require('./adType')
const debug = require('@ff0000-ad-tech/debug')
let log = debug('cs-plugin-vendor-ft:manifest')

Expand Down Expand Up @@ -70,7 +71,6 @@ function parseFtDataImageMap(json, size) {

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

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

Expand All @@ -82,7 +82,6 @@ function transform(dataRaw, buildData) {
let manifestJSON = JSON.parse(toStringJSON)
log(manifestJSON)

// ----------------------------------------
// update base properties
manifestJSON['width'] = buildData['dimensions'][0]
manifestJSON['height'] = buildData['dimensions'][1]
Expand All @@ -101,13 +100,23 @@ function transform(dataRaw, buildData) {
})

// if expandable, create a manifest node for the expanded params
if (buildData['adType'] == 'expandabale') {
if (buildData['adType'] == AdType.EXPANDABLE) {
manifestJSON['expand'] = {
width: buildData['dimensions'][0],
height: buildData['dimensions'][1],
width: buildData['dimensionsExpand'][0],
height: buildData['dimensionsExpand'][1],
indentAcross: 0,
indentDown: 0
}

// add expandable to richload/instantAds
manifestJSON['richLoads'].push({
name: 'richloadExpand',
src: buildData.directories.name['expanded']
})
manifestJSON['instantAds'].push({
name: 'richloadExpand',
type: 'richLoad'
})
}

// apply the FtData
Expand Down
29 changes: 21 additions & 8 deletions lib/packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ const JSZIP = require('jszip')
const Utils = require('./utils')
const Manifest = require('./manifest')
const RegEx = require('./regex')
const AdType = require('./adType')
const debug = require('@ff0000-ad-tech/debug')
let log = debug('cs-plugin-vendor-ft:packager')

let storedCollapsedName = null

function createVendorPackage(profile, context, folders, targets) {
log('createVendorPackage()')
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -67,12 +70,13 @@ function createVendorPackage(profile, context, folders, targets) {
}

// get the ad type; then is expandable, set flag to skip the partner
buildData['buildType'] = buildData['adType'] = 'standard'
buildData['buildType'] = buildData['adType'] = AdType.STANDARD
const isCollapsed = folderName.match(/collapsed/g)
const isExpanded = folderName.match(/expanded/g)
if (isCollapsed || isExpanded) {
buildData['buildType'] = isCollapsed ? 'collapsed' : 'expanded'
buildData['adType'] = 'expandable'
buildData['adType'] = AdType.EXPANDABLE
buildData['dimensionsExpand'] = folderNameExtracted.split('_')[1].split('x')
}

// REVIEW
Expand All @@ -86,10 +90,17 @@ function createVendorPackage(profile, context, folders, targets) {
masterPromises.push(copyRichLoad(filePath, buildData))

if (isCollapsed) {
// don't make the first time
// store the collapsed name
storedCollapsedName = buildData.directories.name.rich
log(buildData)
// don't make the first time
return
}
if (isExpanded) {
buildData.directories.name['expanded'] = buildData.directories.name['rich']
buildData.directories.name['rich'] = storedCollapsedName
storedCollapsedName = null
}

// BASE
buildData.directories.review['base'] = buildData.directories.review['size'] + 'baseLoad/' + buildData.directories.name.base + '/'
Expand All @@ -99,7 +110,9 @@ function createVendorPackage(profile, context, folders, targets) {
let basePromises = [
// index
new Promise((resolve, reject) => {
fs.readFile(path.join(__dirname, '../src') + '/ft_base_standard.html', 'utf8', (err, data) => {
const indexName = buildData['adType'] == AdType.EXPANDABLE ? 'ft_base_expandable' : 'ft_base_standard'
const indexPath = path.join(__dirname, '../src') + '/' + indexName + '.html'
fs.readFile(indexPath, 'utf8', (err, data) => {
// modify the index now:
data = data.replace(RegEx.cssRichLoadBase, val => {
return val
Expand Down Expand Up @@ -155,12 +168,12 @@ function createVendorPackage(profile, context, folders, targets) {
}

function copyRichLoad(filePath, buildData) {
buildData.directories.review.rich[buildData['buildType']] =
buildData.directories.review.rich['root'] + buildData.directories.name.rich + '/'
fs.emptyDirSync(buildData.directories.review.rich[buildData['buildType']])
const type = buildData['buildType']
buildData.directories.review.rich[type] = buildData.directories.review.rich['root'] + buildData.directories.name.rich + '/'
fs.emptyDirSync(buildData.directories.review.rich[type])
let zipRich = new JSZIP()
// copy the entire directory
return Utils.copyDirectory(filePath, buildData.directories.review.rich[buildData['buildType']], './', zipRich).then(() => {
return Utils.copyDirectory(filePath, buildData.directories.review.rich[type], './', zipRich).then(() => {
// return the promise of the zip save
return Utils.save(zipRich, buildData.directories.upload['rich'], buildData.directories.name['rich'])
})
Expand Down
8 changes: 4 additions & 4 deletions src/ft_base_expandable.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
}

#richload-base {
width: 970px;
height: 33px;
width: 0px;
height: 0px;
position: absolute;
left: 0;
top: 0;
}

#richload-expand {
display: none;
height: 250px;
width: 970px;
height: 0px;
width: 0px;
}
</style>
</head>
Expand Down
4 changes: 2 additions & 2 deletions src/ft_base_standard.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
}

#richload-base {
width: 300px;
height: 600px;
width: 0px;
height: 0px;
position: absolute;
left: 0;
top: 0;
Expand Down

0 comments on commit 3746806

Please sign in to comment.