Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

headlamp-plugin: Make the package arg of the build command optional #321

Merged
merged 5 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ jobs:
run: |
make frontend-build

- name: Test plugins
run: |
make plugins-test
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ frontend-tsc:
frontend-test:
cd frontend && npm run test -- --coverage

plugins-test:
cd plugins/headlamp-plugin && ./test-headlamp-plugin.sh

image:
$(DOCKER_CMD) build \
--build-arg IMAGE_BASE=$(DOCKER_IMAGE_BASE) \
Expand Down
37 changes: 26 additions & 11 deletions plugins/headlamp-plugin/bin/headlamp-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ const yargs = require('yargs/yargs');
* Then runs npm install inside of the folder.
*
* @param {string} name - name of package and output folder.
* @param {bool} link - if we link @kinvolk/headlamp-plugin for testing
*/
function create(name) {
function create(name, link) {
const dstFolder = name;
const templateFolder = path.resolve(__dirname, '..', 'template');
const indexPath = path.join(dstFolder, 'src', 'index.tsx');
const packagePath = path.join(dstFolder, 'package.json');
const packageLockPath = path.join(dstFolder, 'package-lock.json');

if (fs.existsSync(name)) {
console.error(`"${name}" already exists, not initializing`);
Expand All @@ -50,18 +52,27 @@ function create(name) {
}

replaceFileVariables(packagePath);
replaceFileVariables(packageLockPath);
replaceFileVariables(indexPath);

console.log('Installing dependencies...');

// This can be used to make testing locally easier.
// const proc1 = child_process.spawnSync('npm', ['link', '@kinvolk/headlamp-plugin'], {cwd: dstFolder});
if (link) {
console.log('Linking @kinvolk/headlamp-plugin')
const proc1 = child_process.spawnSync('npm', ['link', '@kinvolk/headlamp-plugin'], {cwd: dstFolder});
}

console.log('Installing dependencies...');
// Run npm install.
const proc = child_process.spawnSync('npm', ['install'], {cwd: dstFolder});
process.stdout.write(proc.stdout);
process.stderr.write(proc.stderr);
if (proc.status !== 0) {
try {
child_process.execSync(
'npm install',
{
stdio: 'inherit',
cwd: dstFolder,
encoding : 'utf8',
}
);
} catch (e) {
console.error(`Problem running npm install inside of "${dstFolder}"`);
return 3;
}
Expand Down Expand Up @@ -267,8 +278,8 @@ function build(packageFolder) {
}

const argv = yargs(process.argv.slice(2))
.command('build <package>', (
'Build the plugin, or folder of plugins. ' +
.command('build [package]', (
'Build the plugin, or folder of plugins. ' +
'<package> defaults to current working directory.'
),
(yargs) => {
Expand All @@ -288,8 +299,12 @@ const argv = yargs(process.argv.slice(2))
describe: 'Name of package',
type: 'string',
})
.option("link", {
describe: "For testing, use npm link @kinvolk/headlamp-plugin.",
type: "boolean",
})
}, (argv) => {
process.exitCode = create(argv.name);
process.exitCode = create(argv.name, argv.link);
})
.command(
'extract <pluginPackages> <outputPlugins>',
Expand Down
Loading