From b2e120eca675bff5b039c4ebca61d2ad2357ecdd Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Tue, 13 Feb 2024 10:32:17 +0100 Subject: [PATCH 1/2] Markdown to HTML in gulp script --- Package/gulpfile.js | 25 +++++++++++++++++++++++++ Package/package-lock.json | 19 +++++++++++++++++++ Package/package.json | 3 +++ 3 files changed, 47 insertions(+) diff --git a/Package/gulpfile.js b/Package/gulpfile.js index 452c48237..a7d24c4f9 100644 --- a/Package/gulpfile.js +++ b/Package/gulpfile.js @@ -8,6 +8,7 @@ const shelljs = require('shelljs'); const rename = require('gulp-rename'); const glob = require('glob'); const chalk = require('chalk'); +const marked = require('marked'); let assemblediOSAndroidDir = 'Assembled-iOSAndroid'; let assembledWindowsDir = 'Assembled-Windows'; @@ -15,6 +16,28 @@ let basekitBuild = false; let cmakeBasekitBuildDefinition = ''; let basekitPackagePath = ''; + +const makeHTMLNotice = async () => { + fs.readFile('../README.md', 'utf8', (err, data) => { + if (err) { + console.error('Error reading file:', err); + return; + } + + // Convert Markdown to HTML + const html = marked.parse(data); + + // Write the HTML to a file + fs.writeFile('../NOTICE.html', html, 'utf8', err => { + if (err) { + console.error('Error writing file:', err); + return; + } + console.log('NOTICE Conversion complete!'); + }); +}); +}; + function exec(command, workingDirectory = '.', logCommand = true) { if (logCommand) { log(command); @@ -616,6 +639,8 @@ const build = gulp.series(buildIOSAndroid, switchToBaseKit, buildIOSAndroid); const rebuild = gulp.series(clean, build); const pack = gulp.series(rebuild, createPackage); +exports.buildNotice = makeHTMLNotice; + exports.validateAssembled = validateAssembled; exports.validateAssemblediOSAndroid = validateAssemblediOSAndroid; diff --git a/Package/package-lock.json b/Package/package-lock.json index bb637408a..cfc000e8f 100644 --- a/Package/package-lock.json +++ b/Package/package-lock.json @@ -4,6 +4,9 @@ "requires": true, "packages": { "": { + "dependencies": { + "marked": "^4.3.0" + }, "devDependencies": { "chalk": "^4.1.1", "fancy-log": "^1.3.3", @@ -2361,6 +2364,17 @@ "node": ">=0.10.0" } }, + "node_modules/marked": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/marked/-/marked-4.3.0.tgz", + "integrity": "sha512-PRsaiG84bK+AMvxziE/lCFss8juXjNaWzVbN5tXAm4XjeaS9NAHhop+PjQxz2A9h8Q4M/xGmzP8vqNwy6JeK0A==", + "bin": { + "marked": "bin/marked.js" + }, + "engines": { + "node": ">= 12" + } + }, "node_modules/matchdep": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/matchdep/-/matchdep-2.0.0.tgz", @@ -6102,6 +6116,11 @@ "object-visit": "^1.0.0" } }, + "marked": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/marked/-/marked-4.3.0.tgz", + "integrity": "sha512-PRsaiG84bK+AMvxziE/lCFss8juXjNaWzVbN5tXAm4XjeaS9NAHhop+PjQxz2A9h8Q4M/xGmzP8vqNwy6JeK0A==" + }, "matchdep": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/matchdep/-/matchdep-2.0.0.tgz", diff --git a/Package/package.json b/Package/package.json index 07cf86061..2ca8177d3 100644 --- a/Package/package.json +++ b/Package/package.json @@ -7,5 +7,8 @@ "gulp": "^4.0.2", "gulp-rename": "2.0.0", "shelljs": "^0.8.4" + }, + "dependencies": { + "marked": "^4.3.0" } } From e80bf46fcd6922f0eb9c22727903ae5e6e7f2a5d Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Wed, 14 Feb 2024 10:00:33 +0100 Subject: [PATCH 2/2] promises --- Package/gulpfile.js | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/Package/gulpfile.js b/Package/gulpfile.js index a7d24c4f9..6eb8e2930 100644 --- a/Package/gulpfile.js +++ b/Package/gulpfile.js @@ -16,26 +16,15 @@ let basekitBuild = false; let cmakeBasekitBuildDefinition = ''; let basekitPackagePath = ''; - const makeHTMLNotice = async () => { - fs.readFile('../README.md', 'utf8', (err, data) => { - if (err) { - console.error('Error reading file:', err); - return; - } - - // Convert Markdown to HTML - const html = marked.parse(data); - - // Write the HTML to a file - fs.writeFile('../NOTICE.html', html, 'utf8', err => { - if (err) { - console.error('Error writing file:', err); - return; - } - console.log('NOTICE Conversion complete!'); + return fs.promises.readFile('../README.md', 'utf8').then(content =>{ + const html = marked.parse(content); + return fs.promises.writeFile('../NOTICE.html', html, 'utf8').then(() => { + console.log(chalk.black.bgCyan(`NOTICE Conversion complete!`)); + }) + }).catch(reason =>{ + console.error(chalk.white.bgRedBright(`Error generating notice : ${reason}`)); }); -}); }; function exec(command, workingDirectory = '.', logCommand = true) { @@ -639,7 +628,7 @@ const build = gulp.series(buildIOSAndroid, switchToBaseKit, buildIOSAndroid); const rebuild = gulp.series(clean, build); const pack = gulp.series(rebuild, createPackage); -exports.buildNotice = makeHTMLNotice; +exports.makeHTMLNotice = makeHTMLNotice; exports.validateAssembled = validateAssembled; exports.validateAssemblediOSAndroid = validateAssemblediOSAndroid;