-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FAT-299 successful packaging of standard ad
- Loading branch information
Kenny Arehart
committed
Apr 18, 2018
1 parent
4820021
commit 10eee7b
Showing
7 changed files
with
383 additions
and
11 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
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,20 @@ | ||
const excludedFilesList = ['.gitignore', '.DS_Store', '*.txt', 'manifest.js'] | ||
|
||
function excludedFiles(filename) { | ||
for (let str of excludedFilesList) { | ||
if (str.indexOf('*') == 0) { | ||
// means to check all file types | ||
const fileExt = filename.split('.')[1] | ||
const exclExt = str.split('.')[1] | ||
if (fileExt == exclExt) return true | ||
} else { | ||
// just do straight compare | ||
if (str == filename) return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
module.exports = { | ||
excludedFiles | ||
} |
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,63 @@ | ||
const fs = require('fs-extra') | ||
const path = require('path') | ||
const walk = require('walk') | ||
const JSZIP = require('jszip') | ||
const debug = require('@ff0000-ad-tech/debug') | ||
let log = debug('cs-plugin-vendor-ft:packager') | ||
|
||
function copyDirectory(from, filters, toReview, toUpload, zip) { | ||
return new Promise((resolve, reject) => { | ||
walk | ||
.walk(from, { | ||
filters: ['instantAssets'] | ||
}) | ||
.on('file', (root, stat, next) => { | ||
if (filters.call(this, stat.name)) { | ||
// skip the excluded files | ||
next() | ||
} else { | ||
fs.readFile(root + '/' + stat.name, (err, data) => { | ||
// remove the base file path to get just the directores to copy over | ||
let baseFolder = '.' + String(root).substr(from.length) + '/' | ||
log('file:', stat.name, '| root:', root, '| baseFolder:', baseFolder) | ||
|
||
fs.writeFile((toReview || from) + baseFolder + stat.name, data) | ||
|
||
// write the file into the zip | ||
// ternary decides if including the entire pathing or just relative file paths | ||
// console.log('toUpload:', toUpload) | ||
zip.file((toUpload || from) + baseFolder + stat.name, data) | ||
next() | ||
}) | ||
} | ||
}) | ||
.on('errors', (entry, stat) => { | ||
// log('walking error:', entry) | ||
reject() | ||
}) | ||
.on('end', () => { | ||
// log('walk.end') | ||
resolve() | ||
}) | ||
}) | ||
} | ||
|
||
function save(zip, path, name) { | ||
return new Promise((resolve, reject) => { | ||
zip | ||
.generateNodeStream({ | ||
type: 'nodebuffer', | ||
streamFiles: true | ||
}) | ||
.pipe(fs.createWriteStream(path + name + '.zip')) | ||
.on('finish', () => { | ||
log(path + name, 'save() successful') | ||
resolve() | ||
}) | ||
}) | ||
} | ||
|
||
module.exports = { | ||
copyDirectory, | ||
save | ||
} |
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.