|
| 1 | +import type { AddonImplementation } from "ember-cli/lib/models/addon"; |
| 2 | + |
| 3 | +/** |
| 4 | + * An ember-cli addon for Ember applications using CSS Blocks in its |
| 5 | + * application code. This addon should be a dependency in the |
| 6 | + * following Ember artifacts... |
| 7 | + * |
| 8 | + * - Ember applications. |
| 9 | + * - Lazy Ember Engines. |
| 10 | + * |
| 11 | + * This addon is responsible for bundling together all CSS Blocks content |
| 12 | + * from the application, concatenating it into a final artifact, and |
| 13 | + * optimizing its content using OptiCSS. Additionaly, this addon generates a |
| 14 | + * JSON bundle that contains runtime data that templates need to resolve |
| 15 | + * what classes to add to each CSS Blocks-powered component. And, finally, |
| 16 | + * this addon provides a runtime helper to actually write out those classes. |
| 17 | + * |
| 18 | + * This addon expects that all intermediary blocks have already been compiled |
| 19 | + * into their respective Compiled CSS and Definition Files using the |
| 20 | + * @css-blocks/ember addon. Your app should also include this as a dependency, |
| 21 | + * or else this addon won't generate any CSS output! |
| 22 | + * |
| 23 | + * A friendly refresher for those that might've missed this tidbit from |
| 24 | + * @css-blocks/ember... CSS Blocks actually compiles its CSS as part of the |
| 25 | + * Template tree, not the styles tree! This is because CSS Blocks is unique |
| 26 | + * in how it reasons about both your templates and styles together. So, in order |
| 27 | + * to actually reason about both, and, in turn, rewrite your templates for you, |
| 28 | + * both have to be processed when building templates. |
| 29 | + * |
| 30 | + * You can read more about CSS Blocks at... |
| 31 | + * css-blocks.com |
| 32 | + * |
| 33 | + * And you can read up on the Ember build pipeline for CSS Blocks at... |
| 34 | + * <LINK_TBD> |
| 35 | + * |
| 36 | + * @todo: Provide a link for Ember build pipeline readme. |
| 37 | + */ |
| 38 | +const EMBER_ADDON: AddonImplementation = { |
| 39 | + /** |
| 40 | + * The name of this addon. Generally matches the package name in package.json. |
| 41 | + */ |
| 42 | + name: "@css-blocks/ember-app", |
| 43 | + |
| 44 | + /** |
| 45 | + * Initalizes this addon instance for use. |
| 46 | + * @param parent - The project or addon that directly depends on this addon. |
| 47 | + * @param project - The current project (deprecated). |
| 48 | + */ |
| 49 | + init(parent, project) { |
| 50 | + // We must call this._super or weird stuff happens. The Ember CLI docs |
| 51 | + // recommend guarding this call, so we're gonna ask TSLint to chill. |
| 52 | + // tslint:disable-next-line: no-unused-expression |
| 53 | + this._super.init && this._super.init.call(this, parent, project); |
| 54 | + }, |
| 55 | + |
| 56 | + /** |
| 57 | + * This method is called when the addon is included in a build. You would typically |
| 58 | + * use this hook to perform additional imports. |
| 59 | + * @param parent - The parent addon or application this addon is currently working on. |
| 60 | + */ |
| 61 | + included(parent) { |
| 62 | + // We must call this._super or weird stuff happens. |
| 63 | + this._super.included.apply(this, [parent]); |
| 64 | + }, |
| 65 | + |
| 66 | + /** |
| 67 | + * Pre-process a tree. Used for adding/removing files from the build. |
| 68 | + * @param type - What kind of tree. |
| 69 | + * @param tree - The tree that's to be processed. |
| 70 | + * @returns - A tree that's ready to process. |
| 71 | + */ |
| 72 | + preprocessTree(type, tree) { |
| 73 | + if (type !== "template") return tree; |
| 74 | + |
| 75 | + // TODO: Do something in the template tree. |
| 76 | + return tree; |
| 77 | + }, |
| 78 | + |
| 79 | + /** |
| 80 | + * Post-process a tree. Runs after the files in this tree have been built. |
| 81 | + * @param type - What kind of tree. |
| 82 | + * @param tree - The processed tree. |
| 83 | + * @returns - The processed tree. |
| 84 | + */ |
| 85 | + postprocessTree(type, tree) { |
| 86 | + if (type !== "template") return tree; |
| 87 | + |
| 88 | + // TODO: Do something in the template tree. |
| 89 | + return tree; |
| 90 | + }, |
| 91 | + |
| 92 | + /** |
| 93 | + * Used to add preprocessors to the preprocessor registry. This is often used |
| 94 | + * by addons like ember-cli-htmlbars and ember-cli-coffeescript to add a |
| 95 | + * template or js preprocessor to the registry. |
| 96 | + * @param _type - Either "self" or "parent". |
| 97 | + * @param _registry - The registry to be set up. |
| 98 | + */ |
| 99 | + setupPreprocessorRegistry(_type, _registry) { |
| 100 | + // TODO: This hook may not be necessary in this addon. |
| 101 | + }, |
| 102 | +}; |
| 103 | + |
| 104 | +// Aaaaand export the addon implementation! |
| 105 | +module.exports = EMBER_ADDON; |
0 commit comments