@valbuild/init 0.51.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/CHANGELOG.md +0 -0
- package/babel.config.js +6 -0
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/valbuild-init.cjs.d.ts +2 -0
- package/dist/valbuild-init.cjs.d.ts.map +1 -0
- package/dist/valbuild-init.cjs.dev.js +1373 -0
- package/dist/valbuild-init.cjs.js +7 -0
- package/dist/valbuild-init.cjs.prod.js +1373 -0
- package/dist/valbuild-init.esm.js +1361 -0
- package/out/index.js +9 -0
- package/package.json +55 -0
- package/src/codemods/index.ts +1 -0
- package/src/codemods/transformNextAppRouterValProvider.ts +76 -0
- package/src/codemods.test.ts +75 -0
- package/src/index.ts +49 -0
- package/src/init.ts +611 -0
- package/src/logger.ts +32 -0
- package/src/templates.ts +75 -0
- package/tsconfig.json +11 -0
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@valbuild/init",
|
|
3
|
+
"version": "0.51.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/valbuild-init.cjs.js",
|
|
6
|
+
"module": "dist/valbuild-init.esm.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"module": "./dist/valbuild-init.esm.js",
|
|
10
|
+
"default": "./dist/valbuild-init.cjs.js"
|
|
11
|
+
},
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"test": "jest",
|
|
16
|
+
"build": "ncc build ./src/index.ts -o ./out/ --minify --no-cache --no-source-map-register"
|
|
17
|
+
},
|
|
18
|
+
"bin": {
|
|
19
|
+
"@valbuild/init": "./out/index.js"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@inquirer/confirm": "^2.0.15",
|
|
23
|
+
"@inquirer/prompts": "^3.0.2",
|
|
24
|
+
"@types/diff": "^5.0.9",
|
|
25
|
+
"chalk": "^4.1.2",
|
|
26
|
+
"cors": "^2.8.5",
|
|
27
|
+
"diff": "^5.1.0",
|
|
28
|
+
"eslint": "^8.31.0",
|
|
29
|
+
"express": "^4.18.2",
|
|
30
|
+
"fast-glob": "^3.3.1",
|
|
31
|
+
"jscodeshift": "^0.15.1",
|
|
32
|
+
"meow": "^9.0.0",
|
|
33
|
+
"open": "^9.1.0",
|
|
34
|
+
"picocolors": "^1.0.0",
|
|
35
|
+
"recast": "^0.23.4",
|
|
36
|
+
"semver": "^7.5.4",
|
|
37
|
+
"simple-git": "^3.22.0",
|
|
38
|
+
"typescript": "^5.3.3",
|
|
39
|
+
"zod": "^3.22.4"
|
|
40
|
+
},
|
|
41
|
+
"preconstruct": {
|
|
42
|
+
"entrypoints": [
|
|
43
|
+
"./index.ts"
|
|
44
|
+
],
|
|
45
|
+
"exports": true
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@babel/preset-env": "^7.23.8",
|
|
49
|
+
"@babel/preset-typescript": "^7.23.3",
|
|
50
|
+
"@types/jest": "^29.5.11",
|
|
51
|
+
"@types/jscodeshift": "^0.11.11",
|
|
52
|
+
"@vercel/ncc": "^0.38.1",
|
|
53
|
+
"jest": "^29.7.0"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./transformNextAppRouterValProvider";
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import j from "jscodeshift";
|
|
2
|
+
|
|
3
|
+
export function transformNextAppRouterValProvider(
|
|
4
|
+
fileInfo: j.FileInfo,
|
|
5
|
+
api: j.API,
|
|
6
|
+
options: j.Options
|
|
7
|
+
) {
|
|
8
|
+
if (!options.configImportPath) {
|
|
9
|
+
throw new Error("configImportPath is required");
|
|
10
|
+
}
|
|
11
|
+
const root = api.jscodeshift(fileInfo.source);
|
|
12
|
+
root
|
|
13
|
+
.find(j.ImportDeclaration)
|
|
14
|
+
.at(0)
|
|
15
|
+
.insertBefore(
|
|
16
|
+
j.importDeclaration(
|
|
17
|
+
[j.importSpecifier(j.identifier("ValProvider"))],
|
|
18
|
+
j.literal("@valbuild/next")
|
|
19
|
+
)
|
|
20
|
+
)
|
|
21
|
+
.insertBefore(
|
|
22
|
+
j.importDeclaration(
|
|
23
|
+
[j.importSpecifier(j.identifier("config"))],
|
|
24
|
+
j.literal(options.configImportPath)
|
|
25
|
+
)
|
|
26
|
+
);
|
|
27
|
+
root
|
|
28
|
+
.findJSXElements("body")
|
|
29
|
+
.childNodes()
|
|
30
|
+
.forEach((el) => {
|
|
31
|
+
if (el.value.type === "JSXExpressionContainer") {
|
|
32
|
+
if (
|
|
33
|
+
el.value.expression.type === "Identifier" &&
|
|
34
|
+
el.value.expression.name === "children"
|
|
35
|
+
) {
|
|
36
|
+
el.replace(
|
|
37
|
+
j.jsxElement(
|
|
38
|
+
{
|
|
39
|
+
name: {
|
|
40
|
+
type: "JSXIdentifier",
|
|
41
|
+
name: "ValProvider",
|
|
42
|
+
},
|
|
43
|
+
type: "JSXOpeningElement",
|
|
44
|
+
selfClosing: false,
|
|
45
|
+
attributes: [
|
|
46
|
+
{
|
|
47
|
+
type: "JSXAttribute",
|
|
48
|
+
name: {
|
|
49
|
+
type: "JSXIdentifier",
|
|
50
|
+
name: "config",
|
|
51
|
+
},
|
|
52
|
+
value: {
|
|
53
|
+
type: "JSXExpressionContainer",
|
|
54
|
+
expression: {
|
|
55
|
+
type: "Identifier",
|
|
56
|
+
name: "config",
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: {
|
|
64
|
+
type: "JSXIdentifier",
|
|
65
|
+
name: "ValProvider",
|
|
66
|
+
},
|
|
67
|
+
type: "JSXClosingElement",
|
|
68
|
+
},
|
|
69
|
+
[j.jsxExpressionContainer(j.identifier("children"))]
|
|
70
|
+
)
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return root.toSource();
|
|
76
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import jcs from "jscodeshift";
|
|
2
|
+
import { transformNextAppRouterValProvider } from "./codemods/transformNextAppRouterValProvider";
|
|
3
|
+
|
|
4
|
+
const APP_ROUTER_LAYOUT_SANS_VAL_PROVIDER = `import type { Metadata } from "next";
|
|
5
|
+
import { Inter } from "next/font/google";
|
|
6
|
+
import "./globals.css";
|
|
7
|
+
|
|
8
|
+
const inter = Inter({ subsets: ["latin"] });
|
|
9
|
+
|
|
10
|
+
export const metadata: Metadata = {
|
|
11
|
+
title: "Create Next App",
|
|
12
|
+
description: "Generated by create next app",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default function RootLayout({
|
|
16
|
+
children,
|
|
17
|
+
}: {
|
|
18
|
+
children: React.ReactNode;
|
|
19
|
+
}) {
|
|
20
|
+
return (
|
|
21
|
+
<html lang="en">
|
|
22
|
+
<body className={inter.className}>
|
|
23
|
+
{children}
|
|
24
|
+
</body>
|
|
25
|
+
</html>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
describe("codemods", () => {
|
|
31
|
+
test("init ValProvider layout", async () => {
|
|
32
|
+
const res = transformNextAppRouterValProvider(
|
|
33
|
+
{
|
|
34
|
+
path: "./app/layout.tsx",
|
|
35
|
+
source: APP_ROUTER_LAYOUT_SANS_VAL_PROVIDER,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
j: jcs,
|
|
39
|
+
jscodeshift: jcs.withParser("tsx"),
|
|
40
|
+
stats: () => {},
|
|
41
|
+
report: () => {},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
configImportPath: "../val.config",
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
expect(res).toEqual(`import { ValProvider } from "@valbuild/next";
|
|
48
|
+
import { config } from "../val.config";
|
|
49
|
+
import type { Metadata } from "next";
|
|
50
|
+
import { Inter } from "next/font/google";
|
|
51
|
+
import "./globals.css";
|
|
52
|
+
|
|
53
|
+
const inter = Inter({ subsets: ["latin"] });
|
|
54
|
+
|
|
55
|
+
export const metadata: Metadata = {
|
|
56
|
+
title: "Create Next App",
|
|
57
|
+
description: "Generated by create next app",
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export default function RootLayout({
|
|
61
|
+
children,
|
|
62
|
+
}: {
|
|
63
|
+
children: React.ReactNode;
|
|
64
|
+
}) {
|
|
65
|
+
return (
|
|
66
|
+
(<html lang="en">
|
|
67
|
+
<body className={inter.className}>
|
|
68
|
+
<ValProvider config={config}>{children}</ValProvider>
|
|
69
|
+
</body>
|
|
70
|
+
</html>)
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
`);
|
|
74
|
+
});
|
|
75
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import meow from "meow";
|
|
2
|
+
import { init } from "./init";
|
|
3
|
+
import { error } from "./logger";
|
|
4
|
+
|
|
5
|
+
async function main() {
|
|
6
|
+
const { flags } = meow(
|
|
7
|
+
`
|
|
8
|
+
Usage
|
|
9
|
+
$ npx @valbuild/init
|
|
10
|
+
Commands
|
|
11
|
+
Initialize Val in a project
|
|
12
|
+
|
|
13
|
+
Options
|
|
14
|
+
--help Show this message
|
|
15
|
+
--root [root], -r [root] Set project root directory (default process.cwd())
|
|
16
|
+
--yes [yes], -y [yes] Accept all prompts with defaults.
|
|
17
|
+
`,
|
|
18
|
+
{
|
|
19
|
+
flags: {
|
|
20
|
+
root: {
|
|
21
|
+
type: "string",
|
|
22
|
+
alias: "r",
|
|
23
|
+
},
|
|
24
|
+
yes: {
|
|
25
|
+
type: "boolean",
|
|
26
|
+
alias: "y",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
hardRejection: false,
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
await init(flags.root, { yes: flags.yes });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
void main().catch((err) => {
|
|
37
|
+
if (err.message.includes("force closed the prompt")) {
|
|
38
|
+
process.exitCode = 2;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
error(
|
|
42
|
+
err instanceof Error
|
|
43
|
+
? err.message + "\n" + err.stack
|
|
44
|
+
: typeof err === "object"
|
|
45
|
+
? JSON.stringify(err, null, 2)
|
|
46
|
+
: err
|
|
47
|
+
);
|
|
48
|
+
process.exitCode = 1;
|
|
49
|
+
});
|