@valbuild/init 0.63.4 → 0.64.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/main/dist/valbuild-init-main.cjs.dev.js +4 -4
- package/main/dist/valbuild-init-main.cjs.prod.js +4 -4
- package/main/dist/valbuild-init-main.esm.js +4 -4
- package/package.json +1 -1
- package/src/codemods/transformNextAppRouterValProvider.ts +7 -7
- package/src/codemods.test.ts +1 -1
- package/src/init.ts +46 -46
- package/src/logger.ts +1 -1
- package/src/main.ts +3 -3
- package/src/templates.ts +12 -8
|
@@ -516,7 +516,7 @@ function transformNextAppRouterValProvider(fileInfo, api, options) {
|
|
|
516
516
|
|
|
517
517
|
var packageJson = {
|
|
518
518
|
name: "@valbuild/init",
|
|
519
|
-
version: "0.
|
|
519
|
+
version: "0.64.0",
|
|
520
520
|
description: "Initialize a new val.build project",
|
|
521
521
|
exports: {
|
|
522
522
|
"./main": {
|
|
@@ -569,8 +569,8 @@ var packageJson = {
|
|
|
569
569
|
var VAL_CLIENT = function VAL_CLIENT(configImportPath) {
|
|
570
570
|
return "import \"client-only\";\nimport { initValClient } from \"@valbuild/next/client\";\nimport { config } from \"".concat(configImportPath, "\";\n\nconst { useValStega: useVal } = initValClient(config);\n\nexport { useVal };\n");
|
|
571
571
|
};
|
|
572
|
-
var VAL_RSC = function VAL_RSC(configImportPath) {
|
|
573
|
-
return "import \"server-only\";\nimport { initValRsc } from \"@valbuild/next/rsc\";\nimport { config } from \"".concat(configImportPath, "\";\nimport { cookies, draftMode, headers } from \"next/headers\";\n\nconst { fetchValStega: fetchVal } = initValRsc(config, {\n draftMode,\n headers,\n cookies,\n});\n\nexport { fetchVal };\n");
|
|
572
|
+
var VAL_RSC = function VAL_RSC(configImportPath, valModulesImportPath) {
|
|
573
|
+
return "import \"server-only\";\nimport { initValRsc } from \"@valbuild/next/rsc\";\nimport { config } from \"".concat(configImportPath, "\";\nimport valModules from \"").concat(valModulesImportPath, "\";\nimport { cookies, draftMode, headers } from \"next/headers\";\n\nconst { fetchValStega: fetchVal } = initValRsc(config, valModules, {\n draftMode,\n headers,\n cookies,\n});\n\nexport { fetchVal };\n");
|
|
574
574
|
};
|
|
575
575
|
var VAL_SERVER = function VAL_SERVER(configImportPath, valModulesImportPath) {
|
|
576
576
|
return "import \"server-only\";\nimport { initValServer } from \"@valbuild/next/server\";\nimport { config } from \"".concat(configImportPath, "\";\nimport { draftMode } from \"next/headers\";\nimport valModules from \"").concat(valModulesImportPath, "\";\n\nconst { valNextAppRouter } = initValServer(\n valModules,\n { ...config },\n {\n draftMode,\n }\n);\n\nexport { valNextAppRouter };\n");
|
|
@@ -1337,7 +1337,7 @@ function _plan() {
|
|
|
1337
1337
|
if (_answer6) {
|
|
1338
1338
|
plan.createValRsc = {
|
|
1339
1339
|
path: path__default["default"].join(valUtilsDir, analysis.isTypeScript ? "val.rsc.ts" : "val.rsc.js"),
|
|
1340
|
-
source: VAL_RSC(valUtilsImportPath)
|
|
1340
|
+
source: VAL_RSC(valUtilsImportPath, valModulesServerImport)
|
|
1341
1341
|
};
|
|
1342
1342
|
} else {
|
|
1343
1343
|
plan.createValRsc = false;
|
|
@@ -516,7 +516,7 @@ function transformNextAppRouterValProvider(fileInfo, api, options) {
|
|
|
516
516
|
|
|
517
517
|
var packageJson = {
|
|
518
518
|
name: "@valbuild/init",
|
|
519
|
-
version: "0.
|
|
519
|
+
version: "0.64.0",
|
|
520
520
|
description: "Initialize a new val.build project",
|
|
521
521
|
exports: {
|
|
522
522
|
"./main": {
|
|
@@ -569,8 +569,8 @@ var packageJson = {
|
|
|
569
569
|
var VAL_CLIENT = function VAL_CLIENT(configImportPath) {
|
|
570
570
|
return "import \"client-only\";\nimport { initValClient } from \"@valbuild/next/client\";\nimport { config } from \"".concat(configImportPath, "\";\n\nconst { useValStega: useVal } = initValClient(config);\n\nexport { useVal };\n");
|
|
571
571
|
};
|
|
572
|
-
var VAL_RSC = function VAL_RSC(configImportPath) {
|
|
573
|
-
return "import \"server-only\";\nimport { initValRsc } from \"@valbuild/next/rsc\";\nimport { config } from \"".concat(configImportPath, "\";\nimport { cookies, draftMode, headers } from \"next/headers\";\n\nconst { fetchValStega: fetchVal } = initValRsc(config, {\n draftMode,\n headers,\n cookies,\n});\n\nexport { fetchVal };\n");
|
|
572
|
+
var VAL_RSC = function VAL_RSC(configImportPath, valModulesImportPath) {
|
|
573
|
+
return "import \"server-only\";\nimport { initValRsc } from \"@valbuild/next/rsc\";\nimport { config } from \"".concat(configImportPath, "\";\nimport valModules from \"").concat(valModulesImportPath, "\";\nimport { cookies, draftMode, headers } from \"next/headers\";\n\nconst { fetchValStega: fetchVal } = initValRsc(config, valModules, {\n draftMode,\n headers,\n cookies,\n});\n\nexport { fetchVal };\n");
|
|
574
574
|
};
|
|
575
575
|
var VAL_SERVER = function VAL_SERVER(configImportPath, valModulesImportPath) {
|
|
576
576
|
return "import \"server-only\";\nimport { initValServer } from \"@valbuild/next/server\";\nimport { config } from \"".concat(configImportPath, "\";\nimport { draftMode } from \"next/headers\";\nimport valModules from \"").concat(valModulesImportPath, "\";\n\nconst { valNextAppRouter } = initValServer(\n valModules,\n { ...config },\n {\n draftMode,\n }\n);\n\nexport { valNextAppRouter };\n");
|
|
@@ -1337,7 +1337,7 @@ function _plan() {
|
|
|
1337
1337
|
if (_answer6) {
|
|
1338
1338
|
plan.createValRsc = {
|
|
1339
1339
|
path: path__default["default"].join(valUtilsDir, analysis.isTypeScript ? "val.rsc.ts" : "val.rsc.js"),
|
|
1340
|
-
source: VAL_RSC(valUtilsImportPath)
|
|
1340
|
+
source: VAL_RSC(valUtilsImportPath, valModulesServerImport)
|
|
1341
1341
|
};
|
|
1342
1342
|
} else {
|
|
1343
1343
|
plan.createValRsc = false;
|
|
@@ -504,7 +504,7 @@ function transformNextAppRouterValProvider(fileInfo, api, options) {
|
|
|
504
504
|
|
|
505
505
|
var packageJson = {
|
|
506
506
|
name: "@valbuild/init",
|
|
507
|
-
version: "0.
|
|
507
|
+
version: "0.64.0",
|
|
508
508
|
description: "Initialize a new val.build project",
|
|
509
509
|
exports: {
|
|
510
510
|
"./main": {
|
|
@@ -557,8 +557,8 @@ var packageJson = {
|
|
|
557
557
|
var VAL_CLIENT = function VAL_CLIENT(configImportPath) {
|
|
558
558
|
return "import \"client-only\";\nimport { initValClient } from \"@valbuild/next/client\";\nimport { config } from \"".concat(configImportPath, "\";\n\nconst { useValStega: useVal } = initValClient(config);\n\nexport { useVal };\n");
|
|
559
559
|
};
|
|
560
|
-
var VAL_RSC = function VAL_RSC(configImportPath) {
|
|
561
|
-
return "import \"server-only\";\nimport { initValRsc } from \"@valbuild/next/rsc\";\nimport { config } from \"".concat(configImportPath, "\";\nimport { cookies, draftMode, headers } from \"next/headers\";\n\nconst { fetchValStega: fetchVal } = initValRsc(config, {\n draftMode,\n headers,\n cookies,\n});\n\nexport { fetchVal };\n");
|
|
560
|
+
var VAL_RSC = function VAL_RSC(configImportPath, valModulesImportPath) {
|
|
561
|
+
return "import \"server-only\";\nimport { initValRsc } from \"@valbuild/next/rsc\";\nimport { config } from \"".concat(configImportPath, "\";\nimport valModules from \"").concat(valModulesImportPath, "\";\nimport { cookies, draftMode, headers } from \"next/headers\";\n\nconst { fetchValStega: fetchVal } = initValRsc(config, valModules, {\n draftMode,\n headers,\n cookies,\n});\n\nexport { fetchVal };\n");
|
|
562
562
|
};
|
|
563
563
|
var VAL_SERVER = function VAL_SERVER(configImportPath, valModulesImportPath) {
|
|
564
564
|
return "import \"server-only\";\nimport { initValServer } from \"@valbuild/next/server\";\nimport { config } from \"".concat(configImportPath, "\";\nimport { draftMode } from \"next/headers\";\nimport valModules from \"").concat(valModulesImportPath, "\";\n\nconst { valNextAppRouter } = initValServer(\n valModules,\n { ...config },\n {\n draftMode,\n }\n);\n\nexport { valNextAppRouter };\n");
|
|
@@ -1325,7 +1325,7 @@ function _plan() {
|
|
|
1325
1325
|
if (_answer6) {
|
|
1326
1326
|
plan.createValRsc = {
|
|
1327
1327
|
path: path.join(valUtilsDir, analysis.isTypeScript ? "val.rsc.ts" : "val.rsc.js"),
|
|
1328
|
-
source: VAL_RSC(valUtilsImportPath)
|
|
1328
|
+
source: VAL_RSC(valUtilsImportPath, valModulesServerImport)
|
|
1329
1329
|
};
|
|
1330
1330
|
} else {
|
|
1331
1331
|
plan.createValRsc = false;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@ import j from "jscodeshift";
|
|
|
3
3
|
export function transformNextAppRouterValProvider(
|
|
4
4
|
fileInfo: j.FileInfo,
|
|
5
5
|
api: j.API,
|
|
6
|
-
options: j.Options
|
|
6
|
+
options: j.Options,
|
|
7
7
|
) {
|
|
8
8
|
if (!options.configImportPath) {
|
|
9
9
|
throw new Error("configImportPath is required");
|
|
@@ -15,14 +15,14 @@ export function transformNextAppRouterValProvider(
|
|
|
15
15
|
.insertBefore(
|
|
16
16
|
j.importDeclaration(
|
|
17
17
|
[j.importSpecifier(j.identifier("ValProvider"))],
|
|
18
|
-
j.literal("@valbuild/next")
|
|
19
|
-
)
|
|
18
|
+
j.literal("@valbuild/next"),
|
|
19
|
+
),
|
|
20
20
|
)
|
|
21
21
|
.insertBefore(
|
|
22
22
|
j.importDeclaration(
|
|
23
23
|
[j.importSpecifier(j.identifier("config"))],
|
|
24
|
-
j.literal(options.configImportPath)
|
|
25
|
-
)
|
|
24
|
+
j.literal(options.configImportPath),
|
|
25
|
+
),
|
|
26
26
|
);
|
|
27
27
|
root
|
|
28
28
|
.findJSXElements("body")
|
|
@@ -66,8 +66,8 @@ export function transformNextAppRouterValProvider(
|
|
|
66
66
|
},
|
|
67
67
|
type: "JSXClosingElement",
|
|
68
68
|
},
|
|
69
|
-
[j.jsxExpressionContainer(j.identifier("children"))]
|
|
70
|
-
)
|
|
69
|
+
[j.jsxExpressionContainer(j.identifier("children"))],
|
|
70
|
+
),
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
73
|
}
|
package/src/codemods.test.ts
CHANGED
package/src/init.ts
CHANGED
|
@@ -26,14 +26,14 @@ const MIN_NEXT_VERSION = "13.4.0";
|
|
|
26
26
|
let maxResetLength = 0;
|
|
27
27
|
export async function init(
|
|
28
28
|
root: string = process.cwd(),
|
|
29
|
-
{ yes: defaultAnswers }: { yes?: boolean } = {}
|
|
29
|
+
{ yes: defaultAnswers }: { yes?: boolean } = {},
|
|
30
30
|
) {
|
|
31
31
|
logger.info(
|
|
32
32
|
"Initializing " +
|
|
33
33
|
chalk.bgBlack.hex("#37cd99")("Val") +
|
|
34
34
|
' in "' +
|
|
35
35
|
root +
|
|
36
|
-
'"...\n'
|
|
36
|
+
'"...\n',
|
|
37
37
|
);
|
|
38
38
|
process.stdout.write("Analyzing project...");
|
|
39
39
|
const analysis = await analyze(path.resolve(root), walk(path.resolve(root)));
|
|
@@ -126,7 +126,7 @@ const analyze = async (root: string, files: string[]): Promise<Analysis> => {
|
|
|
126
126
|
}
|
|
127
127
|
const analysis: Analysis = { root };
|
|
128
128
|
const packageJsonPath = files.find(
|
|
129
|
-
(file) => file === [root, "package.json"].join(sep)
|
|
129
|
+
(file) => file === [root, "package.json"].join(sep),
|
|
130
130
|
);
|
|
131
131
|
analysis.packageJsonDir = packageJsonPath && path.dirname(packageJsonPath);
|
|
132
132
|
|
|
@@ -148,7 +148,7 @@ const analyze = async (root: string, files: string[]): Promise<Analysis> => {
|
|
|
148
148
|
analysis.valNextVersion = packageJson.dependencies["@valbuild/next"];
|
|
149
149
|
} catch (err) {
|
|
150
150
|
throw new Error(
|
|
151
|
-
`Failed to parse package.json in file: ${packageJsonPath}
|
|
151
|
+
`Failed to parse package.json in file: ${packageJsonPath}`,
|
|
152
152
|
);
|
|
153
153
|
}
|
|
154
154
|
}
|
|
@@ -158,7 +158,7 @@ const analyze = async (root: string, files: string[]): Promise<Analysis> => {
|
|
|
158
158
|
if (minNextVersion) {
|
|
159
159
|
analysis.nextVersionIsSatisfied = semver.satisfies(
|
|
160
160
|
minNextVersion,
|
|
161
|
-
">=" + MIN_NEXT_VERSION
|
|
161
|
+
">=" + MIN_NEXT_VERSION,
|
|
162
162
|
);
|
|
163
163
|
}
|
|
164
164
|
}
|
|
@@ -167,7 +167,7 @@ const analyze = async (root: string, files: string[]): Promise<Analysis> => {
|
|
|
167
167
|
if (minValVersion) {
|
|
168
168
|
analysis.valNextVersionIsSatisfied = semver.satisfies(
|
|
169
169
|
minValVersion,
|
|
170
|
-
">=" + MIN_VAL_VERSION
|
|
170
|
+
">=" + MIN_VAL_VERSION,
|
|
171
171
|
);
|
|
172
172
|
}
|
|
173
173
|
}
|
|
@@ -176,7 +176,7 @@ const analyze = async (root: string, files: string[]): Promise<Analysis> => {
|
|
|
176
176
|
if (minValVersion) {
|
|
177
177
|
analysis.valCoreVersionIsSatisfied = semver.satisfies(
|
|
178
178
|
minValVersion,
|
|
179
|
-
">=" + MIN_VAL_VERSION
|
|
179
|
+
">=" + MIN_VAL_VERSION,
|
|
180
180
|
);
|
|
181
181
|
}
|
|
182
182
|
}
|
|
@@ -187,7 +187,7 @@ const analyze = async (root: string, files: string[]): Promise<Analysis> => {
|
|
|
187
187
|
if (analysis.eslintRcJsText) {
|
|
188
188
|
// TODO: Evaluate and extract config?
|
|
189
189
|
analysis.isValEslintRulesConfigured = analysis.eslintRcJsText.includes(
|
|
190
|
-
"plugin:@valbuild/recommended"
|
|
190
|
+
"plugin:@valbuild/recommended",
|
|
191
191
|
);
|
|
192
192
|
}
|
|
193
193
|
}
|
|
@@ -197,12 +197,12 @@ const analyze = async (root: string, files: string[]): Promise<Analysis> => {
|
|
|
197
197
|
if (analysis.eslintRcJsonPath) {
|
|
198
198
|
analysis.eslintRcJsonText = fs.readFileSync(
|
|
199
199
|
analysis.eslintRcJsonPath,
|
|
200
|
-
"utf8"
|
|
200
|
+
"utf8",
|
|
201
201
|
);
|
|
202
202
|
if (analysis.eslintRcJsonText) {
|
|
203
203
|
// TODO: Parse properly
|
|
204
204
|
analysis.isValEslintRulesConfigured = analysis.eslintRcJsonText.includes(
|
|
205
|
-
"plugin:@valbuild/recommended"
|
|
205
|
+
"plugin:@valbuild/recommended",
|
|
206
206
|
);
|
|
207
207
|
}
|
|
208
208
|
}
|
|
@@ -295,7 +295,7 @@ type Plan = Partial<{
|
|
|
295
295
|
|
|
296
296
|
async function plan(
|
|
297
297
|
analysis: Readonly<Analysis>,
|
|
298
|
-
defaultAnswers: boolean = false
|
|
298
|
+
defaultAnswers: boolean = false,
|
|
299
299
|
): Promise<Plan> {
|
|
300
300
|
const plan: Plan = { root: analysis.root };
|
|
301
301
|
|
|
@@ -329,7 +329,7 @@ async function plan(
|
|
|
329
329
|
} else {
|
|
330
330
|
if (!analysis.valCoreVersionIsSatisfied) {
|
|
331
331
|
logger.warn(
|
|
332
|
-
` This init script expects @valbuild/core >= ${MIN_VAL_VERSION}. Found: ${analysis.valCoreVersion}
|
|
332
|
+
` This init script expects @valbuild/core >= ${MIN_VAL_VERSION}. Found: ${analysis.valCoreVersion}`,
|
|
333
333
|
);
|
|
334
334
|
const answer = !defaultAnswers
|
|
335
335
|
? await confirm({
|
|
@@ -339,14 +339,14 @@ async function plan(
|
|
|
339
339
|
: false;
|
|
340
340
|
if (!answer) {
|
|
341
341
|
logger.error(
|
|
342
|
-
`Aborted: @valbuild/core version is not satisfied.\n\nInstall the @valbuild/core@${MIN_VAL_VERSION} package with your favorite package manager.\n\nExample:\n\n npm install -D @valbuild/core@${MIN_VAL_VERSION}\n
|
|
342
|
+
`Aborted: @valbuild/core version is not satisfied.\n\nInstall the @valbuild/core@${MIN_VAL_VERSION} package with your favorite package manager.\n\nExample:\n\n npm install -D @valbuild/core@${MIN_VAL_VERSION}\n`,
|
|
343
343
|
);
|
|
344
344
|
return { abort: true };
|
|
345
345
|
}
|
|
346
346
|
} else {
|
|
347
347
|
logger.info(
|
|
348
348
|
` Val version: found ${analysis.valCoreVersion} >= ${MIN_VAL_VERSION}`,
|
|
349
|
-
{ isGood: true }
|
|
349
|
+
{ isGood: true },
|
|
350
350
|
);
|
|
351
351
|
}
|
|
352
352
|
}
|
|
@@ -356,7 +356,7 @@ async function plan(
|
|
|
356
356
|
} else {
|
|
357
357
|
if (!analysis.valNextVersionIsSatisfied) {
|
|
358
358
|
logger.warn(
|
|
359
|
-
` This init script expects @valbuild/next >= ${MIN_VAL_VERSION}. Found: ${analysis.valNextVersion}
|
|
359
|
+
` This init script expects @valbuild/next >= ${MIN_VAL_VERSION}. Found: ${analysis.valNextVersion}`,
|
|
360
360
|
);
|
|
361
361
|
const answer = !defaultAnswers
|
|
362
362
|
? await confirm({
|
|
@@ -366,26 +366,26 @@ async function plan(
|
|
|
366
366
|
: false;
|
|
367
367
|
if (!answer) {
|
|
368
368
|
logger.error(
|
|
369
|
-
`Aborted: @valbuild/next version is not satisfied.\n\nInstall the @valbuild/next@${MIN_VAL_VERSION} package with your favorite package manager.\n\nExample:\n\n npm install -D @valbuild/next@${MIN_VAL_VERSION}\n
|
|
369
|
+
`Aborted: @valbuild/next version is not satisfied.\n\nInstall the @valbuild/next@${MIN_VAL_VERSION} package with your favorite package manager.\n\nExample:\n\n npm install -D @valbuild/next@${MIN_VAL_VERSION}\n`,
|
|
370
370
|
);
|
|
371
371
|
return { abort: true };
|
|
372
372
|
}
|
|
373
373
|
} else {
|
|
374
374
|
logger.info(
|
|
375
375
|
` Val version: found ${analysis.valNextVersion} >= ${MIN_VAL_VERSION}`,
|
|
376
|
-
{ isGood: true }
|
|
376
|
+
{ isGood: true },
|
|
377
377
|
);
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
380
|
if (!analysis.nextVersionIsSatisfied) {
|
|
381
381
|
logger.error(
|
|
382
|
-
`Val requires Next.js >= ${MIN_NEXT_VERSION}. Found: ${analysis.nextVersion}
|
|
382
|
+
`Val requires Next.js >= ${MIN_NEXT_VERSION}. Found: ${analysis.nextVersion}`,
|
|
383
383
|
);
|
|
384
384
|
return { abort: true };
|
|
385
385
|
} else {
|
|
386
386
|
logger.info(
|
|
387
387
|
` Next.js version: found ${analysis.nextVersion} >= ${MIN_NEXT_VERSION}`,
|
|
388
|
-
{ isGood: true }
|
|
388
|
+
{ isGood: true },
|
|
389
389
|
);
|
|
390
390
|
}
|
|
391
391
|
if (analysis.isTypeScript) {
|
|
@@ -426,7 +426,7 @@ async function plan(
|
|
|
426
426
|
: false;
|
|
427
427
|
if (!answer) {
|
|
428
428
|
logger.error(
|
|
429
|
-
"Aborted: the Val eslint plugin is not installed.\n\nInstall the @valbuild/eslint-plugin package with your favorite package manager.\n\nExample:\n\n npm install -D @valbuild/eslint-plugin\n"
|
|
429
|
+
"Aborted: the Val eslint plugin is not installed.\n\nInstall the @valbuild/eslint-plugin package with your favorite package manager.\n\nExample:\n\n npm install -D @valbuild/eslint-plugin\n",
|
|
430
430
|
);
|
|
431
431
|
return { abort: true };
|
|
432
432
|
}
|
|
@@ -445,7 +445,7 @@ async function plan(
|
|
|
445
445
|
" Git state: clean (only package.json / lock files modified)",
|
|
446
446
|
{
|
|
447
447
|
isGood: true,
|
|
448
|
-
}
|
|
448
|
+
},
|
|
449
449
|
);
|
|
450
450
|
} else {
|
|
451
451
|
logger.info(" Git state: clean", { isGood: true });
|
|
@@ -474,11 +474,11 @@ async function plan(
|
|
|
474
474
|
// New required files:
|
|
475
475
|
const valConfigPath = path.join(
|
|
476
476
|
analysis.root,
|
|
477
|
-
analysis.isTypeScript ? "val.config.ts" : "val.config.js"
|
|
477
|
+
analysis.isTypeScript ? "val.config.ts" : "val.config.js",
|
|
478
478
|
);
|
|
479
479
|
if (fs.existsSync(valConfigPath)) {
|
|
480
480
|
logger.error(
|
|
481
|
-
`Aborted: a Val config file: ${valConfigPath} already exists
|
|
481
|
+
`Aborted: a Val config file: ${valConfigPath} already exists.`,
|
|
482
482
|
);
|
|
483
483
|
return { abort: true };
|
|
484
484
|
}
|
|
@@ -499,7 +499,7 @@ async function plan(
|
|
|
499
499
|
const exampleDir = path.join(analysis.srcDir, "examples", "val");
|
|
500
500
|
const examplePath = path.join(
|
|
501
501
|
exampleDir,
|
|
502
|
-
"example.val." + (analysis.isJavaScript ? "js" : "ts")
|
|
502
|
+
"example.val." + (analysis.isJavaScript ? "js" : "ts"),
|
|
503
503
|
);
|
|
504
504
|
const exampleImport = path
|
|
505
505
|
.relative(exampleDir, valConfigPath)
|
|
@@ -507,12 +507,12 @@ async function plan(
|
|
|
507
507
|
.replace(".ts", "");
|
|
508
508
|
if (!analysis.packageJsonDir) {
|
|
509
509
|
throw Error(
|
|
510
|
-
"Could not detect package.json directory! This is a Val bug."
|
|
510
|
+
"Could not detect package.json directory! This is a Val bug.",
|
|
511
511
|
);
|
|
512
512
|
}
|
|
513
513
|
const exampleModuleFilePath = `/${path.relative(
|
|
514
514
|
analysis.packageJsonDir,
|
|
515
|
-
examplePath
|
|
515
|
+
examplePath,
|
|
516
516
|
)}`;
|
|
517
517
|
|
|
518
518
|
plan.includeExample = {
|
|
@@ -520,7 +520,7 @@ async function plan(
|
|
|
520
520
|
source: BASIC_EXAMPLE(
|
|
521
521
|
exampleModuleFilePath,
|
|
522
522
|
exampleImport,
|
|
523
|
-
!!analysis.isJavaScript
|
|
523
|
+
!!analysis.isJavaScript,
|
|
524
524
|
),
|
|
525
525
|
};
|
|
526
526
|
}
|
|
@@ -555,7 +555,7 @@ async function plan(
|
|
|
555
555
|
.replace(".ts", "");
|
|
556
556
|
const valServerPath = path.join(
|
|
557
557
|
valUtilsDir,
|
|
558
|
-
analysis.isTypeScript ? "val.server.ts" : "val.server.js"
|
|
558
|
+
analysis.isTypeScript ? "val.server.ts" : "val.server.js",
|
|
559
559
|
);
|
|
560
560
|
plan.createValServer = {
|
|
561
561
|
path: valServerPath,
|
|
@@ -571,7 +571,7 @@ async function plan(
|
|
|
571
571
|
"(val)",
|
|
572
572
|
"val",
|
|
573
573
|
"[[...val]]",
|
|
574
|
-
analysis.isTypeScript ? "page.tsx" : "page.jsx"
|
|
574
|
+
analysis.isTypeScript ? "page.tsx" : "page.jsx",
|
|
575
575
|
);
|
|
576
576
|
const valPageImportPath = path
|
|
577
577
|
.relative(path.dirname(valAppPagePath), valConfigPath)
|
|
@@ -588,7 +588,7 @@ async function plan(
|
|
|
588
588
|
"api",
|
|
589
589
|
"val",
|
|
590
590
|
"[[...val]]",
|
|
591
|
-
analysis.isTypeScript ? "route.ts" : "route.js"
|
|
591
|
+
analysis.isTypeScript ? "route.ts" : "route.js",
|
|
592
592
|
);
|
|
593
593
|
const valRouterImportPath = path
|
|
594
594
|
.relative(path.dirname(valRouterPath), valServerPath)
|
|
@@ -612,7 +612,7 @@ async function plan(
|
|
|
612
612
|
plan.createValClient = {
|
|
613
613
|
path: path.join(
|
|
614
614
|
valUtilsDir,
|
|
615
|
-
analysis.isTypeScript ? "val.client.ts" : "val.client.js"
|
|
615
|
+
analysis.isTypeScript ? "val.client.ts" : "val.client.js",
|
|
616
616
|
),
|
|
617
617
|
source: VAL_CLIENT(valUtilsImportPath),
|
|
618
618
|
};
|
|
@@ -631,9 +631,9 @@ async function plan(
|
|
|
631
631
|
plan.createValRsc = {
|
|
632
632
|
path: path.join(
|
|
633
633
|
valUtilsDir,
|
|
634
|
-
analysis.isTypeScript ? "val.rsc.ts" : "val.rsc.js"
|
|
634
|
+
analysis.isTypeScript ? "val.rsc.ts" : "val.rsc.js",
|
|
635
635
|
),
|
|
636
|
-
source: VAL_RSC(valUtilsImportPath),
|
|
636
|
+
source: VAL_RSC(valUtilsImportPath, valModulesServerImport),
|
|
637
637
|
};
|
|
638
638
|
} else {
|
|
639
639
|
plan.createValRsc = false;
|
|
@@ -666,7 +666,7 @@ async function plan(
|
|
|
666
666
|
.relative(path.dirname(analysis.appRouterLayoutPath), valConfigPath)
|
|
667
667
|
.replace(".js", "")
|
|
668
668
|
.replace(".ts", ""),
|
|
669
|
-
}
|
|
669
|
+
},
|
|
670
670
|
);
|
|
671
671
|
|
|
672
672
|
const diff = diffLines(analysis.appRouterLayoutFile, res, {});
|
|
@@ -717,7 +717,7 @@ async function plan(
|
|
|
717
717
|
} else {
|
|
718
718
|
if (analysis.eslintRcJsPath) {
|
|
719
719
|
logger.warn(
|
|
720
|
-
'Cannot patch eslint: found .eslintrc.js but can only patch JSON files (at the moment).\nAdd the following to your eslint config:\n\n "extends": ["plugin:@valbuild/recommended"]\n'
|
|
720
|
+
'Cannot patch eslint: found .eslintrc.js but can only patch JSON files (at the moment).\nAdd the following to your eslint config:\n\n "extends": ["plugin:@valbuild/recommended"]\n',
|
|
721
721
|
);
|
|
722
722
|
} else if (analysis.eslintRcJsonPath) {
|
|
723
723
|
const answer = !defaultAnswers
|
|
@@ -730,12 +730,12 @@ async function plan(
|
|
|
730
730
|
if (answer) {
|
|
731
731
|
const currentEslintRc = fs.readFileSync(
|
|
732
732
|
analysis.eslintRcJsonPath,
|
|
733
|
-
"utf-8"
|
|
733
|
+
"utf-8",
|
|
734
734
|
);
|
|
735
735
|
const parsedEslint = JSON.parse(currentEslintRc);
|
|
736
736
|
if (typeof parsedEslint !== "object") {
|
|
737
737
|
logger.error(
|
|
738
|
-
`Could not patch eslint: ${analysis.eslintRcJsonPath} was not an object
|
|
738
|
+
`Could not patch eslint: ${analysis.eslintRcJsonPath} was not an object`,
|
|
739
739
|
);
|
|
740
740
|
return { abort: true };
|
|
741
741
|
}
|
|
@@ -798,7 +798,7 @@ async function plan(
|
|
|
798
798
|
logger.warn(
|
|
799
799
|
`Failed to parse VS Code extensions.json found here: ${settingsPath}.${
|
|
800
800
|
err instanceof Error ? `Parse error: ${err.message}` : ""
|
|
801
|
-
}
|
|
801
|
+
}`,
|
|
802
802
|
);
|
|
803
803
|
return {
|
|
804
804
|
abort: true,
|
|
@@ -816,7 +816,7 @@ async function plan(
|
|
|
816
816
|
currentSettings = {
|
|
817
817
|
...currentSettings,
|
|
818
818
|
recommendations: (currentRecommendations || []).concat(
|
|
819
|
-
valBuildIntelliSense
|
|
819
|
+
valBuildIntelliSense,
|
|
820
820
|
),
|
|
821
821
|
};
|
|
822
822
|
}
|
|
@@ -865,12 +865,12 @@ Val was successfully initialized!
|
|
|
865
865
|
`https://app.val.build/orgs/new${
|
|
866
866
|
plan.gitRemote
|
|
867
867
|
? `?org=${encodeURIComponent(
|
|
868
|
-
plan.gitRemote.owner
|
|
868
|
+
plan.gitRemote.owner,
|
|
869
869
|
)}&owner=${encodeURIComponent(
|
|
870
|
-
plan.gitRemote.owner
|
|
870
|
+
plan.gitRemote.owner,
|
|
871
871
|
)}&repo=${encodeURIComponent(plan.gitRemote.repo)}`
|
|
872
872
|
: ""
|
|
873
|
-
}
|
|
873
|
+
}`,
|
|
874
874
|
)}
|
|
875
875
|
|
|
876
876
|
`);
|
|
@@ -879,7 +879,7 @@ Val was successfully initialized!
|
|
|
879
879
|
function writeFile(
|
|
880
880
|
fileOp: FileOp | undefined,
|
|
881
881
|
rootDir: string,
|
|
882
|
-
isUpdate: boolean
|
|
882
|
+
isUpdate: boolean,
|
|
883
883
|
) {
|
|
884
884
|
if (fileOp) {
|
|
885
885
|
fs.mkdirSync(path.dirname(fileOp.path), { recursive: true });
|
|
@@ -887,9 +887,9 @@ function writeFile(
|
|
|
887
887
|
logger.info(
|
|
888
888
|
` ${isUpdate ? "Patched" : "Created"} file: ${fileOp.path.replace(
|
|
889
889
|
rootDir,
|
|
890
|
-
""
|
|
890
|
+
"",
|
|
891
891
|
)}`,
|
|
892
|
-
{ isGood: true }
|
|
892
|
+
{ isGood: true },
|
|
893
893
|
);
|
|
894
894
|
}
|
|
895
895
|
}
|
|
@@ -907,7 +907,7 @@ function getGitStatusIsClean(gitStatus: StatusResult): Analysis["isGitClean"] {
|
|
|
907
907
|
path === "yarn.lock" ||
|
|
908
908
|
path === "pnpm-lock.yaml"
|
|
909
909
|
)
|
|
910
|
-
)
|
|
910
|
+
),
|
|
911
911
|
);
|
|
912
912
|
if (filteredFiles.length === 0) {
|
|
913
913
|
if (gitStatus.files.length !== 0) {
|
package/src/logger.ts
CHANGED
|
@@ -10,7 +10,7 @@ export function warn(message: string) {
|
|
|
10
10
|
|
|
11
11
|
export function info(
|
|
12
12
|
message: string,
|
|
13
|
-
opts: { isCodeSnippet?: true; isGood?: true } = {}
|
|
13
|
+
opts: { isCodeSnippet?: true; isGood?: true } = {},
|
|
14
14
|
) {
|
|
15
15
|
if (opts.isCodeSnippet) {
|
|
16
16
|
console.log(chalk.cyanBright("$ > ") + chalk.cyan(message));
|
package/src/main.ts
CHANGED
|
@@ -27,7 +27,7 @@ async function main() {
|
|
|
27
27
|
},
|
|
28
28
|
},
|
|
29
29
|
hardRejection: false,
|
|
30
|
-
}
|
|
30
|
+
},
|
|
31
31
|
);
|
|
32
32
|
|
|
33
33
|
await init(flags.root, { yes: flags.yes });
|
|
@@ -42,8 +42,8 @@ void main().catch((err) => {
|
|
|
42
42
|
err instanceof Error
|
|
43
43
|
? err.message + "\n" + err.stack
|
|
44
44
|
: typeof err === "object"
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
? JSON.stringify(err, null, 2)
|
|
46
|
+
: err,
|
|
47
47
|
);
|
|
48
48
|
process.exitCode = 1;
|
|
49
49
|
});
|
package/src/templates.ts
CHANGED
|
@@ -7,12 +7,16 @@ const { useValStega: useVal } = initValClient(config);
|
|
|
7
7
|
export { useVal };
|
|
8
8
|
`;
|
|
9
9
|
|
|
10
|
-
export const VAL_RSC = (
|
|
10
|
+
export const VAL_RSC = (
|
|
11
|
+
configImportPath: string,
|
|
12
|
+
valModulesImportPath: string,
|
|
13
|
+
) => `import "server-only";
|
|
11
14
|
import { initValRsc } from "@valbuild/next/rsc";
|
|
12
15
|
import { config } from "${configImportPath}";
|
|
16
|
+
import valModules from "${valModulesImportPath}";
|
|
13
17
|
import { cookies, draftMode, headers } from "next/headers";
|
|
14
18
|
|
|
15
|
-
const { fetchValStega: fetchVal } = initValRsc(config, {
|
|
19
|
+
const { fetchValStega: fetchVal } = initValRsc(config, valModules, {
|
|
16
20
|
draftMode,
|
|
17
21
|
headers,
|
|
18
22
|
cookies,
|
|
@@ -23,7 +27,7 @@ export { fetchVal };
|
|
|
23
27
|
|
|
24
28
|
export const VAL_SERVER = (
|
|
25
29
|
configImportPath: string,
|
|
26
|
-
valModulesImportPath: string
|
|
30
|
+
valModulesImportPath: string,
|
|
27
31
|
) => `import "server-only";
|
|
28
32
|
import { initValServer } from "@valbuild/next/server";
|
|
29
33
|
import { config } from "${configImportPath}";
|
|
@@ -50,7 +54,7 @@ type ValConfig = {
|
|
|
50
54
|
};
|
|
51
55
|
export const VAL_CONFIG = (
|
|
52
56
|
isTypeScript: boolean,
|
|
53
|
-
options: ValConfig
|
|
57
|
+
options: ValConfig,
|
|
54
58
|
) => `import { initVal } from "@valbuild/next";
|
|
55
59
|
|
|
56
60
|
const { s, c, val, config } = initVal(${JSON.stringify(options, null, 2)});
|
|
@@ -60,7 +64,7 @@ export { s, c, val, config };
|
|
|
60
64
|
`;
|
|
61
65
|
|
|
62
66
|
export const VAL_API_ROUTER = (
|
|
63
|
-
valServerPath: string
|
|
67
|
+
valServerPath: string,
|
|
64
68
|
) => `import { valNextAppRouter } from "${valServerPath}";
|
|
65
69
|
|
|
66
70
|
export const GET = valNextAppRouter;
|
|
@@ -72,7 +76,7 @@ export const HEAD = valNextAppRouter;
|
|
|
72
76
|
`;
|
|
73
77
|
|
|
74
78
|
export const VAL_APP_PAGE = (
|
|
75
|
-
configImportPath: string
|
|
79
|
+
configImportPath: string,
|
|
76
80
|
) => `import { ValApp } from "@valbuild/next";
|
|
77
81
|
import { config } from "${configImportPath}";
|
|
78
82
|
|
|
@@ -83,7 +87,7 @@ export default function Val() {
|
|
|
83
87
|
|
|
84
88
|
export const VAL_MODULES = (
|
|
85
89
|
configImportPath: string,
|
|
86
|
-
exampleModuleImport?: string
|
|
90
|
+
exampleModuleImport?: string,
|
|
87
91
|
) => `import { modules } from "@valbuild/next";
|
|
88
92
|
import { config } from "./${configImportPath}";
|
|
89
93
|
|
|
@@ -101,7 +105,7 @@ export default modules(config, [
|
|
|
101
105
|
export const BASIC_EXAMPLE = (
|
|
102
106
|
moduleFilePath: string,
|
|
103
107
|
configImportPath: string,
|
|
104
|
-
isJavaScript: boolean
|
|
108
|
+
isJavaScript: boolean,
|
|
105
109
|
) => `${isJavaScript ? "// @ts-check\n" : ""}/**
|
|
106
110
|
* Val example file - generated by @valbuild/init
|
|
107
111
|
**/
|