@vercel/dream-init 0.2.1
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/dist/init.d.ts +11 -0
- package/dist/init.js +47 -0
- package/package.json +27 -0
- package/template/package.json +11 -0
- package/template/specs/sample.md +10 -0
package/dist/init.d.ts
ADDED
package/dist/init.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// lib/init.ts
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
function init(options) {
|
|
5
|
+
const dir = path.resolve(options.dir);
|
|
6
|
+
const version = options.version ?? "^0.2.1";
|
|
7
|
+
const templateDir = path.resolve(
|
|
8
|
+
new URL(".", import.meta.url).pathname,
|
|
9
|
+
"../template"
|
|
10
|
+
);
|
|
11
|
+
if (!fs.existsSync(dir)) {
|
|
12
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
13
|
+
}
|
|
14
|
+
const specsDir = path.join(dir, "specs");
|
|
15
|
+
let specsCreated = false;
|
|
16
|
+
if (!fs.existsSync(specsDir)) {
|
|
17
|
+
copyDirSync(path.join(templateDir, "specs"), specsDir);
|
|
18
|
+
specsCreated = true;
|
|
19
|
+
}
|
|
20
|
+
const packageJsonPath = path.join(dir, "package.json");
|
|
21
|
+
let packageJsonCreated = false;
|
|
22
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
23
|
+
const template = fs.readFileSync(
|
|
24
|
+
path.join(templateDir, "package.json"),
|
|
25
|
+
"utf-8"
|
|
26
|
+
);
|
|
27
|
+
const content = template.replace("{{name}}", path.basename(dir)).replace("{{version}}", version);
|
|
28
|
+
fs.writeFileSync(packageJsonPath, content);
|
|
29
|
+
packageJsonCreated = true;
|
|
30
|
+
}
|
|
31
|
+
return { dir, specsCreated, packageJsonCreated };
|
|
32
|
+
}
|
|
33
|
+
function copyDirSync(src, dest) {
|
|
34
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
35
|
+
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
36
|
+
const srcPath = path.join(src, entry.name);
|
|
37
|
+
const destPath = path.join(dest, entry.name);
|
|
38
|
+
if (entry.isDirectory()) {
|
|
39
|
+
copyDirSync(srcPath, destPath);
|
|
40
|
+
} else {
|
|
41
|
+
fs.copyFileSync(srcPath, destPath);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
init
|
|
47
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vercel/dream-init",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Scaffolding logic for dream projects",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/init.js",
|
|
9
|
+
"types": "./dist/init.d.ts"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"template"
|
|
15
|
+
],
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/node": "^22.0.0",
|
|
18
|
+
"tsup": "^8.5.1",
|
|
19
|
+
"typescript": "^5.4.0"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsup",
|
|
24
|
+
"check": "biome check .",
|
|
25
|
+
"check:fix": "biome check --write ."
|
|
26
|
+
}
|
|
27
|
+
}
|