Skip to content

Commit

Permalink
[IMP] bundle_xml: improve the bundling o xml
Browse files Browse the repository at this point in the history
This commit replace the parsing by hand of the arguments of the script
bundling xml by the library minimist.

It also add release note as a comment at the end of the bundled xml file.

closes #2175

Signed-off-by: Pierre Rousseau (pro) <[email protected]>
  • Loading branch information
hokolomopo committed Mar 6, 2023
1 parent 6b4d816 commit 5b8ff6c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
18 changes: 11 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"devDependencies": {
"@prettier/plugin-xml": "^2.0.1",
"@rollup/plugin-node-resolve": "^11.0.1",
"@rollup/plugin-terser": "^0.2.0",
"@types/chart.js": "2.9.3",
"@types/jest": "^27.0.1",
"@types/node": "^13.13.23",
Expand All @@ -74,14 +75,14 @@
"jszip": "^3.6.0",
"lint-staged": "^12.1.2",
"live-server": "^1.2.1",
"minimist": "^1.2.8",
"mockdate": "^3.0.2",
"node-watch": "^0.7.3",
"npm-run-all": "^4.1.5",
"prettier": "^2.7.1",
"prettier-plugin-organize-imports": "^3.1.1",
"rollup": "^2.38.5",
"rollup-plugin-dts": "^4.2.0",
"@rollup/plugin-terser": "^0.2.0",
"rollup-plugin-typescript2": "^0.34.1",
"ts-jest": "^27.0.5",
"typedoc": "0.23.15",
Expand Down
5 changes: 4 additions & 1 deletion tools/bundle_xml/bundle_xml_templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ async function createOwlTemplateBundle(files, removeRootTags) {
/**
* Write the xml bundle to the `dist` directory
*/
async function writeOwlTemplateBundleToFile(dir) {
async function writeOwlTemplateBundleToFile(dir, outro = "") {
process.stdout.write(`Building xml template bundle in "${dir}/" ...`);
let templateBundle = await getOwlTemplatesBundle(true);
if (outro) {
templateBundle += "<!--" + outro + "-->";
}
templateBundle = prettify(templateBundle);
writeToFile(path.join(__dirname, `../../${dir}/o_spreadsheet.xml`), templateBundle);
process.stdout.write("done\n");
Expand Down
20 changes: 17 additions & 3 deletions tools/bundle_xml/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
const { version } = require("../../package.json");
const git = require("git-rev-sync");
const bundle = require("./bundle_xml_templates");
const parseArgs = require("minimist");

const DEFAULT_DIR = "dist";

const outDirFlagIndex = process.argv.findIndex((arg) => arg === "--outDir");
const outDir = outDirFlagIndex !== -1 ? process.argv[outDirFlagIndex + 1] : DEFAULT_DIR;
const argv = parseArgs(process.argv.slice(2));

bundle.writeOwlTemplateBundleToFile(outDir || DEFAULT_DIR);
let commitHash = "";

try {
commitHash = git.short();
} catch (_) {}

const OUTRO = `
__info__.version = '${version}';
__info__.date = '${new Date().toISOString()}';
__info__.hash = '${commitHash}';
`;

bundle.writeOwlTemplateBundleToFile(argv.outDir || DEFAULT_DIR, OUTRO);

0 comments on commit 5b8ff6c

Please sign in to comment.