Skip to content

Commit 276ebbb

Browse files
committed
feat: Setting up addon test-support for the ember-app.
1 parent ce06f74 commit 276ebbb

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// @ts-ignore
2+
import { data as _data } from "./-css-blocks-data";
3+
import CSSBlocksService from "./css-blocks";
4+
import { mockTestData } from "./test-data";
5+
6+
export class CSSBlocksTestService extends CSSBlocksService {
7+
constructor() {
8+
/// @ts-ignore
9+
super(...arguments); // need to pass in ...arguments since "@ember/service" extends from EmberObject
10+
CSSBlocksTestService.enableDebugMode = true;
11+
console.log(mockTestData);
12+
}
13+
14+
getBlock(moduleName: string, blockName: string): string {
15+
return `${moduleName}-${blockName}`;
16+
}
17+
}

packages/@css-blocks/ember-app/runtime/app/services/css-blocks.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import { StyleResolver } from "./StyleResolver";
1111

1212
const data: AggregateRewriteData = _data;
1313

14-
let DEBUGGING = false;
15-
1614
type DebugExpression = string | Array<DebugExpression>;
1715

1816
enum Operator {
@@ -29,13 +27,14 @@ interface StyleIdToOptimizationsMap {
2927
export default class CSSBlocksService extends Service {
3028
possibleOptimizations!: StyleIdToOptimizationsMap;
3129
styleNames: { [name: string]: string };
30+
static enableDebugMode: Boolean = false;
3231
constructor() {
3332
super(...arguments);
3433
this.possibleOptimizations = getOptimizationInverseMap(data.optimizations);
3534
this.styleNames = getStyleNames();
3635
}
3736
classNamesFor(argv: Array<string | number | boolean | null>): string {
38-
if (DEBUGGING) {
37+
if (CSSBlocksService.enableDebugMode) {
3938
console.log(argv);
4039
}
4140
let styleEvaluator = new StyleEvaluator(data, argv);
@@ -47,7 +46,7 @@ export default class CSSBlocksService extends Service {
4746
resolver.addStyle(style);
4847
}
4948

50-
if (DEBUGGING) {
49+
if (CSSBlocksService.enableDebugMode) {
5150
this.debugStyles("all possible implied styles", resolver.currentStyles());
5251
}
5352

@@ -68,7 +67,7 @@ export default class CSSBlocksService extends Service {
6867
classNames.push(data.outputClassnames[idx]);
6968
}
7069
let result = classNames.join(" ");
71-
if (DEBUGGING) {
70+
if (CSSBlocksService.enableDebugMode) {
7271
console.log(classNames);
7372
}
7473
return result;
@@ -93,7 +92,7 @@ export default class CSSBlocksService extends Service {
9392
* Reverse maps style ids to their style names for debugging.
9493
*/
9594
debugStyles(msg: string, stylesApplied: Set<number>): void {
96-
if (!DEBUGGING) return;
95+
if (!CSSBlocksService.enableDebugMode) return;
9796
let appliedStyleNames = new Array<string>();
9897
for (let s of stylesApplied) {
9998
appliedStyleNames.push(this.styleNames[s]);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const mockTestData = {
2+
"hue-web-component/styles/components/hue-web-component.compiledblock.css": [{"default": "hue-web-component-9e5_18bad"}],
3+
"dummy/styles/application.compiledblock.css": [{"default": "application-275_08b2d"}]
4+
};

packages/@css-blocks/ember-app/src/brocolli-plugin.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ export class CSSBlocksApplicationPlugin extends Filter {
5555
debug("blocks", serializedAnalysis.stylesFound);
5656
for (let blockId of Object.keys(serializedAnalysis.blocks)) {
5757
serializedAnalysis.blocks[blockId] = pathToIdent(serializedAnalysis.blocks[blockId]);
58+
console.log(`serializedAnalysis.blocks[blockId]: ${serializedAnalysis.blocks[blockId]}`);
59+
console.log(`blockId: ${blockId}`);
60+
61+
console.log("output of pathToIdent");
62+
console.log(serializedAnalysis.blocks[blockId]);
5863
}
5964
let analysis = await EmberAnalysis.deserializeSource(serializedAnalysis, factory, analyzer);
6065
unionInto(blocksUsed, analysis.transitiveBlockDependencies());
@@ -86,6 +91,7 @@ export class CSSBlocksApplicationPlugin extends Filter {
8691
let optLogFileName = `${cssFileName}.optimization.log`;
8792
let optimizationResult = await optimizer.optimize(cssFileName);
8893
debug(`Optimized CSS. There were ${optimizationResult.actions.performed.length} optimizations performed.`);
94+
console.log(optimizationResult.styleMapping);
8995
this.output.mkdirSync(path.dirname(cssFileName), {recursive: true});
9096
this.output.writeFileSync(cssFileName, optimizationResult.output.content.toString(), "utf8");
9197
this.output.writeFileSync(sourceMapFileName, optimizationResult.output.sourceMap?.toString(), "utf8");

packages/@css-blocks/ember-app/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ const EMBER_ADDON: AddonImplementation<CSSBlocksApplicationAddon> = {
8282
this._super.init && this._super.init.call(this, parent, project);
8383
this.treePaths.app = "../runtime/app";
8484
this.treePaths.addon = "../runtime/addon";
85+
this.treePaths["addon-test-support"] = "../runtime/addon-test-support";
8586
},
8687

8788
_modulePrefix(): string {

0 commit comments

Comments
 (0)