-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #910 from thoov/preprocess-argument-fix
Fix arguments to `preprocessCss` (to match classic build)
- Loading branch information
Showing
4 changed files
with
97 additions
and
8 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,46 @@ | ||
'use strict'; | ||
|
||
const Filter = require('broccoli-persistent-filter'); | ||
const funnel = require('broccoli-funnel'); | ||
const { join } = require('path').posix; | ||
|
||
class Awk extends Filter { | ||
constructor(inputNode, searchReplaceObj) { | ||
super(inputNode, {}); | ||
this.searchReplaceObj = searchReplaceObj; | ||
} | ||
|
||
processString(content) { | ||
let modifiedContent = content; | ||
|
||
Object.entries(this.searchReplaceObj).forEach(([search, replace]) => { | ||
modifiedContent = modifiedContent.replace(search, replace); | ||
}); | ||
|
||
return modifiedContent; | ||
} | ||
} | ||
|
||
module.exports = { | ||
name: require('./package').name, | ||
|
||
setupPreprocessorRegistry(type, registry) { | ||
registry.add('css', { | ||
name: this.name, | ||
ext: 'css', | ||
toTree: (tree, inputPath, outputPath) => { | ||
return funnel(new Awk(tree, { '%%%': inputPath === '/app/styles' ? 'red' : 'blue' }), { | ||
getDestinationPath(relativePath) { | ||
let relativePathWithPrefix = `/${relativePath}`; | ||
|
||
if (relativePathWithPrefix === `${inputPath}/app.css`) { | ||
return join(outputPath, 'app-template.css'); | ||
} | ||
|
||
return join(outputPath, relativePathWithPrefix.replace(inputPath, '')); | ||
}, | ||
}); | ||
}, | ||
}); | ||
}, | ||
}; |
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,40 @@ | ||
import { appScenarios } from './scenarios'; | ||
import { PreparedApp, Project } from 'scenario-tester'; | ||
import QUnit from 'qunit'; | ||
import merge from 'lodash/merge'; | ||
import { loadFromFixtureData } from './helpers'; | ||
import { dirname, join } from 'path'; | ||
import fs from 'fs'; | ||
const { module: Qmodule, test } = QUnit; | ||
|
||
appScenarios | ||
.map('preprocess', project => { | ||
let preprocessAddon = Project.fromDir(dirname(require.resolve('../addon-template/package.json')), { | ||
linkDeps: true, | ||
}); | ||
|
||
merge(preprocessAddon.files, loadFromFixtureData('preprocess-addon')); | ||
preprocessAddon.linkDependency('broccoli-funnel', { baseDir: __dirname }); | ||
preprocessAddon.linkDependency('broccoli-persistent-filter', { baseDir: __dirname }); | ||
preprocessAddon.pkg.name = 'preprocess-addon'; | ||
|
||
project.addDevDependency(preprocessAddon); | ||
merge(project.files, { | ||
app: { | ||
styles: { | ||
'app.css': `body { background: %%%; }`, | ||
}, | ||
}, | ||
}); | ||
}) | ||
.forEachScenario(scenario => { | ||
Qmodule(scenario.name, function () { | ||
test(`yarn test`, async function (assert) { | ||
let app: PreparedApp = await scenario.prepare(); | ||
await app.execute('node ./node_modules/ember-cli/bin/ember b'); | ||
|
||
const data = fs.readFileSync(join(app.dir, 'dist', 'assets', 'app-template.css'), 'utf8'); | ||
assert.equal(data, 'body { background: red; }'); | ||
}); | ||
}); | ||
}); |