From 4bed56b913a697c0b32ad7b7ac4a04e311decff9 Mon Sep 17 00:00:00 2001 From: Oj Date: Sun, 14 Feb 2021 18:30:46 +0000 Subject: [PATCH] [Autotag] Add autotag --- src/autoTag.js | 12 ++++++++++++ src/index.js | 5 +++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 src/autoTag.js diff --git a/src/autoTag.js b/src/autoTag.js new file mode 100644 index 0000000..b428ee1 --- /dev/null +++ b/src/autoTag.js @@ -0,0 +1,12 @@ +const basicIncludes = (bundleCode, code, display = (code[0].toUpperCase() + code.substring(1))) => { + if (bundleCode.includes(code)) return display; +}; + +export default (bundleCode) => { // Scans final bundle JS to try and auto-detect things, then adding tags + const tags = [ + basicIncludes(bundleCode, 'react'), + basicIncludes(bundleCode, 'document', 'DOM'), + ].filter((x) => x !== undefined); + + return tags; +}; \ No newline at end of file diff --git a/src/index.js b/src/index.js index 3a58642..92e91e5 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,5 @@ import ModuleRepos from './modules/index.js'; +import AutoTag from './autoTag.js'; import Parcel from 'parcel-bundler'; import axios from 'axios'; @@ -161,7 +162,7 @@ for (const parentRepo of ModuleRepos) { version: manifest.version, - tags: manifest.tags, + tags: manifest.tags.concat(AutoTag(jsCode)), authors: manifest.authors, @@ -182,7 +183,7 @@ for (const parentRepo of ModuleRepos) { // console.log(lastHash); - if (lastHash !== commitHash) { + if (commitHash !== '' && lastHash !== commitHash) { console.log('[Warning] Commit hash in modules does not match latest commit in repo'); } }