setup-express-api 1.0.1 → 1.2.0
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 +11 -0
- package/bin/cli.js +1 -0
- package/package.json +37 -36
- package/src/scaffold.js +5 -8
- package/src/utils/project-config.js +33 -0
package/README.md
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
# setup-express-api
|
|
2
2
|
|
|
3
3
|
Scaffold an Express API into the current empty directory.
|
|
4
|
+
Generated project `package.json` defaults to version `0.1.0` (minimum supported scaffolded version).
|
|
5
|
+
|
|
6
|
+
## Test scaffold script
|
|
7
|
+
|
|
8
|
+
Generate a local test scaffold under `.express-api/`:
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm run scaffold
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
This script recreates `.express-api/` on each run (deletes it first if it already exists).
|
|
4
15
|
|
|
5
16
|
## Usage
|
|
6
17
|
|
package/bin/cli.js
CHANGED
|
@@ -28,6 +28,7 @@ try {
|
|
|
28
28
|
const projectConfig = skipPrompts
|
|
29
29
|
? {
|
|
30
30
|
name: path.basename(targetDir).toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "") || "express-api-server",
|
|
31
|
+
version: "0.1.0",
|
|
31
32
|
description: "",
|
|
32
33
|
author: "",
|
|
33
34
|
license: "MIT"
|
package/package.json
CHANGED
|
@@ -1,37 +1,38 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "setup-express-api",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "Create an Express API with
|
|
5
|
-
"type": "module",
|
|
6
|
-
"bin": {
|
|
7
|
-
"setup-express-api": "./bin/cli.js"
|
|
8
|
-
},
|
|
9
|
-
"files": [
|
|
10
|
-
"bin",
|
|
11
|
-
"src"
|
|
12
|
-
],
|
|
13
|
-
"scripts": {
|
|
14
|
-
"test": "node --test test/*.test.js"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"express",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "setup-express-api",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Create an Express API with basic features set up.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"setup-express-api": "./bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"src"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "node --test test/*.test.js",
|
|
15
|
+
"scaffold": "node scripts/scaffold-test.js"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@thantpyaeshine/express-api": "1.2.0"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"setup-express-api",
|
|
22
|
+
"create-express-api",
|
|
23
|
+
"express",
|
|
24
|
+
"cli",
|
|
25
|
+
"api",
|
|
26
|
+
"typescript",
|
|
27
|
+
"better-auth"
|
|
28
|
+
],
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=22"
|
|
32
|
+
},
|
|
33
|
+
"allowScripts": {
|
|
34
|
+
"esbuild": true,
|
|
35
|
+
"@parcel/watcher": true,
|
|
36
|
+
"unrs-resolver": true
|
|
37
|
+
}
|
|
37
38
|
}
|
package/src/scaffold.js
CHANGED
|
@@ -102,14 +102,11 @@ export async function scaffold(targetDir, options = {}) {
|
|
|
102
102
|
|
|
103
103
|
try {
|
|
104
104
|
fs.cpSync(templateDirectory, targetDir, { recursive: true });
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
`${JSON.stringify({ ...generatedPackage, ...options.projectConfig }, null, 2)}\n`
|
|
111
|
-
);
|
|
112
|
-
}
|
|
105
|
+
const generatedPackagePath = path.join(targetDir, "package.json");
|
|
106
|
+
const generatedPackage = readPackageJson(generatedPackagePath, "generated project");
|
|
107
|
+
const mergedPackage = options.projectConfig ? { ...generatedPackage, ...options.projectConfig } : generatedPackage;
|
|
108
|
+
delete mergedPackage.publishConfig;
|
|
109
|
+
fs.writeFileSync(generatedPackagePath, `${JSON.stringify(mergedPackage, null, 2)}\n`);
|
|
113
110
|
} catch {
|
|
114
111
|
throw new Error(`Unable to copy template files into: ${targetDir}`);
|
|
115
112
|
}
|
|
@@ -2,6 +2,8 @@ import path from "node:path";
|
|
|
2
2
|
import { stdin as input, stdout as output } from "node:process";
|
|
3
3
|
import readline from "node:readline/promises";
|
|
4
4
|
|
|
5
|
+
const MINIMUM_PACKAGE_VERSION = "0.1.0";
|
|
6
|
+
|
|
5
7
|
function toPackageName(value) {
|
|
6
8
|
return value
|
|
7
9
|
.toLowerCase()
|
|
@@ -10,6 +12,27 @@ function toPackageName(value) {
|
|
|
10
12
|
.replace(/^-|-$/g, "");
|
|
11
13
|
}
|
|
12
14
|
|
|
15
|
+
function compareVersions(left, right) {
|
|
16
|
+
const parseParts = (value) =>
|
|
17
|
+
String(value ?? "0")
|
|
18
|
+
.split("-")[0]
|
|
19
|
+
.split(".")
|
|
20
|
+
.map((part) => Number.parseInt(part, 10) || 0);
|
|
21
|
+
|
|
22
|
+
const leftParts = parseParts(left);
|
|
23
|
+
const rightParts = parseParts(right);
|
|
24
|
+
const maxLength = Math.max(leftParts.length, rightParts.length);
|
|
25
|
+
|
|
26
|
+
for (let index = 0; index < maxLength; index += 1) {
|
|
27
|
+
const difference = (leftParts[index] ?? 0) - (rightParts[index] ?? 0);
|
|
28
|
+
if (difference !== 0) {
|
|
29
|
+
return difference;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
13
36
|
async function ask(prompt, question, defaultValue = "") {
|
|
14
37
|
const suffix = defaultValue ? ` (${defaultValue})` : "";
|
|
15
38
|
const answer = await prompt.question(`${question}${suffix}: `);
|
|
@@ -25,6 +48,15 @@ async function askPackageName(prompt, defaultValue) {
|
|
|
25
48
|
return packageName;
|
|
26
49
|
}
|
|
27
50
|
|
|
51
|
+
async function askPackageVersion(prompt) {
|
|
52
|
+
let version = await ask(prompt, "Version", MINIMUM_PACKAGE_VERSION);
|
|
53
|
+
while (compareVersions(version, MINIMUM_PACKAGE_VERSION) < 0) {
|
|
54
|
+
console.log(`Version must be ${MINIMUM_PACKAGE_VERSION} or higher.`);
|
|
55
|
+
version = await ask(prompt, "Version", MINIMUM_PACKAGE_VERSION);
|
|
56
|
+
}
|
|
57
|
+
return version;
|
|
58
|
+
}
|
|
59
|
+
|
|
28
60
|
export async function promptForProjectConfig(targetDir) {
|
|
29
61
|
const prompt = readline.createInterface({ input, output });
|
|
30
62
|
const defaultName = toPackageName(path.basename(targetDir)) || "express-api-server";
|
|
@@ -33,6 +65,7 @@ export async function promptForProjectConfig(targetDir) {
|
|
|
33
65
|
console.log("\nCreate an Express API\n");
|
|
34
66
|
return {
|
|
35
67
|
name: await askPackageName(prompt, defaultName),
|
|
68
|
+
version: await askPackageVersion(prompt),
|
|
36
69
|
description: await ask(prompt, "Description"),
|
|
37
70
|
author: await ask(prompt, "Author"),
|
|
38
71
|
license: await ask(prompt, "License", "MIT")
|