Skip to content

Commit

Permalink
feat: add default P3 post-process config for theme modules (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored and Limon Monte committed Nov 6, 2018
1 parent 196c745 commit f5d21d0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
23 changes: 19 additions & 4 deletions bin/magi-p3-convert
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

const {workingPackage} = require('../lib/tools.js');
const {EOL} = require('os');
const {files, from, to} = require('../lib/p3-post.js')
const path = require('path');
const fs = require('fs');
const jsonfile = require('jsonfile');
Expand Down Expand Up @@ -114,6 +115,9 @@ async function main() {
${process.argv.slice(2).join(' ')} \
`);

// Set default values for replacements
const postProcess = {files, from, to};

// Run custom project adjustments
let postFile = 'magi-p3-post.json';
let magiPost = jsonfile.readFileSync(postFile, {throws: false});
Expand All @@ -126,11 +130,22 @@ async function main() {
}

if (magiPost) {
// magiPost json is a valid options object for 'replace-in-file'
replace.sync(magiPost);
// we don't need "magi-p3-post" anymore
(magiPost.remove || []).concat(postFile).forEach(file => fs.unlinkSync(file));
magiPost.files = [...postProcess.files, ...magiPost.files];
magiPost.from = [...postProcess.from, ...magiPost.from];
magiPost.to = [...postProcess.to, ...magiPost.to];
} else {
magiPost = postProcess;
}

// magiPost json is a valid options object for 'replace-in-file'
replace.sync(magiPost);

const filesToRemove = magiPost.remove || [];
// we don't need "magi-p3-post" anymore
if (fs.existsSync(postFile)) {
filesToRemove.push(postFile);
}
filesToRemove.forEach(file => fs.unlinkSync(file));
}

main()
Expand Down
22 changes: 22 additions & 0 deletions lib/p3-post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const fixme = `
/*
FIXME(polymer-modulizer): the above comments were extracted
from HTML and may be out of place here. Review them and
then delete this comment!
*/
;`
module.exports = {
files: [
"theme/**/*-styles.js"
],
from: [
"const $_documentContainer = document.createElement('template');",
"$_documentContainer.innerHTML = `",
fixme
],
to: [
"import { html } from '@polymer/polymer/lib/utils/html-tag.js';",
"const $_documentContainer = html`",
""
]
}

0 comments on commit f5d21d0

Please sign in to comment.