Skip to content

Commit 854ce4c

Browse files
committed
I stole some package-json typings from a gist
1 parent fb4ed68 commit 854ce4c

File tree

8 files changed

+415
-29
lines changed

8 files changed

+415
-29
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
build

.vscode/launch.json

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"version": "0.2.0",
33
"configurations": [
4+
{
5+
"type": "node",
6+
"request": "launch",
7+
"name": "Launch Explore",
8+
"program": "${workspaceFolder}/build/cli/explore.js"
9+
},
410
{
511
"type": "node",
612
"request": "launch",

package-lock.json

+232-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
},
2222
"homepage": "https://github.com/jessitron/about-typescript#readme",
2323
"dependencies": {
24-
"jetty": "^0.2.1"
24+
"inquirer": "^6.0.0"
2525
},
2626
"devDependencies": {
2727
"@types/node": "^10.5.2",
2828
"ts-node": "^7.0.0",
2929
"typescript": "^2.9.2"
3030
}
31-
}
31+
}

src/cli/explore.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ import { youAreIn } from "./support/youAreIn";
44

55
youAreIn(process.cwd());
66

7-
console.log("everything is fucked here")
7+
console.log("i tried")

src/cli/support/youAreIn.ts

+36-17
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,47 @@
11

2-
import Poo from "jetty";
2+
import * as fs from "fs";
3+
import * as path from "path";
4+
5+
import { PackageJSON } from "package-json";
36

47
export function youAreIn(appDir: string) {
58

6-
var jetty = new Poo(process.stdout)
79

8-
jetty.text("Hello from " + appDir);
910

10-
console.log("fuck you")
11+
console.log("Hello from " + appDir);
12+
13+
14+
15+
}
16+
17+
function determineCircumstances(appDir: string): Circumstances {
18+
const pjString: string = readPackageJson(appDir)
19+
if (!pjString) {
20+
return "not a package";
21+
}
22+
const pj = parsePackageJson(pjString);
23+
if (!pj) {
24+
return "invalid package json";
25+
}
26+
}
1127

12-
// Clear the screen
13-
jetty.clear();
28+
type NotAPackage = "not a package";
29+
type InvalidPackageDefinition = "invalid package json";
1430

15-
// Draw a circle with fly colours
16-
var i = 0;
17-
setInterval(function () {
18-
i += 0.025;
31+
type Circumstances = NotAPackage | InvalidPackageDefinition
1932

20-
var x = Math.round(Math.cos(i) * 25 + 50),
21-
y = Math.round(Math.sin(i) * 13 + 20);
33+
function readPackageJson(appDir: string): string | undefined {
34+
try {
35+
return fs.readFileSync(path.join(appDir, "package.json"), { encoding: "utf8" })
36+
} catch {
37+
return;
38+
}
39+
}
2240

23-
jetty.rgb(
24-
Math.round(Math.random() * 215),
25-
Math.random() > 0.5
26-
).moveTo([y, x]).text(".");
27-
}, 5);
41+
function parsePackageJson(pjContent: string): PackageJSON | undefined {
42+
try {
43+
return JSON.parse(pjContent);
44+
} catch {
45+
return;
46+
}
2847
}

0 commit comments

Comments
 (0)