From 1a5cab57a1b28806479ce6ce1c25eaef3114e51b Mon Sep 17 00:00:00 2001 From: Stuart Taylor Date: Mon, 19 Feb 2018 20:41:01 +0000 Subject: [PATCH] feat(sass): Enable client-side sass compiling (#16747) --- .../routes/Challenges/rechallenge/builders.js | 2 +- .../Challenges/rechallenge/transformers.js | 78 ++++++++++++++----- common/utils/polyvinyl.js | 8 ++ .../03-front-end-libraries/sass.json | 36 ++++----- 4 files changed, 86 insertions(+), 38 deletions(-) diff --git a/common/app/routes/Challenges/rechallenge/builders.js b/common/app/routes/Challenges/rechallenge/builders.js index 3984c83e0d..c38c1a6f30 100644 --- a/common/app/routes/Challenges/rechallenge/builders.js +++ b/common/app/routes/Challenges/rechallenge/builders.js @@ -95,7 +95,7 @@ export function concactHtml(required, template) { const body = source .flatMap(file => file.reduce((body, file) => { - return body + file.contents + htmlCatch; + return body + file.contents + file.tail + htmlCatch; }, '')) .map(source => ({ source })) .map(createBody); diff --git a/common/app/routes/Challenges/rechallenge/transformers.js b/common/app/routes/Challenges/rechallenge/transformers.js index 5eb60d5c8e..c0b3a9a94a 100644 --- a/common/app/routes/Challenges/rechallenge/transformers.js +++ b/common/app/routes/Challenges/rechallenge/transformers.js @@ -1,4 +1,13 @@ -import _ from 'lodash'; +import { + cond, + flow, + identity, + matchesProperty, + overEvery, + overSome, + partial, + stubTrue +} from 'lodash'; import * as babel from 'babel-core'; import presetEs2015 from 'babel-preset-es2015'; @@ -24,15 +33,34 @@ function loopProtectHit(line) { const console$logReg = /(?:\b)console(\.log\S+)/g; const NBSPReg = new RegExp(String.fromCharCode(160), 'g'); -const isJS = _.matchesProperty('ext', 'js'); -const testHTMLJS = _.overSome(isJS, _.matchesProperty('ext', 'html')); -const testJS$JSX = _.overSome(isJS, _.matchesProperty('ext', 'jsx')); +const isJS = matchesProperty('ext', 'js'); +const testHTMLJS = overSome(isJS, matchesProperty('ext', 'html')); +const testJS$JSX = overSome(isJS, matchesProperty('ext', 'jsx')); +// work around the absence of multi-flile editing +// this can be replaced with `matchesProperty('ext', 'sass')` +// when the time comes +const testSASS = file => (/type='text\/sass'/i).test(file.contents); +// This can be done in the transformer when we have multi-file editing +const browserSassCompiler = ` + +`; // if shouldProxyConsole then we change instances of console log // to `window.__console.log` // this let's us tap into logging into the console. // currently we only do this to the main window and not the test window -export const proxyLoggerTransformer = _.partial( +export const proxyLoggerTransformer = partial( vinyl.transformHeadTailAndContents, source => ( source.replace(console$logReg, (match, methodCall) => { @@ -40,7 +68,7 @@ export const proxyLoggerTransformer = _.partial( })), ); -const addLoopProtect = _.partial( +const addLoopProtect = partial( vinyl.transformContents, contents => { /* eslint-disable import/no-unresolved */ @@ -51,11 +79,11 @@ const addLoopProtect = _.partial( } ); -export const addLoopProtectHtmlJsJsx = _.cond([ +export const addLoopProtectHtmlJsJsx = cond([ [ - _.overEvery( + overEvery( testHTMLJS, - _.partial( + partial( vinyl.testContents, contents => contents.toLowerCase().includes('