diff --git a/plugins/headlamp-plugin/bin/headlamp-plugin.js b/plugins/headlamp-plugin/bin/headlamp-plugin.js index 13522ef6a95..2d4e7de6d5c 100755 --- a/plugins/headlamp-plugin/bin/headlamp-plugin.js +++ b/plugins/headlamp-plugin/bin/headlamp-plugin.js @@ -58,7 +58,7 @@ function create(name, link) { .split('$${name}') .join(name) .split('$${headlamp-plugin-version}') - .join(headlampPluginPkg.version) + .join(headlampPluginPkg.version), ); } @@ -84,7 +84,7 @@ function create(name, link) { }); } catch (e) { console.error( - `Problem running npm install inside of "${dstFolder}" abs: "${resolve(dstFolder)}"` + `Problem running npm install inside of "${dstFolder}" abs: "${resolve(dstFolder)}"`, ); return 3; } @@ -231,7 +231,7 @@ function extract(pluginPackagesPath, outputPlugins) { /** * Start watching for changes, and build again if there are changes. - * @returns {0} Exit code, where 0 is success. + * @returns {number} - Exit code, where 0 is success. */ function start() { /** @@ -271,22 +271,31 @@ function start() { /** * Inform if @kinvolk/headlamp-plugin is outdated. */ - function informIfOutdated() { - console.log('Checking if headlamp-plugin is up to date...'); - const outdated = getNpmOutdated(); - if ('@kinvolk/headlamp-plugin' in outdated) { - const url = `https://github.com/kinvolk/headlamp/releases`; - console.warn( - ' @kinvolk/headlamp-plugin is out of date. Run the following command to upgrade \n' + - ` See release notes here: ${url}` + - ' npx @kinvolk/headlamp-plugin upgrade' - ); - } else { - console.log(' @kinvolk/headlamp-plugin is up to date.'); - } + async function informIfOutdated() { + console.log('Checking if @kinvolk/headlamp-plugin is up to date...'); + child_process.exec('npm outdated --json', (error, stdout) => { + if (error) { + // npm outdated exit codes 1 when something is not up to date. + const result = stdout.toString(); + const outdated = JSON.parse(result); + if ('@kinvolk/headlamp-plugin' in outdated) { + const url = `https://github.com/headlamp-k8s/headlamp/releases`; + console.warn( + ' @kinvolk/headlamp-plugin is out of date. Run the following command to upgrade \n' + + ` See release notes here: ${url}` + + ' npx @kinvolk/headlamp-plugin upgrade', + ); + return; + } + } + }); } - informIfOutdated(); + setTimeout(() => { + informIfOutdated().catch(error => { + console.error('Error checking if @kinvolk/headlamp-plugin is up to date:', error); + }); + }, 500); config.watch = true; config.mode = 'development'; @@ -373,7 +382,7 @@ function runScriptOnPackages(packageFolder, scriptName, cmdLine, env) { '..', '..', '..', - nodeModulesBinCmd + nodeModulesBinCmd, ); if (fs.existsSync(nodeModulesBinCmd)) { @@ -385,8 +394,8 @@ function runScriptOnPackages(packageFolder, scriptName, cmdLine, env) { } else { console.warn( `"${scriptCmd}" not found in "${resolve(nodeModulesBinCmd)}" or "${resolve( - upNodeModulesBinCmd - )}" or "${resolve(npxBinCmd)}".` + upNodeModulesBinCmd, + )}" or "${resolve(npxBinCmd)}".`, ); } @@ -432,7 +441,7 @@ function runScriptOnPackages(packageFolder, scriptName, cmdLine, env) { }; }); const failedErrorFolders = errorFolders.filter( - errFolder => errFolder.error !== runOnPackageReturn.success + errFolder => errFolder.error !== runOnPackageReturn.success, ); if (failedErrorFolders.length === 0) { @@ -453,14 +462,14 @@ function runScriptOnPackages(packageFolder, scriptName, cmdLine, env) { const folderErr = runOnFolderOfPackages(packageFolder); if (folderErr.error === runOnPackageReturn.notThere) { console.error( - `"${resolve(packageFolder)}" does not contain a package or packages. Not ${scriptName}-ing.` + `"${resolve(packageFolder)}" does not contain a package or packages. Not ${scriptName}-ing.`, ); return 1; // failed } else if (folderErr.error === runOnPackageReturn.issue) { console.error( `Some in "${resolve(packageFolder)}" failed. Failed folders: ${folderErr.failedFolders.join( - ', ' - )}` + ', ', + )}`, ); return 1; // failed } @@ -681,7 +690,7 @@ function upgrade(packageFolder, skipPackageUpdates, headlampPluginVersion) { const templateFolder = path.resolve(__dirname, '..', 'template'); const packageJsonPath = path.join('.', 'package.json'); const templatePackageJson = JSON.parse( - fs.readFileSync(path.join(templateFolder, 'package.json'), 'utf8') + fs.readFileSync(path.join(templateFolder, 'package.json'), 'utf8'), ); const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); let configChanged = false; @@ -702,8 +711,8 @@ function upgrade(packageFolder, skipPackageUpdates, headlampPluginVersion) { configChanged = true; console.log( `Updated package.json field ${keyName}.${key}: ${JSON.stringify( - packageJson[keyName][key] - )}` + packageJson[keyName][key], + )}`, ); } }); @@ -859,7 +868,7 @@ function upgrade(packageFolder, skipPackageUpdates, headlampPluginVersion) { for (const folder of packageFolders) { if (failed) { console.error( - `Skipping "${folder.name}", because "${failed}" did not upgrade successfully.` + `Skipping "${folder.name}", because "${failed}" did not upgrade successfully.`, ); continue; } @@ -940,11 +949,11 @@ function storybook(packageFolder) { stdio: 'inherit', cwd: packageFolder, encoding: 'utf8', - } + }, ); } catch (e) { console.error( - `Problem running storybook dev inside of "${packageFolder}" abs: "${resolve(packageFolder)}"` + `Problem running storybook dev inside of "${packageFolder}" abs: "${resolve(packageFolder)}"`, ); return 1; } @@ -990,7 +999,7 @@ yargs(process.argv.slice(2)) }, argv => { process.exitCode = build(argv.package); - } + }, ) .command('start', 'Watch for changes and build plugin.', {}, () => { process.exitCode = start(); @@ -1012,7 +1021,7 @@ yargs(process.argv.slice(2)) }, argv => { process.exitCode = create(argv.name, argv.link); - } + }, ) .command( 'extract ', @@ -1035,7 +1044,7 @@ yargs(process.argv.slice(2)) }, argv => { process.exitCode = extract(argv.pluginPackages, argv.outputPlugins); - } + }, ) .command( 'format [package]', @@ -1055,7 +1064,7 @@ yargs(process.argv.slice(2)) }, argv => { process.exitCode = format(argv.package, argv.check); - } + }, ) .command( 'lint [package]', @@ -1076,7 +1085,7 @@ yargs(process.argv.slice(2)) }, argv => { process.exitCode = lint(argv.package, argv.fix); - } + }, ) .command( 'tsc [package]', @@ -1092,7 +1101,7 @@ yargs(process.argv.slice(2)) }, argv => { process.exitCode = tsc(argv.package); - } + }, ) .command( 'storybook [package]', @@ -1106,7 +1115,7 @@ yargs(process.argv.slice(2)) }, argv => { process.exitCode = storybook(argv.package); - } + }, ) .command( 'storybook-build [package]', @@ -1121,7 +1130,7 @@ yargs(process.argv.slice(2)) }, argv => { process.exitCode = storybook_build(argv.package); - } + }, ) .command( 'upgrade [package]', @@ -1147,7 +1156,7 @@ yargs(process.argv.slice(2)) }, argv => { process.exitCode = upgrade(argv.package, argv.skipPackageUpdates, argv.headlampPluginVersion); - } + }, ) .command( 'test [package]', @@ -1161,7 +1170,7 @@ yargs(process.argv.slice(2)) }, argv => { process.exitCode = test(argv.package); - } + }, ) .demandCommand(1, '') .strict()