Skip to content

Commit

Permalink
chore: add nx (BuilderIO#890)
Browse files Browse the repository at this point in the history
* chore: add nx

* add secret env var

Co-authored-by: Sami Jaber <[email protected]>
  • Loading branch information
FrozenPandaz and samijaber authored Jan 18, 2023
1 parent 60a83c8 commit 06cc3da
Show file tree
Hide file tree
Showing 5 changed files with 477 additions and 56 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
push:
pull_request:

env:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}

jobs:
checks:
runs-on: ubuntu-latest
Expand Down
27 changes: 18 additions & 9 deletions e2e/e2e-app/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ async function yarn(...args) {
});
}

async function nxRunMany(target: string, projects: string[]) {
return new Promise((res, reject) => {
let child = spawn(`nx run-many --target ${target} --parallel 4 --projects ${projects.join()}`, {
cwd: resolve(__dirname, '../..'),
shell: true,
stdio: 'inherit',
});

child.on('error', reject);
child.on('exit', (code) => (code === 0 ? res(0) : reject(code)));
});
}

function allOk(specs: Entry[]) {
return specs.every((s) => s.ok);
}
Expand Down Expand Up @@ -96,9 +109,7 @@ async function main() {

// Clean the output - don't want Vite or other tools to leave behind
// previous app on failure.
for (const p of packages) {
await yarn('workspace', p, 'run', 'clean');
}
await nxRunMany('clean', packages);

// Mitosis all targets - with a workaround to tolerate failure, until:
// https://github.com/BuilderIO/mitosis/issues/510
Expand All @@ -108,12 +119,10 @@ async function main() {
// Ideally we could use Yarn Workspace, but it lacks a partial-success-OK flag.
// await yarn('workspaces', 'foreach', '-pt', '--include', '*/e2e-*', '--verbose', 'run', 'build');

for (const p of packages) {
try {
await yarn('workspace', p, 'run', 'build');
} catch (e) {
console.log('Failed', p, 'proceeding with E2E');
}
try {
await nxRunMany('build', packages);
} catch (e) {
console.log('Build Failed', 'proceeding with E2E');
}

// Invoke Playwright to test them all.
Expand Down
32 changes: 32 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"tasksRunnerOptions": {
"default": {
"runner": "@nrwl/nx-cloud",
"options": {
"cacheableOperations": [
"build"
],
"accessToken": "N2JjNTFkZDMtZmU1ZS00ZTU1LTgzMjYtYzNkMzFjYWNmYjFmfHJlYWQ="
}
}
},
"namedInputs": {
"default": ["{projectRoot}/**/*", "!{projectRoot}/dist/**/*"],
"production": []
},
"targetDefaults": {
"build": {
"dependsOn": [
"^build"
],
"inputs": [
"default",
"^default"
],
"outputs": [
"{projectRoot}/dist"
]
}
},
"defaultBase": "main"
}
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"npm": "99999999.9.9"
},
"scripts": {
"build:core": "yarn workspace @builder.io/mitosis run build",
"build:fiddle": "yarn workspace @builder.io/mitosis-fiddle run build",
"build:eslint-plugin": "yarn workspace @builder.io/eslint-plugin-mitosis run build",
"ci:build": "yarn workspaces foreach -pt --exclude \"*/e2e*\" --exclude @builder.io/mitosis-fiddle --exclude \"@builder.io/talk-*\" --verbose run build",
"build:core": "nx build @builder.io/mitosis",
"build:fiddle": "nx build @builder.io/mitosis-fiddle",
"build:eslint-plugin": "nx build @builder.io/eslint-plugin-mitosis",
"ci:build": "nx run-many --target build --parallel 4 --exclude \"*/e2e*,@builder.io/mitosis-fiddle,@builder.io/talk-*\"",
"ci:build:core": "yarn run build:core",
"ci:build:fiddle": "yarn run build:fiddle",
"ci:build:eslint-plugin": "yarn run build:eslint-plugin",
Expand All @@ -42,6 +42,7 @@
},
"devDependencies": {
"@babel/preset-env": "^7.6.0",
"@nrwl/nx-cloud": "15.0.2",
"@playwright/test": "1.24.0",
"@typescript-eslint/eslint-plugin": "^5.27.1",
"@typescript-eslint/parser": "^5.27.1",
Expand All @@ -52,6 +53,7 @@
"eslint-plugin-unused-imports": "^2.0.0",
"execa": "6.1.0",
"npm-run-all": "^4.1.5",
"nx": "15.4.5",
"prettier": "^2.3.2",
"typescript": "^4.8.4"
},
Expand Down
Loading

0 comments on commit 06cc3da

Please sign in to comment.