Skip to content

Commit

Permalink
feat: strf-7393 make cli work with paper 3.x branch
Browse files Browse the repository at this point in the history
  • Loading branch information
bc-williamkwon committed Oct 9, 2019
1 parent 79244d9 commit 7ba9688
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 60 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"modules": true
},
"env": {
"es6": true,
"node": true
},
"globals": {
Expand Down
100 changes: 78 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"homepage": "https://github.com/bigcommerce/stencil-cli",
"dependencies": {
"@bigcommerce/stencil-paper": "^2.0.19",
"@bigcommerce/stencil-paper": "^3.0.0-rc.24",
"@bigcommerce/stencil-styles": "1.1.0",
"accept-language-parser": "^1.0.2",
"archiver": "^0.14.4",
Expand Down
39 changes: 24 additions & 15 deletions server/plugins/renderer/renderer.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,24 +458,33 @@ internals.getHeaders = function (request, options, config) {
* @type {Object}
*/
internals.themeAssembler = {
getTemplates: (path, processor, callback) => {
TemplateAssembler.assemble(internals.getThemeTemplatesPath(), path, (err, templates) => {
if (templates[path]) {
// Check if the string includes frontmatter configuration and remove it
var match = templates[path].match(/---\r?\n[\S\s]*\r?\n---\r?\n([\S\s]*)$/);

if (_.isObject(match) && match[1]) {
templates[path] = match[1];
getTemplates: (path, processor) => {
return new Promise((resolve, reject) => {
TemplateAssembler.assemble(internals.getThemeTemplatesPath(), path, (err, templates) => {
if (err) {
return reject(err);
}
}
if (templates[path]) {
// Check if the string includes frontmatter configuration and remove it
const match = templates[path].match(/---\r?\n[\S\s]*\r?\n---\r?\n([\S\s]*)$/);

callback(null, processor(templates));
});
if (_.isObject(match) && match[1]) {
templates[path] = match[1];
}
}
return resolve(processor(templates));
});
})
},
getTranslations: (callback) => {
LangAssembler.assemble((err, translations) => {
callback(null, _.mapValues(translations, locales => JSON.parse(locales)));
});
getTranslations: () => {
return new Promise((resolve, reject) => {
LangAssembler.assemble((err, translations) => {
if (err) {
return reject(err);
}
return resolve(_.mapValues(translations, locales => JSON.parse(locales)));
});
})
},
};

Expand Down
43 changes: 21 additions & 22 deletions server/plugins/renderer/responses/pencil-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ const internals = {};

module.exports = function (data, assembler) {
this.respond = function (request, reply) {
var response,
output,
paper,
templatePath;

var paper = new Paper(data.context.settings, data.context.theme_settings, assembler);
const paper = new Paper(data.context.settings, data.context.theme_settings, assembler, "handlebars-v3");

// Set the environment to dev
data.context.in_development = true;
Expand All @@ -20,23 +15,27 @@ module.exports = function (data, assembler) {
// Plugins have the opportunity to add/modify the response by using decorators
_.each(request.app.decorators, function (decorator) {
paper.addDecorator(decorator);
})

templatePath = internals.getTemplatePath(request, data);

paper.loadTheme(templatePath, data.acceptLanguage, function () {
if (request.query.debug === 'context') {
return reply(data.context);
}

output = paper.renderTheme(templatePath, data);
response = reply(output);
response.code(data.statusCode);

if (data.headers['set-cookie']) {
response.header('set-cookie', data.headers['set-cookie']);
}
});

const templatePath = internals.getTemplatePath(request, data);

paper.loadTheme(templatePath, data.acceptLanguage)
.then(() => {
if (request.query.debug === 'context') {
return reply(data.context);
}
})
.catch(err => console.error(err.message.red))
.then(() => paper.renderTheme(templatePath, data))
.catch(err => console.error(err.message.red))
.then(output => {
const response = reply(output);
response.code(data.statusCode);
if (data.headers['set-cookie']) {
response.header('set-cookie', data.headers['set-cookie']);
}
return response;
}).catch(err => console.error(err.message.red));
};
};

Expand Down

0 comments on commit 7ba9688

Please sign in to comment.