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

Move scripts to bin field of package.json for cli hackery #1446

Merged
merged 2 commits into from May 11, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Expand Up @@ -35,6 +35,11 @@
"coverage": "codecov",
"watch": "npx nodemon --watch 'src' --ext 'ts' --exec npm run build"
},
"bin": {
"slack-cli-get-hooks": "./src/cli/get-hooks.js",
"slack-cli-get-manifest": "./src/cli/manifest.js",
"slack-cli-start": "./src/cli/start.js"
},
"repository": "slackapi/bolt",
"homepage": "https://slack.dev/bolt-js",
"bugs": {
Expand Down
16 changes: 16 additions & 0 deletions src/cli/get-hooks.js
@@ -0,0 +1,16 @@
#!/usr/bin/env node
console.log(JSON.stringify({
hooks: {
'get-manifest': 'npm exec --package=@slack/bolt slack-cli-get-manifest',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of npm exec!

start: 'npm exec --package=@slack/bolt slack-cli-start',
},
config: {
watch: {
'filter-regex': '^manifest\\.(ts|js|json)$',
paths: [
'.',
],
},
'sdk-managed-connection-enabled': true,
},
}));
17 changes: 17 additions & 0 deletions src/cli/manifest.js
@@ -0,0 +1,17 @@
#!/usr/bin/env node
// Manifest script hook returns a manifest JSON if it exists in the working directory
const fs = require('fs');
const path = require('path');
(function _(cwd) {
// TODO: Support additonal accepted formats
// const acceptedFormat = ['json', 'yml', 'ts'];
let fileData;
try {
fileData = fs.readFileSync(path.resolve(cwd, 'manifest.json'), 'utf8');
} catch (error) {
// TODO: Throw a coded error
console.error(`Failed to find a manifest file in this project: ${error}`);
process.exit(1);
}
console.log(JSON.stringify(JSON.parse(fileData)));
}(process.cwd()));
15 changes: 0 additions & 15 deletions src/cli/manifest.ts

This file was deleted.

11 changes: 6 additions & 5 deletions src/cli/start.ts → src/cli/start.js 100644 → 100755
@@ -1,11 +1,12 @@
import { spawn } from 'child_process';
import path from 'path';
#!/usr/bin/env node
const { spawn } = require('child_process');
const path = require('path');

// Run script hook verifies that requirements for running an App in
// in developerMode (via Socket Mode) are met
(function _(cwd: string) {
(function _(cwd) {
// TODO - Format so that its less miss-able in output
process.stdout.write('Preparing local run in developer mode (Socket Mode)\n');
console.log('Preparing local run in developer mode (Socket Mode)');
// Check required local run tokens
validate();

Expand All @@ -21,7 +22,7 @@ import path from 'path';
});

app.on('close', (code) => {
process.stdout.write(`bolt-app local run exited with code ${code}`);
console.log(`bolt-app local run exited with code ${code}`);
});
}(process.cwd()));

Expand Down