From 954728dfed5abb71c25084c6f6a9f74b8860104b Mon Sep 17 00:00:00 2001 From: Roland Szoke Date: Thu, 27 Feb 2020 15:27:40 +0100 Subject: [PATCH 1/2] ci(examples): start locally linked example with npm script --- package-lock.json | 77 +++++++++++++++++++------------- package.json | 8 +++- rollup.config.js | 2 +- scripts/startExample.js | 99 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 154 insertions(+), 32 deletions(-) create mode 100644 scripts/startExample.js diff --git a/package-lock.json b/package-lock.json index 3327066..ff20929 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5290,6 +5290,53 @@ "integrity": "sha512-ng6Tm537E/M42GjE4TRUxQyL8sRfClcL7bQWblOCoxPZzJ2J3bdALsjeG3vDnVCIfI/R0AeFalN9KjMt0+Z/Zg==", "dev": true }, + "@rollup/plugin-node-resolve": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-7.1.1.tgz", + "integrity": "sha512-14ddhD7TnemeHE97a4rLOhobfYvUVcaYuqTnL8Ti7Jxi9V9Jr5LY7Gko4HZ5k4h4vqQM0gBQt6tsp9xXW94WPA==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^3.0.6", + "@types/resolve": "0.0.8", + "builtin-modules": "^3.1.0", + "is-module": "^1.0.0", + "resolve": "^1.14.2" + }, + "dependencies": { + "builtin-modules": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.1.0.tgz", + "integrity": "sha512-k0KL0aWZuBt2lrxrcASWDfwOLMnodeQjodT/1SxEQAXsHANgo6ZC/VEaSEHCXt7aSTZ4/4H5LKa+tBXmW7Vtvw==", + "dev": true + }, + "resolve": { + "version": "1.15.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.15.1.tgz", + "integrity": "sha512-84oo6ZTtoTUpjgNEr5SJyzQhzL72gaRodsSfyxC/AXRvwu0Yse9H8eF9IpGo7b8YetZhlI6v7ZQ6bKBFV/6S7w==", + "dev": true, + "requires": { + "path-parse": "^1.0.6" + } + } + } + }, + "@rollup/pluginutils": { + "version": "3.0.8", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.0.8.tgz", + "integrity": "sha512-rYGeAc4sxcZ+kPG/Tw4/fwJODC3IXHYDH4qusdN/b6aLw5LPUbzpecYbEJh4sVQGPFJxd2dBU4kc1H3oy9/bnw==", + "dev": true, + "requires": { + "estree-walker": "^1.0.1" + }, + "dependencies": { + "estree-walker": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", + "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==", + "dev": true + } + } + }, "@sheerun/mutationobserver-shim": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/@sheerun/mutationobserver-shim/-/mutationobserver-shim-0.3.2.tgz", @@ -18699,36 +18746,6 @@ "rollup-pluginutils": "^2.8.1" } }, - "rollup-plugin-node-resolve": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-5.2.0.tgz", - "integrity": "sha512-jUlyaDXts7TW2CqQ4GaO5VJ4PwwaV8VUGA7+km3n6k6xtOEacf61u0VXwN80phY/evMcaS+9eIeJ9MOyDxt5Zw==", - "dev": true, - "requires": { - "@types/resolve": "0.0.8", - "builtin-modules": "^3.1.0", - "is-module": "^1.0.0", - "resolve": "^1.11.1", - "rollup-pluginutils": "^2.8.1" - }, - "dependencies": { - "builtin-modules": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.1.0.tgz", - "integrity": "sha512-k0KL0aWZuBt2lrxrcASWDfwOLMnodeQjodT/1SxEQAXsHANgo6ZC/VEaSEHCXt7aSTZ4/4H5LKa+tBXmW7Vtvw==", - "dev": true - }, - "resolve": { - "version": "1.15.1", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.15.1.tgz", - "integrity": "sha512-84oo6ZTtoTUpjgNEr5SJyzQhzL72gaRodsSfyxC/AXRvwu0Yse9H8eF9IpGo7b8YetZhlI6v7ZQ6bKBFV/6S7w==", - "dev": true, - "requires": { - "path-parse": "^1.0.6" - } - } - } - }, "rollup-pluginutils": { "version": "2.8.2", "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz", diff --git a/package.json b/package.json index 1cbca10..dd880e8 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,12 @@ "test-web": "jest --config ./jest.web.json", "test-web-no-hook": "NOHOOK=true jest --config ./jest.no-hook.json", "test": "npm run test-web && npm run test-web-no-hook && npm run test-native", + "example-beer-finder": "node ./scripts/startExample.js ./examples/beer-finder", + "example-clock": "node ./scripts/startExample.js ./examples/clock", + "example-contacts": "node ./scripts/startExample.js ./examples/contacts", + "example-stop-watch": "node ./scripts/startExample.js ./examples/stop-watch", + "example-todo-mvc": "node ./scripts/startExample.js ./examples/todo-mvc", + "example-native-clock": "node ./scripts/startExample.js ./examples/native-clock", "coveralls": "cat ./coverage/lcov.info | coveralls", "test-builds": "node ./scripts/testBuilds.js", "lint": "eslint --max-warnings 0 --ext js,jsx src scripts", @@ -76,6 +82,7 @@ "@babel/preset-react": "^7.8.3", "@commitlint/cli": "^8.3.5", "@commitlint/config-angular": "^8.3.4", + "@rollup/plugin-node-resolve": "^7.1.1", "@testing-library/jest-dom": "^5.1.1", "@testing-library/react": "^9.4.0", "@types/react": "^16.9.19", @@ -108,7 +115,6 @@ "rollup": "^1.31.0", "rollup-plugin-auto-external": "^2.0.0", "rollup-plugin-babel": "^4.3.3", - "rollup-plugin-node-resolve": "^5.2.0", "sinon": "^8.1.1", "styled-components": "^5.0.1" }, diff --git a/rollup.config.js b/rollup.config.js index c4969f8..e5cd63f 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,5 +1,5 @@ import path from 'path'; -import resolvePlugin from 'rollup-plugin-node-resolve'; +import resolvePlugin from '@rollup/plugin-node-resolve'; import babelPlugin from 'rollup-plugin-babel'; import externalsPlugin from 'rollup-plugin-auto-external'; diff --git a/scripts/startExample.js b/scripts/startExample.js new file mode 100644 index 0000000..aa1f9d2 --- /dev/null +++ b/scripts/startExample.js @@ -0,0 +1,99 @@ +/* eslint-disable no-console */ +const path = require('path'); +const { execSync: exec } = require('child_process'); +const rollup = require('rollup'); +const resolvePlugin = require('@rollup/plugin-node-resolve'); +const babelPlugin = require('rollup-plugin-babel'); +const externalsPlugin = require('rollup-plugin-auto-external'); + +console.customInfo = args => { + console.info( + '\x1b[44m\x1b[37m', + '\u2139', + '\x1b[0m', + '\x1b[36m', + args, + '\x1b[0m', + ); +}; + +const exampleFolder = path.resolve(process.argv[2]); + +// 1. BUILD EASY-STATE BUNDLE +console.customInfo('Building react-easy-state in watch mode.'); +const watchOptions = { + input: path.resolve('src/index.js'), + plugins: [ + resolvePlugin(), + babelPlugin({ exclude: 'node_modules/**' }), + externalsPlugin({ dependencies: true, peerDependecies: true }), + ], + output: { + format: 'es', + dir: 'dist', + entryFileNames: 'es.es6.js', + sourcemap: true, + }, + watch: { + include: 'src/**', + }, +}; +const watcher = rollup.watch(watchOptions); +watcher.on('event', ({ code }) => { + if (code === 'START') { + console.customInfo('Building bundle.'); + } else if (code === 'END') { + console.customInfo('Bundle built!'); + } else if (code === 'ERROR') { + console.customInfo('Encountered an error while bundling!'); + } +}); + +// 2. LINK EASY-STATE +console.customInfo('Create link to react-easy-state.'); +exec('npm link', { stdio: 'inherit' }); +console.customInfo('Installing dependencies for example.'); +exec('npm i', { + cwd: exampleFolder, + stdio: 'inherit', +}); +console.customInfo('Deleting react dependency duplicates.'); +exec( + ` +rm -rf ./node_modules/react-easy-state && +rm -rf ./node_modules/react && +rm -rf ./node_modules/react-dom + `, + { + cwd: exampleFolder, + stdio: 'inherit', + }, +); +console.customInfo('Linking react-easy-state.'); +exec('npm link react-easy-state', { + cwd: exampleFolder, + stdio: 'inherit', +}); + +// 3. START EXAMPLE +console.customInfo(`Starting ${process.argv[2]} in the background.`); +exec("nohup bash -c 'npm run start' >/dev/null 2>&1 &", { + cwd: exampleFolder, + stdio: 'inherit', +}); + +const gracefullShutdown = () => { + console.customInfo('Killing nodes.'); + exec('killall node', { stdio: 'inherit' }); + console.customInfo('Unlinking react-easy-state.'); + exec('npm unlink --no-save react-easy-state', { + cwd: exampleFolder, + stdio: 'inherit', + }); + exec('npm unlink', { stdio: 'inherit' }); + console.customInfo('Stoping bundle builder.'); + watcher.close(); +}; + +process.on('SIGINT', gracefullShutdown); +process.on('SIGTERM', gracefullShutdown); From 488fe9b62f49ad9e0308e3b81196c37230b0442b Mon Sep 17 00:00:00 2001 From: Roland Szoke Date: Wed, 4 Mar 2020 14:53:00 +0100 Subject: [PATCH 2/2] ci(examples): show logs and errors of nohup process --- .gitignore | 1 + scripts/startExample.js | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 5ac0c8f..dccffba 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ logs npm-debug.log* yarn-debug.log* yarn-error.log* +nohup.out # Runtime data pids diff --git a/scripts/startExample.js b/scripts/startExample.js index aa1f9d2..ad64871 100644 --- a/scripts/startExample.js +++ b/scripts/startExample.js @@ -77,20 +77,26 @@ exec('npm link react-easy-state', { // 3. START EXAMPLE console.customInfo(`Starting ${process.argv[2]} in the background.`); -exec("nohup bash -c 'npm run start' >/dev/null 2>&1 &", { - cwd: exampleFolder, - stdio: 'inherit', -}); +exec( + "nohup bash -c 'npm run start' 2>&1 > nohup.out & tail -f nohup.out &", + { + cwd: exampleFolder, + stdio: 'inherit', + }, +); const gracefullShutdown = () => { console.customInfo('Killing nodes.'); exec('killall node', { stdio: 'inherit' }); + exec('rm nohup.out', { + cwd: exampleFolder, + stdio: 'inherit', + }); console.customInfo('Unlinking react-easy-state.'); exec('npm unlink --no-save react-easy-state', { cwd: exampleFolder, stdio: 'inherit', }); - exec('npm unlink', { stdio: 'inherit' }); console.customInfo('Stoping bundle builder.'); watcher.close(); };