Skip to content

Commit 3dc0591

Browse files
Exclude unnecessary files from npm package (superbrothers#8)
1 parent ccfbb3a commit 3dc0591

File tree

6 files changed

+22
-10
lines changed

6 files changed

+22
-10
lines changed

Diff for: .github/workflows/ci.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ jobs:
3030
- run: npm install
3131
- run: npm test
3232
- run: npm run build
33+
- run: npm install -g "$(npm pack)"

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/lib
22
/node_modules
33
/ga.zip
4+
*.tgz

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ verify:
3030

3131
.PHONY: clean
3232
clean:
33-
$(RM) ga.zip ga.zip.sha256
33+
$(RM) ga.zip ga.zip.sha256 *.tgz
3434

3535
.PHONY: run-in-node
3636
run-in-node:

Diff for: bin/cli.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env node
2+
3+
const ga = require("../lib/index.js");
4+
ga.parse(process.argv);
5+
if (ga.args.length === 0) ga.help();

Diff for: package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
"version": "0.1.0",
44
"description": "The GitHub Actions helper command-line tool.",
55
"main": "lib/index.js",
6+
"bin": "bin/cli.js",
67
"scripts": {
78
"test": "jest",
89
"lint": "eslint **/*.ts",
910
"lint:fix": "eslint --fix **/*.ts",
1011
"build": "tsc",
11-
"start": "ts-node ./src/index.ts",
12+
"start": "npm run build && node bin/cli.js",
1213
"ts-node": "ts-node"
1314
},
1415
"repository": {
@@ -39,6 +40,10 @@
3940
"ts-node": "^8.6.2",
4041
"typescript": "^3.7.5"
4142
},
43+
"files": [
44+
"/lib",
45+
"LICENSE"
46+
],
4247
"jest": {
4348
"preset": "ts-jest"
4449
}

Diff for: src/index.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as fs from "fs";
55
import * as path from "path";
66

77
const { description, version } = JSON.parse(
8-
fs.readFileSync(path.join(__dirname, "../package.json"), "utf8")
8+
fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf8")
99
);
1010

1111
const ga = new commander.Command("ga");
@@ -111,12 +111,12 @@ ga.command("get-state <name>")
111111
/**
112112
* Other commands will be redirected to the help message.
113113
*/
114-
ga.command("*").action(() => ga.help());
115-
116-
if (require.main === module) {
117-
ga.parse(process.argv);
118-
119-
if (ga.args.length === 0) ga.help();
120-
}
114+
ga.command("*").action(() => {
115+
console.error(
116+
"Invalid command: %s\nSee --help for a list of available commands.",
117+
ga.args.join(" ")
118+
);
119+
process.exit(1);
120+
});
121121

122122
export = ga;

0 commit comments

Comments
 (0)