diff --git a/packages/build/src/build/buildPages/buildTestPage.js b/packages/build/src/build/buildPages/buildTestPage.js new file mode 100644 index 000000000..578013be7 --- /dev/null +++ b/packages/build/src/build/buildPages/buildTestPage.js @@ -0,0 +1,44 @@ +/* + Copyright 2020-2022 Lowdefy, Inc + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +// Used in @lowdefy/engine tests + +import buildAuth from '../buildAuth/buildAuth.js'; +import buildPages from './buildPages.js'; +import createContext from '../../createContext.js'; + +function buildTestPage({ pageConfig }) { + const context = createContext({ + customTypesMap: {}, + directories: {}, + logger: { + debug: () => {}, + log: () => {}, + warn: () => {}, + error: () => {}, + }, + stage: 'test', + }); + const components = { + pages: [pageConfig], + }; + buildAuth({ components, context }); + buildPages({ components, context }); + + return components.pages[0]; +} + +export default buildTestPage; diff --git a/packages/build/src/createContext.js b/packages/build/src/createContext.js index 9605cf18a..b91703840 100644 --- a/packages/build/src/createContext.js +++ b/packages/build/src/createContext.js @@ -24,10 +24,9 @@ import createReadConfigFile from './utils/readConfigFile.js'; import createWriteBuildArtifact from './utils/writeBuildArtifact.js'; const require = createRequire(import.meta.url); +const defaultTypesMap = require('./defaultTypesMap.json'); function createContext({ customTypesMap, directories, logger, refResolver, stage = 'prod' }) { - const defaultTypesMap = require('./defaultTypesMap.json'); - const context = { directories, logger, diff --git a/packages/cli/src/index.js b/packages/cli/src/index.js index 8eea978bf..765c3c707 100755 --- a/packages/cli/src/index.js +++ b/packages/cli/src/index.js @@ -15,7 +15,7 @@ limitations under the License. */ -import { fileURLToPath } from 'url'; +import { createRequire } from 'module'; import { readFile } from '@lowdefy/node-utils'; import { Command } from 'commander'; @@ -26,9 +26,9 @@ import init from './commands/init/init.js'; import start from './commands/start/start.js'; import runCommand from './utils/runCommand.js'; -const packageJson = JSON.parse( - await readFile(fileURLToPath(new URL('../package.json', import.meta.url))) -); +const require = createRequire(import.meta.url); + +const packageJson = require('../package.json'); const { description, version: cliVersion } = packageJson; const program = new Command();