mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 15:32:26 +08:00
DEV: invert pretty-text build logic (#22524)
Generally follows the same pattern as #22520 There are some changes here, notably it uses the addon's babel settings rather than the app's, and it goes through the same treatment as the rest of the addon code (which may include more than just babel). However, this probably brings us closer to the normal expectations you have around developing addon code, and in any case, does not seem to have any effect on the final output: ``` $ diff dist/assets/markdown-it-bundle.js /tmp/dist-before/assets/markdown-it-bundle.js ```
This commit is contained in:
parent
7d5db385d6
commit
3140a4b2ce
|
@ -4,7 +4,6 @@ const EmberApp = require("ember-cli/lib/broccoli/ember-app");
|
|||
const resolve = require("path").resolve;
|
||||
const mergeTrees = require("broccoli-merge-trees");
|
||||
const concat = require("broccoli-concat");
|
||||
const prettyTextEngine = require("./lib/pretty-text-engine");
|
||||
const { createI18nTree } = require("./lib/translation-plugin");
|
||||
const { parsePluginClientSettings } = require("./lib/site-settings-plugin");
|
||||
const discourseScss = require("./lib/discourse-scss");
|
||||
|
@ -186,6 +185,10 @@ module.exports = function (defaults) {
|
|||
|
||||
const wizardTree = app.project.findAddonByName("wizard").treeForAddonBundle();
|
||||
|
||||
const markdownItBundleTree = app.project
|
||||
.findAddonByName("pretty-text")
|
||||
.treeForMarkdownItBundle();
|
||||
|
||||
const terserPlugin = app.project.findAddonByName("ember-cli-terser");
|
||||
const applyTerser = (tree) => terserPlugin.postprocessTree("all", tree);
|
||||
|
||||
|
@ -211,7 +214,12 @@ module.exports = function (defaults) {
|
|||
outputFile: `assets/wizard.js`,
|
||||
})
|
||||
),
|
||||
applyTerser(prettyTextEngine(app)),
|
||||
applyTerser(
|
||||
concat(markdownItBundleTree, {
|
||||
inputFiles: ["**/*.js"],
|
||||
outputFile: `assets/markdown-it-bundle.js`,
|
||||
})
|
||||
),
|
||||
generateScriptsTree(app),
|
||||
applyTerser(discoursePluginsTree),
|
||||
]);
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
const mergeTrees = require("broccoli-merge-trees");
|
||||
const funnel = require("broccoli-funnel");
|
||||
const concat = require("broccoli-concat");
|
||||
const WatchedDir = require("broccoli-source").WatchedDir;
|
||||
const Funnel = require("broccoli-funnel");
|
||||
|
||||
module.exports = function prettyTextEngine(app) {
|
||||
let babelAddon = app.project.findAddonByName("ember-cli-babel");
|
||||
|
||||
const sourceTree = new WatchedDir(
|
||||
"../pretty-text/engines/discourse-markdown"
|
||||
);
|
||||
const namespacedTree = new Funnel(sourceTree, {
|
||||
getDestinationPath: function (relativePath) {
|
||||
return `pretty-text/engines/discourse-markdown/${relativePath}`;
|
||||
},
|
||||
});
|
||||
|
||||
const engineTree = babelAddon.transpileTree(namespacedTree);
|
||||
|
||||
let markdownIt = funnel("../node_modules/markdown-it/dist", {
|
||||
files: ["markdown-it.js"],
|
||||
});
|
||||
return concat(mergeTrees([engineTree, markdownIt]), {
|
||||
inputFiles: ["**/*.js"],
|
||||
outputFile: `assets/markdown-it-bundle.js`,
|
||||
});
|
||||
};
|
|
@ -21,7 +21,6 @@
|
|||
"discourse-widget-hbs": "1.0.0",
|
||||
"ember-source": "~3.28.12",
|
||||
"handlebars": "^4.7.7",
|
||||
"markdown-it": "^13.0.1",
|
||||
"pretty-text": "1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -1,7 +1,44 @@
|
|||
"use strict";
|
||||
|
||||
const Funnel = require("broccoli-funnel");
|
||||
const mergeTrees = require("broccoli-merge-trees");
|
||||
const path = require("path");
|
||||
|
||||
module.exports = {
|
||||
name: require("./package").name,
|
||||
|
||||
// custom method to produce the tree for markdown-it-bundle.js
|
||||
// called by ember-cli-build.js in discourse core
|
||||
//
|
||||
// code in here is only needed by the editor and we do not want them included
|
||||
// into the main addon/vendor bundle; instead, it'll be included via a script
|
||||
// tag as needed
|
||||
treeForMarkdownItBundle() {
|
||||
return mergeTrees([this._treeForEngines(), this._treeForMarkdownIt()]);
|
||||
},
|
||||
|
||||
// treat the JS code in /engines like any other JS code in the /addon folder
|
||||
_treeForEngines() {
|
||||
let enginesTreePath = path.resolve(this.root, "engines");
|
||||
let enginesTree = this.treeGenerator(enginesTreePath);
|
||||
|
||||
// we started at /engines, if we just call treeForAddon, the modules will
|
||||
// be under pretty-text/*, but we want pretty-text/engines/*
|
||||
let namespacedTree = new Funnel(enginesTree, {
|
||||
destDir: "engines",
|
||||
});
|
||||
|
||||
return this.treeForAddon.call(this, namespacedTree);
|
||||
},
|
||||
|
||||
_treeForMarkdownIt() {
|
||||
let markdownIt = require.resolve("markdown-it/dist/markdown-it.js");
|
||||
|
||||
return new Funnel(path.dirname(markdownIt), {
|
||||
files: ["markdown-it.js"],
|
||||
});
|
||||
},
|
||||
|
||||
isDevelopingAddon() {
|
||||
return true;
|
||||
},
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
"ember-source": "~3.28.12",
|
||||
"ember-source-channel-url": "^3.0.0",
|
||||
"loader.js": "^4.7.0",
|
||||
"markdown-it": "^13.0.1",
|
||||
"webpack": "^5.88.1"
|
||||
},
|
||||
"engines": {
|
||||
|
|
Loading…
Reference in New Issue
Block a user