json-server 1.0.0-alpha.13 → 1.0.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/bin.js +11 -0
- package/lib/views/index.html +40 -0
- package/package.json +6 -5
package/README.md
CHANGED
package/lib/bin.js
CHANGED
|
@@ -32,9 +32,15 @@ const { values, positionals } = parseArgs({
|
|
|
32
32
|
version: {
|
|
33
33
|
type: 'boolean',
|
|
34
34
|
},
|
|
35
|
+
// Deprecated
|
|
36
|
+
watch: {
|
|
37
|
+
type: 'boolean',
|
|
38
|
+
short: 'w',
|
|
39
|
+
},
|
|
35
40
|
},
|
|
36
41
|
allowPositionals: true,
|
|
37
42
|
});
|
|
43
|
+
// --help
|
|
38
44
|
if (values.help || positionals.length === 0) {
|
|
39
45
|
console.log(`Usage: json-server [options] <file>
|
|
40
46
|
Options:
|
|
@@ -45,11 +51,16 @@ Options:
|
|
|
45
51
|
`);
|
|
46
52
|
process.exit();
|
|
47
53
|
}
|
|
54
|
+
// --version
|
|
48
55
|
if (values.version) {
|
|
49
56
|
const pkg = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf8'));
|
|
50
57
|
console.log(pkg.version);
|
|
51
58
|
process.exit();
|
|
52
59
|
}
|
|
60
|
+
// Handle --watch
|
|
61
|
+
if (values.watch) {
|
|
62
|
+
console.log(chalk.yellow('--watch/-w can be omitted, JSON Server 1+ watches for file changes by default'));
|
|
63
|
+
}
|
|
53
64
|
// App args and options
|
|
54
65
|
const file = positionals[0] ?? '';
|
|
55
66
|
const port = parseInt(values.port ?? process.env['PORT'] ?? '3000');
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<link href="/output.css" rel="stylesheet" />
|
|
8
|
+
</head>
|
|
9
|
+
|
|
10
|
+
<body class="container mx-auto prose dark:prose-invert dark:bg-slate-900 pt-6 bg-white text-slate-900">
|
|
11
|
+
<header>
|
|
12
|
+
<nav class="mx-auto flex items-center justify-between">
|
|
13
|
+
<strong>JSON Server (* ^ω^)</strong>
|
|
14
|
+
<div class="flex gap-x-6">
|
|
15
|
+
<a href="https://github.com/typicode/json-server">
|
|
16
|
+
<span class="ml-2">GitHub</span>
|
|
17
|
+
</a>
|
|
18
|
+
<a href="https://github.com/sponsors/typicode">
|
|
19
|
+
<span class="ml-2">♡ Sponsor</span>
|
|
20
|
+
</a>
|
|
21
|
+
</div>
|
|
22
|
+
</nav>
|
|
23
|
+
</header>
|
|
24
|
+
<main class="my-12">
|
|
25
|
+
<% if (Object.keys(it.data).length === 0) { %>
|
|
26
|
+
<p>No resources found in JSON file</p>
|
|
27
|
+
<% } %>
|
|
28
|
+
<% Object.entries(it.data).forEach(function([name]) { %>
|
|
29
|
+
<div class="py-1">
|
|
30
|
+
<a href="<%= name %>">/<%= name %></a>
|
|
31
|
+
<span class="text-gray-500">
|
|
32
|
+
<% if (Array.isArray(it.data[name])) { %>
|
|
33
|
+
- <%= it.data[name].length %> items</span>
|
|
34
|
+
<% } %>
|
|
35
|
+
</div>
|
|
36
|
+
<% }) %>
|
|
37
|
+
</main>
|
|
38
|
+
</body>
|
|
39
|
+
|
|
40
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-server",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.15",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"bin":
|
|
6
|
+
"bin": {
|
|
7
|
+
"json-server": "lib/bin.js"
|
|
8
|
+
},
|
|
7
9
|
"types": "lib",
|
|
8
10
|
"files": [
|
|
9
11
|
"lib",
|
|
@@ -14,7 +16,7 @@
|
|
|
14
16
|
"watch-ts": "tsx watch src/bin.ts fixtures/db.json",
|
|
15
17
|
"watch-css": "npm run css -- --watch",
|
|
16
18
|
"dev": "concurrently npm:watch-*",
|
|
17
|
-
"build": "rm -rf lib && tsc && npm run css",
|
|
19
|
+
"build": "rm -rf lib && tsc && npm run css && mkdir lib/views && cp views/index.html lib/views/index.html",
|
|
18
20
|
"test": "npm run css && node --import tsx/esm --test src/*.test.ts",
|
|
19
21
|
"lint": "eslint src --ext .ts --ignore-path .gitignore",
|
|
20
22
|
"prepare": "husky install",
|
|
@@ -49,7 +51,6 @@
|
|
|
49
51
|
"lowdb": "^7.0.1",
|
|
50
52
|
"milliparsec": "^2.3.0",
|
|
51
53
|
"sirv": "^2.0.4",
|
|
52
|
-
"sort-on": "^6.0.0"
|
|
53
|
-
"zod": "^3.22.4"
|
|
54
|
+
"sort-on": "^6.0.0"
|
|
54
55
|
}
|
|
55
56
|
}
|