diff --git a/config/babel-plugin/oakGetAppVersion.js b/config/babel-plugin/oakGetAppVersion.js new file mode 100644 index 0000000..3022462 --- /dev/null +++ b/config/babel-plugin/oakGetAppVersion.js @@ -0,0 +1,27 @@ +const { join } = require('path'); +const t = require('@babel/types'); +const { assert } = require('console'); + + +module.exports = (babel) => { + return { + visitor: { + FunctionDeclaration(path, state) { + const { cwd } = state; + const { node } = path; + if (t.isIdentifier(node.id) && node.id.name === 'oakGetPackageJsonVersion') { + const { body } = node; + assert(t.isBlockStatement(body)); + assert(body.body.length === 1); + + const pkgJson = join(cwd, 'package.json'); + const { version } = require(pkgJson); + + body.body = [ + t.returnStatement(t.stringLiteral(version)) + ]; + } + }, + }, + }; +}; \ No newline at end of file diff --git a/config/mp/webpack.config.js b/config/mp/webpack.config.js index 689c3dc..d0521de 100644 --- a/config/mp/webpack.config.js +++ b/config/mp/webpack.config.js @@ -26,6 +26,7 @@ const createEnvironmentHash = require('./webpack/persistentCache/createEnvironme const oakI18nPlugin = require('../babel-plugin/oakI18n'); const oakPathPlugin = require('../babel-plugin/oakPath'); +const reuseOakComponentPlugin = require('../babel-plugin/reuse-oak-component'); const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false'; const shouldAnalyze = process.env.COMPILE_ANALYZE === 'true'; @@ -242,7 +243,7 @@ module.exports = function (webpackEnv) { ), loader: 'babel-loader', options: { - plugins: [oakI18nPlugin, oakPathPlugin], + plugins: [oakI18nPlugin, oakPathPlugin, reuseOakComponentPlugin], }, }, { diff --git a/config/native/transformer.js b/config/native/transformer.js index f92f143..32abbe5 100644 --- a/config/native/transformer.js +++ b/config/native/transformer.js @@ -27,6 +27,7 @@ const { injectGetRender } = require('../utils/injectGetRender'); const oakPathTsxPlugin = require('../babel-plugin/oakPath'); const oakRenderNativePlugin = require('../babel-plugin/oakRenderNative'); const oakI18nPlugin = require('../babel-plugin/oakI18n'); +const reuseOakComponentPlugin = require('../babel-plugin/reuse-oak-component'); async function renderToCSS({ src, filename, options = {} }) { const { lessOptions = {} } = options; @@ -56,7 +57,7 @@ function transform({ filename, options, plugins, src }) { cwd: options.projectRoot, highlightCode: true, filename, - plugins: plugins.concat([replaceEnvExpressionPlugin, oakPathTsxPlugin, oakRenderNativePlugin, oakI18nPlugin]), + plugins: plugins.concat([replaceEnvExpressionPlugin, oakPathTsxPlugin, oakRenderNativePlugin, oakI18nPlugin, reuseOakComponentPlugin]), sourceType: "module", // NOTE(EvanBacon): We split the parse/transform steps up to accommodate // Hermes parsing, but this defaults to cloning the AST which increases diff --git a/config/web/webpack.config.js b/config/web/webpack.config.js index e6fe325..eae7ad8 100644 --- a/config/web/webpack.config.js +++ b/config/web/webpack.config.js @@ -31,6 +31,7 @@ const createEnvironmentHash = require('./webpack/persistentCache/createEnvironme const oakPathTsxPlugin = require('../babel-plugin/oakPath'); const oakRenderTsxPlugin = require('../babel-plugin/oakRender'); +const oakGetAppVersionPlugin = require('../babel-plugin/oakGetAppVersion'); // const oakRouterPlugin = require('../babel-plugin/oakRouter2'); const oakI18nPlugin = require('../babel-plugin/oakI18n'); const oakStylePlugin = require('../babel-plugin/oakStyle'); @@ -609,6 +610,7 @@ module.exports = function (webpackEnv) { oakRenderTsxPlugin, // oakRouterPlugin, oakI18nPlugin, + oakGetAppVersionPlugin, reuseOakComponentPlugin, // [ // 'import', diff --git a/template/src/exceptionHandler.ts b/template/src/exceptionHandler.ts index 4dd70f5..0069bad 100644 --- a/template/src/exceptionHandler.ts +++ b/template/src/exceptionHandler.ts @@ -11,6 +11,7 @@ import { FeatureDict } from '@project/features'; import { AFD } from '@project/types/RuntimeCxt'; import { OakApplicationLoadingException, OakHasToVerifyPassword, OakPasswordUnset, OakUserInfoLoadingException } from 'oak-general-business'; // import { OakUserInfoLoadingException, OakApplicationLoadingException } from 'oak-general-business'; +import { MessageProps } from 'oak-frontend-base'; function showMessage(reason: OakException, features: AFD, type?: MessageProps['type']) { const { message, _module, params} = reason;