Skip to content

Commit

Permalink
generate an umbraco-package.json file containing the general importma…
Browse files Browse the repository at this point in the history
…p of the backoffice
  • Loading branch information
iOvergaard committed Feb 15, 2024
1 parent 5b109fa commit 96a5958
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
23 changes: 23 additions & 0 deletions devops/build/create-umbraco-package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { createImportMap } from "../importmap/index.js";
import { writeFileSync, rmSync } from "fs";
import { packageJsonName, packageJsonVersion } from "../package/index.js";

const srcDir = './dist-cms';
const outputModuleList = `${srcDir}/umbraco-package.json`;
const importmap = createImportMap({ rootDir: '/umbraco/backoffice', additionalImports: {} });

const umbracoPackageJson = {
name: packageJsonName,
version: packageJsonVersion,
extensions: [],
importmap
};

try {
rmSync(outputModuleList, { force: true });
writeFileSync(outputModuleList, JSON.stringify(umbracoPackageJson));
console.log(`Wrote manifest to ${outputModuleList}`);
} catch (e) {
console.error(`Failed to write manifest to ${outputModuleList}`, e);
process.exit(1);
}
4 changes: 3 additions & 1 deletion devops/importmap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export const createImportMap = (args) => {
const moduleName = key.replace(/^\.\//, '');

// replace ./dist-cms with src and remove /index.js
const modulePath = value.replace(/^\.\/dist-cms/, args.rootDir).replace('.js', '.ts');
let modulePath = value;
if (typeof args.rootDir !== 'undefined') modulePath = modulePath.replace(/^\.\/dist-cms/, args.rootDir);
if (args.replaceModuleExtensions) modulePath = modulePath.replace('.js', '.ts');
console.log('replacing', value, 'with', modulePath)
const importAlias = `${packageJsonName}/${moduleName}`;

Expand Down
1 change: 1 addition & 0 deletions devops/package/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import { readFileSync } from 'fs';
export const packageJsonPath = 'package.json';
export const packageJsonData = JSON.parse(readFileSync(packageJsonPath).toString());
export const packageJsonName = packageJsonData.name;
export const packageJsonVersion = packageJsonData.version;
export const packageJsonExports = packageJsonData.exports;
1 change: 1 addition & 0 deletions devops/tsconfig/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const importmap = createImportMap({
additionalImports: {
'@umbraco-cms/internal/test-utils': './utils/test-utils.ts',
},
replaceModuleExtensions: true,
});

const paths = {};
Expand Down
1 change: 1 addition & 0 deletions web-test-runner.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default {
additionalImports: {
'@umbraco-cms/internal/test-utils': './utils/test-utils.ts',
},
replaceModuleExtensions: true,
}),
},
}),
Expand Down

0 comments on commit 96a5958

Please sign in to comment.