ビジネス上の問題:一連のEmberアプリケーションでは、ソフトウェアの白/灰色のラベル付けをサポートするために、色、ロゴ、特定のコンテンツをCMSが制御できるようにします。Ember CLIカスタムCMS設定でのビルド
提案された解決策:Ember CLIアドオンが作成され、ビルド時に適切なスタイルシートルール、ロゴURLなどが取得され、適切なツリーにコンテンツが挿入されます。アドオンのため
初期の実装:
// index.js
/* jshint node: true */
'use strict';
const BroccoliMergeTrees = require('broccoli-merge-trees');
const broccoliSource = require('broccoli-source');
const UnwatchedDir = broccoliSource.UnwatchedDir;
const apiFactory = require('./lib/cms-integration-addon/api.js');
const writeFile = require('write');
module.exports = {
name: 'cms-integration-addon',
cmsIntegrationConfig: {},
isDevelopingAddon() {
return true;
},
included(app) {
const config = app.project.config(app.env)['cms-integration'] || {};
this.cmsIntegrationConfig = config;
},
treeForAddon() {
let tree = this._super.treeForAddon.apply(this, arguments);
const cmsDetailsSource = new UnwatchedDir(this.app.project.root + '/tmp/cms-integration-addon');
tree = new BroccoliMergeTrees([tree, cmsDetailsSource]);
return tree;
},
preBuild() {
const cms = apiFactory(this.cmsIntegrationConfig);
return cms.fetchSettings().then((settings) => {
const configPath = `${this.app.project.root}/tmp/cms-integration-addon/config/my-config.js`;
return writeFile(configPath, `export default ${JSON.stringify(settings)}`);
});
}
};
問題は、私が期待するように、このコードでCMSから適切なJSONオブジェクトがcms-integration-addon
モジュールの下vendor.js
に挿入されないということです。 treeForAddon
をtreeForApp
に変更すると、設定オブジェクトはアプリのモジュールのapp-name.js
に挿入されます。これは理想的ではなく、このコードがアドオンのモジュールの下に注入されている方が良いでしょう。
私のJSONオブジェクトをアドオンのモジュールに挿入するには、何が欠けていますか?