From 5405a2b3c8d7a1006929b33f13fdb7a36d992fd0 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Mon, 6 Jan 2020 11:30:04 +0100 Subject: [PATCH] update package.json on plugin postinstall This is required in order to fix autocomplete of intellij. --- scm-ui/ui-plugins/bin/ui-plugins.js | 42 ++++++++++++++++ scm-ui/ui-plugins/package.json | 29 ++++++----- scm-ui/ui-plugins/src/commands/postinstall.js | 49 +++++++++++++++++++ scm-ui/ui-scripts/bin/ui-scripts.js | 20 +++----- 4 files changed, 116 insertions(+), 24 deletions(-) create mode 100644 scm-ui/ui-plugins/bin/ui-plugins.js create mode 100644 scm-ui/ui-plugins/src/commands/postinstall.js diff --git a/scm-ui/ui-plugins/bin/ui-plugins.js b/scm-ui/ui-plugins/bin/ui-plugins.js new file mode 100644 index 0000000000..0eba2c9333 --- /dev/null +++ b/scm-ui/ui-plugins/bin/ui-plugins.js @@ -0,0 +1,42 @@ +#!/usr/bin/env node +/* eslint-disable no-console */ +const { spawnSync } = require("child_process"); + +const commands = ["postinstall"]; + +const args = process.argv.slice(2); + +const commandIndex = args.findIndex(arg => { + return commands.includes(arg); +}); + +const command = commandIndex === -1 ? args[0] : args[commandIndex]; +const nodeArgs = commandIndex > 0 ? args.slice(0, commandIndex) : []; + +if (commands.includes(command)) { + const result = spawnSync( + "node", + nodeArgs.concat(require.resolve("../src/commands/" + command)).concat(args.slice(commandIndex + 1)), + { stdio: "inherit" } + ); + if (result.signal) { + if (result.signal === "SIGKILL") { + console.log( + "The build failed because the process exited too early. " + + "This probably means the system ran out of memory or someone called " + + "`kill -9` on the process." + ); + } else if (result.signal === "SIGTERM") { + console.log( + "The build failed because the process exited too early. " + + "Someone might have called `kill` or `killall`, or the system could " + + "be shutting down." + ); + } + process.exit(1); + } + process.exit(result.status); +} else { + console.log(`Unknown script "${command}".`); + console.log("Perhaps you need to update ui-plugins?"); +} diff --git a/scm-ui/ui-plugins/package.json b/scm-ui/ui-plugins/package.json index 2e1fdb119f..d48bdbb3fd 100644 --- a/scm-ui/ui-plugins/package.json +++ b/scm-ui/ui-plugins/package.json @@ -1,15 +1,28 @@ { "name": "@scm-manager/ui-plugins", - "version": "2.0.0-SNAPSHOT", + "version": "2.0.0-11", "license": "BSD-3-Clause", + "bin": { + "ui-plugins": "./bin/ui-plugins.js" + }, "dependencies": { + "@scm-manager/ui-components": "^2.0.0-SNAPSHOT", + "@scm-manager/ui-extensions": "^2.0.0-SNAPSHOT", + "classnames": "^2.2.6", + "query-string": "^5.0.1", + "react": "^16.10.2", + "react-i18next": "^10.13.1", + "react-redux": "^5.0.7", + "react-router-dom": "^5.1.2", + "redux": "^4.0.0", + "styled-components": "^4.4.0" + }, + "devDependencies": { "@scm-manager/babel-preset": "^2.0.0-SNAPSHOT", "@scm-manager/eslint-config": "^2.0.0-SNAPSHOT", "@scm-manager/jest-preset": "^2.0.0-SNAPSHOT", "@scm-manager/prettier-config": "^2.0.0-SNAPSHOT", "@scm-manager/tsconfig": "^2.0.0-SNAPSHOT", - "@scm-manager/ui-components": "^2.0.0-SNAPSHOT", - "@scm-manager/ui-extensions": "^2.0.0-SNAPSHOT", "@scm-manager/ui-scripts": "^2.0.0-SNAPSHOT", "@scm-manager/ui-tests": "^2.0.0-SNAPSHOT", "@scm-manager/ui-types": "^2.0.0-SNAPSHOT", @@ -23,15 +36,7 @@ "@types/react-redux": "5.0.7", "@types/react-router-dom": "^5.1.0", "@types/styled-components": "^4.1.19", - "classnames": "^2.2.6", - "jest": "^24.9.0", - "query-string": "^5.0.1", - "react": "^16.10.2", - "react-i18next": "^10.13.1", - "react-redux": "^5.0.7", - "react-router-dom": "^5.1.2", - "redux": "^4.0.0", - "styled-components": "^4.4.0" + "jest": "^24.9.0" }, "publishConfig": { "access": "public" diff --git a/scm-ui/ui-plugins/src/commands/postinstall.js b/scm-ui/ui-plugins/src/commands/postinstall.js new file mode 100644 index 0000000000..d38ad8d01e --- /dev/null +++ b/scm-ui/ui-plugins/src/commands/postinstall.js @@ -0,0 +1,49 @@ +/* eslint-disable no-console */ +const path = require("path"); +const fs = require("fs"); +const { spawnSync } = require("child_process"); + +const packageJsonPath = path.join(process.cwd(), "package.json"); +const packageJSON = JSON.parse(fs.readFileSync(packageJsonPath, "UTF-8")); + +const reference = require("../../package.json"); + +const sync = (left, right, key) => { + if (!right[key]) { + right[key] = {}; + } + + let changed = false; + + const keys = Object.keys(left[key]); + keys.forEach(name => { + if (right[key][name] !== left[key][name]) { + console.log(name, "has changed from", right[key][name], "to", left[key][name]); + right[key][name] = left[key][name]; + changed = true; + } + }); + + return changed; +}; + +const update = () => { + let dep = sync(reference, packageJSON, "dependencies"); + let devDep = sync(reference, packageJSON, "devDependencies"); + return dep || devDep; +}; + +if (update()) { + console.log("dependencies changed, install new dependencies"); + + fs.writeFileSync(packageJsonPath, JSON.stringify(packageJSON, null, " "), { encoding: "UTF-8" }); + + const result = spawnSync("yarn", ["install"], { stdio: "inherit" }); + if (result.error) { + console.log("could not start yarn command:", result.error); + process.exit(2); + } else if (result.status !== 0) { + console.log("yarn process ends with status code:", result.status); + process.exit(3); + } +} diff --git a/scm-ui/ui-scripts/bin/ui-scripts.js b/scm-ui/ui-scripts/bin/ui-scripts.js index 28f5ef3315..db2f003b74 100755 --- a/scm-ui/ui-scripts/bin/ui-scripts.js +++ b/scm-ui/ui-scripts/bin/ui-scripts.js @@ -1,4 +1,5 @@ #!/usr/bin/env node +/* eslint-disable no-console */ const { spawnSync } = require("child_process"); const commands = ["plugin", "plugin-watch", "publish", "version"]; @@ -15,32 +16,27 @@ const nodeArgs = commandIndex > 0 ? args.slice(0, commandIndex) : []; if (commands.includes(command)) { const result = spawnSync( "node", - nodeArgs - .concat(require.resolve("../src/commands/" + command)) - .concat(args.slice(commandIndex + 1)), + nodeArgs.concat(require.resolve("../src/commands/" + command)).concat(args.slice(commandIndex + 1)), { stdio: "inherit" } ); if (result.signal) { if (result.signal === "SIGKILL") { console.log( "The build failed because the process exited too early. " + - "This probably means the system ran out of memory or someone called " + - "`kill -9` on the process." + "This probably means the system ran out of memory or someone called " + + "`kill -9` on the process." ); } else if (result.signal === "SIGTERM") { console.log( "The build failed because the process exited too early. " + - "Someone might have called `kill` or `killall`, or the system could " + - "be shutting down." + "Someone might have called `kill` or `killall`, or the system could " + + "be shutting down." ); } process.exit(1); } process.exit(result.status); } else { - console.log("Unknown script \"" + command + "\"."); - console.log("Perhaps you need to update react-scripts?"); - console.log( - "See: https://facebook.github.io/create-react-app/docs/updating-to-new-releases" - ); + console.log(`Unknown script "${command}".`); + console.log("Perhaps you need to update ui-scripts?"); }