Skip to content
This repository has been archived by the owner on Dec 21, 2022. It is now read-only.

Commit

Permalink
Merge branch 'fix/npm-release-error' of https://github.com/mendix/wid…
Browse files Browse the repository at this point in the history
…gets-resources into fix/npm-release-error
  • Loading branch information
undefined committed Sep 22, 2021
2 parents c4a5fc3 + 446342e commit e9ef9e1
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions scripts/release/copyReleaseToProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@ const { cp } = require("shelljs");

const pluggableWidgetsFolderPath = join(process.cwd(), "packages/pluggableWidgets");

(async () => {
main().catch(e => {
console.error(e);
process.exit(-1);
});

async function main() {
if (!process.env.MX_PROJECT_PATH) {
throw new Error(`Environment variable "MX_PROJECT_PATH" is not defined.`);
}
console.log(`Copying over widgets to ${process.env.MX_PROJECT_PATH}..`);
// Get pluggable widget folders containing "-native"
const pluggableWidgetsPaths = await asyncFilter(await readdir(pluggableWidgetsFolderPath), isNativeWidgetFolder);
const widgetFolderNames = await asyncFilter(await readdir(pluggableWidgetsFolderPath), isNativeWidgetFolder);
const mpkPathsToCopy = [];
for await (const widgetFolderName of pluggableWidgetsPaths) {
for await (const widgetFolderName of widgetFolderNames) {
const widgetDistFolderPath = join(pluggableWidgetsFolderPath, widgetFolderName, "dist");
const widgetDistPaths = await readdir(widgetDistFolderPath);
const widgetDistFolderNames = await readdir(widgetDistFolderPath);
const allMpkPaths = [];

for await (const widgetDistFolderName of widgetDistPaths) {
for await (const widgetDistFolderName of widgetDistFolderNames) {
// Check if folder name contains versioning
if (!/\d+\.\d+\.\d+/.test(widgetDistFolderName)) {
continue;
Expand All @@ -41,18 +46,14 @@ const pluggableWidgetsFolderPath = join(process.cwd(), "packages/pluggableWidget
console.log(
`Finished copying ${mpkPathsToCopy.length} widgets to Mendix project ${basename(process.env.MX_PROJECT_PATH)}`
);
})();
};

async function asyncFilter(array, fn) {
return Promise.all(array.map(fn)).then(booleans => array.filter((_, i) => booleans[i]));
}

async function isDirectory(path) {
return (await stat(path)).isDirectory();
}

async function isNativeWidgetFolder(widgetFolderName) {
return widgetFolderName.includes("-native") && isDirectory(join(pluggableWidgetsFolderPath, widgetFolderName));
return widgetFolderName.includes("-native") && (await stat(join(pluggableWidgetsFolderPath, widgetFolderName))).isDirectory();
}

async function getFileModifiedTime(path) {
Expand Down

0 comments on commit e9ef9e1

Please sign in to comment.