Skip to content

Commit

Permalink
feat(*): create mitosis build script
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabas-lesti committed Sep 28, 2024
1 parent 4a46068 commit f2a3f08
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 21,383 deletions.
21,371 changes: 0 additions & 21,371 deletions package-lock.json

This file was deleted.

2 changes: 0 additions & 2 deletions packages/ui.mitosis/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.angular
.turbo
node_modules
dist
/targets/**/src
4 changes: 2 additions & 2 deletions packages/ui.mitosis/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@wds/ui.mitosis",
"scripts": {
"dev": "watch \"npm run build\" ./src",
"build": "mitosis build --c mitosis.config.cjs",
"dev": "watch \"npm run build\" src targets",
"build": "node tools/build.cli.mjs",
"lint": "prettier . --check && eslint .",
"lint:fix": "prettier . --write && eslint . --fix"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/ui.mitosis/src/example/example.lite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import { type WdsExampleProps } from "./example.types";
* Example Mitosis generated component.
*/
export default function WdsExample(props: WdsExampleProps) {
return <p>Hello {props.name || "World"}!</p>;
return <p>Hello {props.name || "Woooorld"}!</p>;
}
9 changes: 5 additions & 4 deletions packages/ui.mitosis/targets/angular/package.target.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
"types": "./dist/index.d.ts"
},
"scripts": {
"dev": "ng build --watch",
"build": "ng build"
"dev": "watch \"npm run build\" src",
"build": "ng build && rimraf dist/package.json"
},
"peerDependencies": {
"@angular/common": "18.x",
"@angular/core": "18.x"
},
"devDependencies": {
"@wds/ui.mitosis": "*",
"@angular-devkit/build-angular": "^18.2.1",
"@angular/cli": "^18.2.0",
"@angular/compiler-cli": "^18.2.0",
"ng-packagr": "^18.2.0",
"typescript": "^5.5.2"
"typescript": "^5.5.2",
"rimraf": "^5.0.10",
"watch": "^1.0.2"
}
}
1 change: 0 additions & 1 deletion packages/ui.mitosis/targets/react/package.target.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"react": "18.x"
},
"devDependencies": {
"@wds/ui.mitosis": "*",
"@vitejs/plugin-react": "^4.3.1",
"vite": "^5.4.8",
"vite-plugin-dts": "^4.2.2",
Expand Down
1 change: 0 additions & 1 deletion packages/ui.mitosis/targets/vue/package.target.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"vue": "3.x"
},
"devDependencies": {
"@wds/ui.mitosis": "*",
"@vitejs/plugin-vue": "^5.1.4",
"vite": "^5.4.8",
"vite-plugin-dts": "^4.2.2",
Expand Down
1 change: 0 additions & 1 deletion packages/ui.mitosis/targets/vue/tsconfig.target.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"noEmit": true,

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
Expand Down
78 changes: 78 additions & 0 deletions packages/ui.mitosis/tools/build.cli.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// @ts-check

/* eslint-disable no-console */

import { exec } from "child_process";
import fs from "node:fs";
import path from "path";

import mitosisConfig from "../mitosis.config.cjs";

const MITOSIS_BUILD_SCRIPT = "mitosis build --c mitosis.config.cjs";
const BUILD_DIRECTORY = "dist";
const TARGETS = mitosisConfig.targets;
const TARGETS_DIRECTORY = "targets";
const TARGET_FILE_REPLACE_TOKEN = ".target";

(async () => {
await runMitosisBuild();
await copyTargetConfigFiles();
})();

/**
* Runs the Mitosis build script asynchronously.
* @returns {Promise<void>} Promise of the result.
*/
export function runMitosisBuild() {
return new Promise((resolve, reject) => {
exec(MITOSIS_BUILD_SCRIPT, (error, stdout, stderr) => {
// Run Mitosis build
if (stderr) {
reject(stderr);
return;
}

if (error) {
reject(error);
return;
}

console.log(stdout);
resolve();
});
});
}

/**
* Copies target configurations to build folder.
* @returns {Promise<void>} Promise of the result.
*/
function copyTargetConfigFiles() {
return new Promise((resolve, reject) => {
for (const target of TARGETS) {
const sourceFolder = path.resolve(process.cwd(), TARGETS_DIRECTORY, target);
const destinationFolder = path.resolve(process.cwd(), BUILD_DIRECTORY, target);

if (!fs.existsSync(destinationFolder)) {
fs.mkdirSync(destinationFolder, { recursive: true });
}

try {
const fileNames = fs.readdirSync(sourceFolder);
for (const fileName of fileNames) {
const sourceFilePath = path.join(sourceFolder, fileName);
const destinationFilePath = path.join(destinationFolder, fileName.replace(TARGET_FILE_REPLACE_TOKEN, ""));

fs.copyFileSync(sourceFilePath, destinationFilePath);
}

console.log(`Copied "${target}" target configurations to build folder.`);
} catch (error) {
reject(error);
break;
}
}

resolve();
});
}

0 comments on commit f2a3f08

Please sign in to comment.