@valbuild/init 0.52.0 → 0.54.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/bin.js +1 -1
- package/main/dist/valbuild-init-main.cjs.dev.js +220 -182
- package/main/dist/valbuild-init-main.cjs.prod.js +220 -182
- package/main/dist/valbuild-init-main.esm.js +220 -182
- package/package.json +2 -1
- package/src/init.ts +95 -71
- package/src/templates.ts +4 -2
|
@@ -463,7 +463,7 @@ function transformNextAppRouterValProvider(fileInfo, api, options) {
|
|
|
463
463
|
|
|
464
464
|
var packageJson = {
|
|
465
465
|
name: "@valbuild/init",
|
|
466
|
-
version: "0.
|
|
466
|
+
version: "0.54.0",
|
|
467
467
|
description: "Initialize a new val.build project",
|
|
468
468
|
exports: {
|
|
469
469
|
"./main": {
|
|
@@ -473,6 +473,7 @@ var packageJson = {
|
|
|
473
473
|
"./package.json": "./package.json"
|
|
474
474
|
},
|
|
475
475
|
scripts: {
|
|
476
|
+
typecheck: "tsc --noEmit",
|
|
476
477
|
test: "jest"
|
|
477
478
|
},
|
|
478
479
|
bin: {
|
|
@@ -521,8 +522,8 @@ var VAL_SERVER = function VAL_SERVER(configImportPath) {
|
|
|
521
522
|
|
|
522
523
|
// TODO: use Val config
|
|
523
524
|
|
|
524
|
-
var VAL_CONFIG = function VAL_CONFIG(options) {
|
|
525
|
-
return "import { initVal } from \"@valbuild/next\";\n\nconst { s, val, config } = initVal(".concat(JSON.stringify(options, null, 2), ");\n\nexport { s, val, config };\n");
|
|
525
|
+
var VAL_CONFIG = function VAL_CONFIG(isTypeScript, options) {
|
|
526
|
+
return "import { initVal } from \"@valbuild/next\";\n\nconst { s, c, val, config } = initVal(".concat(JSON.stringify(options, null, 2), ");\n\n").concat(isTypeScript ? 'export type { t } from "@valbuild/next";' : "", ";\nexport { s, c, val, config };\n");
|
|
526
527
|
};
|
|
527
528
|
var VAL_API_ROUTER = function VAL_API_ROUTER(valServerPath) {
|
|
528
529
|
return "import { valNextAppRouter } from \"".concat(valServerPath, "\";\n\nexport const GET = valNextAppRouter;\nexport const POST = valNextAppRouter;\nexport const PATCH = valNextAppRouter;\nexport const DELETE = valNextAppRouter;\nexport const PUT = valNextAppRouter;\nexport const HEAD = valNextAppRouter;\n");
|
|
@@ -607,7 +608,7 @@ function walk(dir) {
|
|
|
607
608
|
maxResetLength = Math.max(maxResetLength, m.length);
|
|
608
609
|
process.stdout.write(m + " ".repeat(maxResetLength - m.length));
|
|
609
610
|
return fs__default["default"].readdirSync(dir).reduce(function (files, fileOrDirName) {
|
|
610
|
-
var fileOrDirPath = [dir, fileOrDirName].join("/"); // always use / as path separator - should work on windows as well?
|
|
611
|
+
var fileOrDirPath = [dir, fileOrDirName].join("/"); // always use / as path separator since we are doing .endsWith("/foo/bar.ts") when checking for files and we thought this would make it easier (if you are reading this and wondering wtf, then maybe not :) - should work on windows as well?
|
|
611
612
|
if (fs__default["default"].statSync(fileOrDirPath).isDirectory() && !skip.test(fileOrDirName)) {
|
|
612
613
|
return files.concat(walk(fileOrDirPath));
|
|
613
614
|
}
|
|
@@ -697,8 +698,8 @@ var analyze = /*#__PURE__*/function () {
|
|
|
697
698
|
});
|
|
698
699
|
analysis.pagesRouter = !!pagesRouterAppPath;
|
|
699
700
|
if (pagesRouterAppPath) {
|
|
700
|
-
analysis.
|
|
701
|
-
analysis.
|
|
701
|
+
analysis.isTypeScript = !!pagesRouterAppPath.endsWith(".tsx");
|
|
702
|
+
analysis.isJavaScript = !!pagesRouterAppPath.endsWith(".jsx");
|
|
702
703
|
analysis.srcDir = path__default["default"].dirname(path__default["default"].dirname(pagesRouterAppPath));
|
|
703
704
|
}
|
|
704
705
|
appRouterLayoutPath = files.find(function (file) {
|
|
@@ -710,8 +711,8 @@ var analyze = /*#__PURE__*/function () {
|
|
|
710
711
|
analysis.appRouter = true;
|
|
711
712
|
analysis.appRouterLayoutPath = appRouterLayoutPath;
|
|
712
713
|
analysis.appRouterLayoutFile = fs__default["default"].readFileSync(appRouterLayoutPath, "utf8");
|
|
713
|
-
analysis.
|
|
714
|
-
analysis.
|
|
714
|
+
analysis.isTypeScript = !!appRouterLayoutPath.endsWith(".tsx");
|
|
715
|
+
analysis.isJavaScript = !!appRouterLayoutPath.endsWith(".jsx");
|
|
715
716
|
analysis.appRouterPath = path__default["default"].dirname(appRouterLayoutPath);
|
|
716
717
|
analysis.srcDir = path__default["default"].dirname(analysis.appRouterPath);
|
|
717
718
|
}
|
|
@@ -752,12 +753,10 @@ function _plan() {
|
|
|
752
753
|
_plan = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(analysis) {
|
|
753
754
|
var defaultAnswers,
|
|
754
755
|
plan,
|
|
756
|
+
answer,
|
|
755
757
|
tsconfigJsonPath,
|
|
756
758
|
jsconfigJsonPath,
|
|
757
|
-
answer,
|
|
758
759
|
_answer,
|
|
759
|
-
currentEslintRc,
|
|
760
|
-
parsedEslint,
|
|
761
760
|
_answer2,
|
|
762
761
|
valConfigPath,
|
|
763
762
|
valUtilsDir,
|
|
@@ -775,6 +774,9 @@ function _plan() {
|
|
|
775
774
|
s,
|
|
776
775
|
_answer5,
|
|
777
776
|
_answer6,
|
|
777
|
+
_answer7,
|
|
778
|
+
currentEslintRc,
|
|
779
|
+
parsedEslint,
|
|
778
780
|
_args3 = arguments;
|
|
779
781
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
780
782
|
while (1) switch (_context3.prev = _context3.next) {
|
|
@@ -840,30 +842,64 @@ function _plan() {
|
|
|
840
842
|
abort: true
|
|
841
843
|
});
|
|
842
844
|
case 25:
|
|
845
|
+
if (analysis.valVersionIsSatisfied) {
|
|
846
|
+
_context3.next = 40;
|
|
847
|
+
break;
|
|
848
|
+
}
|
|
849
|
+
warn(" This init script expects @valbuild/next >= ".concat(MIN_VAL_VERSION, ". Found: ").concat(analysis.valVersion));
|
|
850
|
+
if (defaultAnswers) {
|
|
851
|
+
_context3.next = 33;
|
|
852
|
+
break;
|
|
853
|
+
}
|
|
854
|
+
_context3.next = 30;
|
|
855
|
+
return prompts.confirm({
|
|
856
|
+
message: "Continue?",
|
|
857
|
+
"default": false
|
|
858
|
+
});
|
|
859
|
+
case 30:
|
|
860
|
+
_context3.t0 = _context3.sent;
|
|
861
|
+
_context3.next = 34;
|
|
862
|
+
break;
|
|
863
|
+
case 33:
|
|
864
|
+
_context3.t0 = false;
|
|
865
|
+
case 34:
|
|
866
|
+
answer = _context3.t0;
|
|
867
|
+
if (answer) {
|
|
868
|
+
_context3.next = 38;
|
|
869
|
+
break;
|
|
870
|
+
}
|
|
871
|
+
error("Aborted: val version is not satisfied.\n\nInstall the @valbuild/next@".concat(MIN_VAL_VERSION, " package with your favorite package manager.\n\nExample:\n\n npm install -D @valbuild/next@").concat(MIN_VAL_VERSION, "\n"));
|
|
872
|
+
return _context3.abrupt("return", {
|
|
873
|
+
abort: true
|
|
874
|
+
});
|
|
875
|
+
case 38:
|
|
876
|
+
_context3.next = 41;
|
|
877
|
+
break;
|
|
878
|
+
case 40:
|
|
843
879
|
info(" Val version: found ".concat(analysis.valVersion, " >= ").concat(MIN_VAL_VERSION), {
|
|
844
880
|
isGood: true
|
|
845
881
|
});
|
|
846
|
-
case
|
|
882
|
+
case 41:
|
|
847
883
|
if (analysis.nextVersionIsSatisfied) {
|
|
848
|
-
_context3.next =
|
|
884
|
+
_context3.next = 46;
|
|
849
885
|
break;
|
|
850
886
|
}
|
|
851
887
|
error("Val requires Next.js >= ".concat(MIN_NEXT_VERSION, ". Found: ").concat(analysis.nextVersion));
|
|
852
888
|
return _context3.abrupt("return", {
|
|
853
889
|
abort: true
|
|
854
890
|
});
|
|
855
|
-
case
|
|
891
|
+
case 46:
|
|
856
892
|
info(" Next.js version: found ".concat(analysis.nextVersion, " >= ").concat(MIN_NEXT_VERSION), {
|
|
857
893
|
isGood: true
|
|
858
894
|
});
|
|
859
|
-
case
|
|
860
|
-
if (analysis.
|
|
895
|
+
case 47:
|
|
896
|
+
if (analysis.isTypeScript) {
|
|
861
897
|
info(" Use: TypeScript", {
|
|
862
898
|
isGood: true
|
|
863
899
|
});
|
|
864
900
|
plan.useTypescript = true;
|
|
865
901
|
}
|
|
866
|
-
if (analysis.
|
|
902
|
+
if (analysis.isJavaScript) {
|
|
867
903
|
info(" Use: JavaScript", {
|
|
868
904
|
isGood: true
|
|
869
905
|
});
|
|
@@ -871,82 +907,82 @@ function _plan() {
|
|
|
871
907
|
plan.useJavascript = true;
|
|
872
908
|
}
|
|
873
909
|
}
|
|
874
|
-
if (!analysis.
|
|
875
|
-
_context3.next =
|
|
910
|
+
if (!analysis.isTypeScript) {
|
|
911
|
+
_context3.next = 59;
|
|
876
912
|
break;
|
|
877
913
|
}
|
|
878
914
|
tsconfigJsonPath = path__default["default"].join(analysis.root, "tsconfig.json");
|
|
879
915
|
if (!fs__default["default"].statSync(tsconfigJsonPath).isFile()) {
|
|
880
|
-
_context3.next =
|
|
916
|
+
_context3.next = 55;
|
|
881
917
|
break;
|
|
882
918
|
}
|
|
883
919
|
info(" tsconfig.json: found", {
|
|
884
920
|
isGood: true
|
|
885
921
|
});
|
|
886
|
-
_context3.next =
|
|
922
|
+
_context3.next = 57;
|
|
887
923
|
break;
|
|
888
|
-
case
|
|
924
|
+
case 55:
|
|
889
925
|
error("tsconfig.json: Failed to find tsconfig.json");
|
|
890
926
|
return _context3.abrupt("return", {
|
|
891
927
|
abort: true
|
|
892
928
|
});
|
|
893
|
-
case
|
|
894
|
-
_context3.next =
|
|
929
|
+
case 57:
|
|
930
|
+
_context3.next = 66;
|
|
895
931
|
break;
|
|
896
|
-
case
|
|
932
|
+
case 59:
|
|
897
933
|
jsconfigJsonPath = path__default["default"].join(analysis.root, "jsconfig.json");
|
|
898
934
|
if (!fs__default["default"].statSync(jsconfigJsonPath).isFile()) {
|
|
899
|
-
_context3.next =
|
|
935
|
+
_context3.next = 64;
|
|
900
936
|
break;
|
|
901
937
|
}
|
|
902
938
|
info(" jsconfig.json: found", {
|
|
903
939
|
isGood: true
|
|
904
940
|
});
|
|
905
|
-
_context3.next =
|
|
941
|
+
_context3.next = 66;
|
|
906
942
|
break;
|
|
907
|
-
case
|
|
943
|
+
case 64:
|
|
908
944
|
error(" jsconfig.json: failed to find jsconfig.json");
|
|
909
945
|
return _context3.abrupt("return", {
|
|
910
946
|
abort: true
|
|
911
947
|
});
|
|
912
|
-
case
|
|
948
|
+
case 66:
|
|
913
949
|
if (!(analysis.valEslintVersion === undefined)) {
|
|
914
|
-
_context3.next =
|
|
950
|
+
_context3.next = 80;
|
|
915
951
|
break;
|
|
916
952
|
}
|
|
917
953
|
if (defaultAnswers) {
|
|
918
|
-
_context3.next =
|
|
954
|
+
_context3.next = 73;
|
|
919
955
|
break;
|
|
920
956
|
}
|
|
921
|
-
_context3.next =
|
|
957
|
+
_context3.next = 70;
|
|
922
958
|
return prompts.confirm({
|
|
923
959
|
message: "The recommended Val eslint plugin (@valbuild/eslint-plugin) is not installed. Continue?",
|
|
924
960
|
"default": false
|
|
925
961
|
});
|
|
926
|
-
case
|
|
927
|
-
_context3.
|
|
928
|
-
_context3.next =
|
|
962
|
+
case 70:
|
|
963
|
+
_context3.t1 = _context3.sent;
|
|
964
|
+
_context3.next = 74;
|
|
929
965
|
break;
|
|
930
|
-
case
|
|
931
|
-
_context3.
|
|
932
|
-
case
|
|
933
|
-
|
|
934
|
-
if (
|
|
935
|
-
_context3.next =
|
|
966
|
+
case 73:
|
|
967
|
+
_context3.t1 = false;
|
|
968
|
+
case 74:
|
|
969
|
+
_answer = _context3.t1;
|
|
970
|
+
if (_answer) {
|
|
971
|
+
_context3.next = 78;
|
|
936
972
|
break;
|
|
937
973
|
}
|
|
938
974
|
error("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");
|
|
939
975
|
return _context3.abrupt("return", {
|
|
940
976
|
abort: true
|
|
941
977
|
});
|
|
942
|
-
case
|
|
943
|
-
_context3.next =
|
|
978
|
+
case 78:
|
|
979
|
+
_context3.next = 81;
|
|
944
980
|
break;
|
|
945
|
-
case
|
|
981
|
+
case 80:
|
|
946
982
|
info(" @valbuild/eslint-plugin: installed", {
|
|
947
983
|
isGood: true
|
|
948
984
|
});
|
|
949
|
-
case
|
|
985
|
+
case 81:
|
|
950
986
|
if (analysis.appRouter) {
|
|
951
987
|
info(" Use: App Router", {
|
|
952
988
|
isGood: true
|
|
@@ -965,128 +1001,63 @@ function _plan() {
|
|
|
965
1001
|
if (!analysis.isGitClean) {
|
|
966
1002
|
warn(" Git state: dirty");
|
|
967
1003
|
}
|
|
968
|
-
if (
|
|
1004
|
+
if (analysis.isGitClean) {
|
|
969
1005
|
_context3.next = 101;
|
|
970
1006
|
break;
|
|
971
1007
|
}
|
|
972
|
-
if (!analysis.isValEslintRulesConfigured) {
|
|
973
|
-
_context3.next = 75;
|
|
974
|
-
break;
|
|
975
|
-
}
|
|
976
|
-
info(" @valbuild/eslint-plugin rules configured", {
|
|
977
|
-
isGood: true
|
|
978
|
-
});
|
|
979
|
-
_context3.next = 101;
|
|
980
|
-
break;
|
|
981
|
-
case 75:
|
|
982
|
-
if (!analysis.eslintRcJsPath) {
|
|
983
|
-
_context3.next = 79;
|
|
984
|
-
break;
|
|
985
|
-
}
|
|
986
|
-
warn('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');
|
|
987
|
-
_context3.next = 101;
|
|
988
|
-
break;
|
|
989
|
-
case 79:
|
|
990
|
-
if (!analysis.eslintRcJsonPath) {
|
|
991
|
-
_context3.next = 100;
|
|
992
|
-
break;
|
|
993
|
-
}
|
|
994
|
-
if (defaultAnswers) {
|
|
995
|
-
_context3.next = 86;
|
|
996
|
-
break;
|
|
997
|
-
}
|
|
998
|
-
_context3.next = 83;
|
|
999
|
-
return prompts.confirm({
|
|
1000
|
-
message: "Patch eslintrc.json to use the recommended Val eslint rules?",
|
|
1001
|
-
"default": true
|
|
1002
|
-
});
|
|
1003
|
-
case 83:
|
|
1004
|
-
_context3.t1 = _context3.sent;
|
|
1005
|
-
_context3.next = 87;
|
|
1006
|
-
break;
|
|
1007
1008
|
case 86:
|
|
1008
|
-
_context3.t1 = true;
|
|
1009
|
-
case 87:
|
|
1010
|
-
_answer = _context3.t1;
|
|
1011
|
-
if (!_answer) {
|
|
1012
|
-
_context3.next = 98;
|
|
1013
|
-
break;
|
|
1014
|
-
}
|
|
1015
|
-
currentEslintRc = fs__default["default"].readFileSync(analysis.eslintRcJsonPath, "utf-8");
|
|
1016
|
-
parsedEslint = JSON.parse(currentEslintRc);
|
|
1017
|
-
if (!(_typeof(parsedEslint) !== "object")) {
|
|
1018
|
-
_context3.next = 94;
|
|
1019
|
-
break;
|
|
1020
|
-
}
|
|
1021
|
-
error("Could not patch eslint: ".concat(analysis.eslintRcJsonPath, " was not an object"));
|
|
1022
|
-
return _context3.abrupt("return", {
|
|
1023
|
-
abort: true
|
|
1024
|
-
});
|
|
1025
|
-
case 94:
|
|
1026
|
-
if (typeof parsedEslint["extends"] === "string") {
|
|
1027
|
-
parsedEslint["extends"] = [parsedEslint["extends"]];
|
|
1028
|
-
}
|
|
1029
|
-
parsedEslint["extends"] = parsedEslint["extends"] || [];
|
|
1030
|
-
parsedEslint["extends"].push("plugin:@valbuild/recommended");
|
|
1031
|
-
plan.updateEslint = {
|
|
1032
|
-
path: analysis.eslintRcJsonPath,
|
|
1033
|
-
source: JSON.stringify(parsedEslint, null, 2) + "\n"
|
|
1034
|
-
};
|
|
1035
|
-
case 98:
|
|
1036
|
-
_context3.next = 101;
|
|
1037
|
-
break;
|
|
1038
|
-
case 100:
|
|
1039
|
-
warn("Cannot patch eslint: failed to find eslint config file");
|
|
1040
|
-
case 101:
|
|
1041
|
-
if (analysis.isGitClean) {
|
|
1042
|
-
_context3.next = 117;
|
|
1043
|
-
break;
|
|
1044
|
-
}
|
|
1045
|
-
case 102:
|
|
1046
1009
|
if (!(plan.ignoreGitDirty === undefined)) {
|
|
1047
|
-
_context3.next =
|
|
1010
|
+
_context3.next = 101;
|
|
1048
1011
|
break;
|
|
1049
1012
|
}
|
|
1050
1013
|
if (defaultAnswers) {
|
|
1051
|
-
_context3.next =
|
|
1014
|
+
_context3.next = 93;
|
|
1052
1015
|
break;
|
|
1053
1016
|
}
|
|
1054
|
-
_context3.next =
|
|
1017
|
+
_context3.next = 90;
|
|
1055
1018
|
return prompts.confirm({
|
|
1056
1019
|
message: "You have uncommitted changes. Continue?",
|
|
1057
1020
|
"default": false
|
|
1058
1021
|
});
|
|
1059
|
-
case
|
|
1022
|
+
case 90:
|
|
1060
1023
|
_context3.t2 = _context3.sent;
|
|
1061
|
-
_context3.next =
|
|
1024
|
+
_context3.next = 94;
|
|
1062
1025
|
break;
|
|
1063
|
-
case
|
|
1026
|
+
case 93:
|
|
1064
1027
|
_context3.t2 = false;
|
|
1065
|
-
case
|
|
1028
|
+
case 94:
|
|
1066
1029
|
_answer2 = _context3.t2;
|
|
1067
1030
|
plan.ignoreGitDirty = _answer2;
|
|
1068
1031
|
if (_answer2) {
|
|
1069
|
-
_context3.next =
|
|
1032
|
+
_context3.next = 99;
|
|
1070
1033
|
break;
|
|
1071
1034
|
}
|
|
1072
1035
|
error("Aborted: git state dirty");
|
|
1073
1036
|
return _context3.abrupt("return", {
|
|
1074
|
-
abort: true
|
|
1075
|
-
ignoreGitDirty: true
|
|
1037
|
+
abort: true
|
|
1076
1038
|
});
|
|
1077
|
-
case
|
|
1078
|
-
_context3.next =
|
|
1039
|
+
case 99:
|
|
1040
|
+
_context3.next = 86;
|
|
1079
1041
|
break;
|
|
1080
|
-
case
|
|
1042
|
+
case 101:
|
|
1081
1043
|
// New required files:
|
|
1082
|
-
valConfigPath = path__default["default"].join(analysis.root, "val.config.ts");
|
|
1044
|
+
valConfigPath = path__default["default"].join(analysis.root, analysis.isTypeScript ? "val.config.ts" : "val.config.js");
|
|
1045
|
+
if (!fs__default["default"].existsSync(valConfigPath)) {
|
|
1046
|
+
_context3.next = 105;
|
|
1047
|
+
break;
|
|
1048
|
+
}
|
|
1049
|
+
error("Aborted: a Val config file: ".concat(valConfigPath, " already exists."));
|
|
1050
|
+
return _context3.abrupt("return", {
|
|
1051
|
+
abort: true
|
|
1052
|
+
});
|
|
1053
|
+
case 105:
|
|
1083
1054
|
plan.createConfigFile = {
|
|
1084
1055
|
path: valConfigPath,
|
|
1085
|
-
source: VAL_CONFIG({})
|
|
1056
|
+
source: VAL_CONFIG(!!analysis.isTypeScript, {})
|
|
1086
1057
|
};
|
|
1087
1058
|
valUtilsDir = path__default["default"].join(analysis.srcDir, "val");
|
|
1088
1059
|
valUtilsImportPath = path__default["default"].relative(valUtilsDir, valConfigPath).replace(".js", "").replace(".ts", "");
|
|
1089
|
-
valServerPath = path__default["default"].join(valUtilsDir, analysis.
|
|
1060
|
+
valServerPath = path__default["default"].join(valUtilsDir, analysis.isTypeScript ? "val.server.ts" : "val.server.js");
|
|
1090
1061
|
plan.createValServer = {
|
|
1091
1062
|
path: valServerPath,
|
|
1092
1063
|
source: VAL_SERVER(valUtilsImportPath)
|
|
@@ -1094,13 +1065,13 @@ function _plan() {
|
|
|
1094
1065
|
if (!analysis.appRouterPath) {
|
|
1095
1066
|
warn('Creating a new "app" router');
|
|
1096
1067
|
}
|
|
1097
|
-
valAppPagePath = path__default["default"].join(analysis.appRouterPath || path__default["default"].join(analysis.srcDir, "app"), "(val)", "val", analysis.
|
|
1068
|
+
valAppPagePath = path__default["default"].join(analysis.appRouterPath || path__default["default"].join(analysis.srcDir, "app"), "(val)", "val", "[[...val]]", analysis.isTypeScript ? "page.tsx" : "page.jsx");
|
|
1098
1069
|
valPageImportPath = path__default["default"].relative(path__default["default"].dirname(valAppPagePath), valConfigPath).replace(".js", "").replace(".ts", "");
|
|
1099
1070
|
plan.createValAppPage = {
|
|
1100
1071
|
path: valAppPagePath,
|
|
1101
1072
|
source: VAL_APP_PAGE(valPageImportPath)
|
|
1102
1073
|
};
|
|
1103
|
-
valRouterPath = path__default["default"].join(analysis.appRouterPath || path__default["default"].join(analysis.srcDir, "app"), "(val)", "api", "val", analysis.
|
|
1074
|
+
valRouterPath = path__default["default"].join(analysis.appRouterPath || path__default["default"].join(analysis.srcDir, "app"), "(val)", "api", "val", "[[...val]]", analysis.isTypeScript ? "router.tsx" : "router.jsx");
|
|
1104
1075
|
valRouterImportPath = path__default["default"].relative(path__default["default"].dirname(valRouterPath), valServerPath).replace(".js", "").replace(".ts", "");
|
|
1105
1076
|
plan.createValRouter = {
|
|
1106
1077
|
path: valRouterPath,
|
|
@@ -1108,90 +1079,86 @@ function _plan() {
|
|
|
1108
1079
|
};
|
|
1109
1080
|
|
|
1110
1081
|
// Util files:
|
|
1111
|
-
case
|
|
1082
|
+
case 117:
|
|
1112
1083
|
if (!(plan.createValClient === undefined)) {
|
|
1113
|
-
_context3.next =
|
|
1084
|
+
_context3.next = 129;
|
|
1114
1085
|
break;
|
|
1115
1086
|
}
|
|
1116
1087
|
if (defaultAnswers) {
|
|
1117
|
-
_context3.next =
|
|
1088
|
+
_context3.next = 124;
|
|
1118
1089
|
break;
|
|
1119
1090
|
}
|
|
1120
|
-
_context3.next =
|
|
1091
|
+
_context3.next = 121;
|
|
1121
1092
|
return prompts.confirm({
|
|
1122
1093
|
message: "Setup useVal for Client Components",
|
|
1123
1094
|
"default": true
|
|
1124
1095
|
});
|
|
1125
|
-
case
|
|
1096
|
+
case 121:
|
|
1126
1097
|
_context3.t3 = _context3.sent;
|
|
1127
|
-
_context3.next =
|
|
1098
|
+
_context3.next = 125;
|
|
1128
1099
|
break;
|
|
1129
|
-
case
|
|
1100
|
+
case 124:
|
|
1130
1101
|
_context3.t3 = true;
|
|
1131
|
-
case
|
|
1102
|
+
case 125:
|
|
1132
1103
|
_answer3 = _context3.t3;
|
|
1133
1104
|
if (_answer3) {
|
|
1134
1105
|
plan.createValClient = {
|
|
1135
|
-
path: path__default["default"].join(valUtilsDir, analysis.
|
|
1106
|
+
path: path__default["default"].join(valUtilsDir, analysis.isTypeScript ? "val.client.ts" : "val.client.js"),
|
|
1136
1107
|
source: VAL_CLIENT(valUtilsImportPath)
|
|
1137
1108
|
};
|
|
1138
1109
|
} else {
|
|
1139
1110
|
plan.createValClient = false;
|
|
1140
1111
|
}
|
|
1141
|
-
_context3.next =
|
|
1112
|
+
_context3.next = 117;
|
|
1142
1113
|
break;
|
|
1143
|
-
case
|
|
1114
|
+
case 129:
|
|
1144
1115
|
if (!(plan.createValRsc === undefined)) {
|
|
1145
|
-
_context3.next =
|
|
1116
|
+
_context3.next = 141;
|
|
1146
1117
|
break;
|
|
1147
1118
|
}
|
|
1148
1119
|
if (defaultAnswers) {
|
|
1149
|
-
_context3.next =
|
|
1120
|
+
_context3.next = 136;
|
|
1150
1121
|
break;
|
|
1151
1122
|
}
|
|
1152
|
-
_context3.next =
|
|
1123
|
+
_context3.next = 133;
|
|
1153
1124
|
return prompts.confirm({
|
|
1154
1125
|
message: "Setup fetchVal for React Server Components",
|
|
1155
1126
|
"default": true
|
|
1156
1127
|
});
|
|
1157
|
-
case
|
|
1128
|
+
case 133:
|
|
1158
1129
|
_context3.t4 = _context3.sent;
|
|
1159
|
-
_context3.next =
|
|
1130
|
+
_context3.next = 137;
|
|
1160
1131
|
break;
|
|
1161
|
-
case
|
|
1132
|
+
case 136:
|
|
1162
1133
|
_context3.t4 = true;
|
|
1163
|
-
case
|
|
1134
|
+
case 137:
|
|
1164
1135
|
_answer4 = _context3.t4;
|
|
1165
1136
|
if (_answer4) {
|
|
1166
1137
|
plan.createValRsc = {
|
|
1167
|
-
path: path__default["default"].join(valUtilsDir, analysis.
|
|
1138
|
+
path: path__default["default"].join(valUtilsDir, analysis.isTypeScript ? "val.rsc.ts" : "val.rsc.js"),
|
|
1168
1139
|
source: VAL_SERVER(valUtilsImportPath)
|
|
1169
1140
|
};
|
|
1170
1141
|
} else {
|
|
1171
1142
|
plan.createValRsc = false;
|
|
1172
1143
|
}
|
|
1173
|
-
_context3.next =
|
|
1144
|
+
_context3.next = 129;
|
|
1174
1145
|
break;
|
|
1175
|
-
case
|
|
1176
|
-
if (analysis.eslintRcJsPath) {
|
|
1177
|
-
warn("ESLint config found: " + analysis.eslintRcJsPath);
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1146
|
+
case 141:
|
|
1180
1147
|
// Patches:
|
|
1181
1148
|
NO_PATCH_WARNING = "Remember to add the ValProvider in your root app/layout.tsx or pages/_app.tsx file.\n";
|
|
1182
1149
|
if (!analysis.appRouterLayoutPath) {
|
|
1183
|
-
_context3.next =
|
|
1150
|
+
_context3.next = 171;
|
|
1184
1151
|
break;
|
|
1185
1152
|
}
|
|
1186
1153
|
if (analysis.appRouterLayoutFile) {
|
|
1187
|
-
_context3.next =
|
|
1154
|
+
_context3.next = 146;
|
|
1188
1155
|
break;
|
|
1189
1156
|
}
|
|
1190
1157
|
error("Failed to read app router layout file");
|
|
1191
1158
|
return _context3.abrupt("return", {
|
|
1192
1159
|
abort: true
|
|
1193
1160
|
});
|
|
1194
|
-
case
|
|
1161
|
+
case 146:
|
|
1195
1162
|
res = transformNextAppRouterValProvider({
|
|
1196
1163
|
path: analysis.appRouterLayoutPath,
|
|
1197
1164
|
source: analysis.appRouterLayoutFile
|
|
@@ -1215,42 +1182,42 @@ function _plan() {
|
|
|
1215
1182
|
}
|
|
1216
1183
|
});
|
|
1217
1184
|
if (defaultAnswers) {
|
|
1218
|
-
_context3.next =
|
|
1185
|
+
_context3.next = 156;
|
|
1219
1186
|
break;
|
|
1220
1187
|
}
|
|
1221
|
-
_context3.next =
|
|
1188
|
+
_context3.next = 153;
|
|
1222
1189
|
return prompts.confirm({
|
|
1223
1190
|
message: "Automatically patch ".concat(analysis.appRouterLayoutPath, " file?"),
|
|
1224
1191
|
"default": true
|
|
1225
1192
|
});
|
|
1226
|
-
case
|
|
1193
|
+
case 153:
|
|
1227
1194
|
_context3.t5 = _context3.sent;
|
|
1228
|
-
_context3.next =
|
|
1195
|
+
_context3.next = 157;
|
|
1229
1196
|
break;
|
|
1230
|
-
case
|
|
1197
|
+
case 156:
|
|
1231
1198
|
_context3.t5 = true;
|
|
1232
|
-
case
|
|
1199
|
+
case 157:
|
|
1233
1200
|
_answer5 = _context3.t5;
|
|
1234
1201
|
if (!_answer5) {
|
|
1235
|
-
_context3.next =
|
|
1202
|
+
_context3.next = 170;
|
|
1236
1203
|
break;
|
|
1237
1204
|
}
|
|
1238
1205
|
if (defaultAnswers) {
|
|
1239
|
-
_context3.next =
|
|
1206
|
+
_context3.next = 165;
|
|
1240
1207
|
break;
|
|
1241
1208
|
}
|
|
1242
|
-
_context3.next =
|
|
1209
|
+
_context3.next = 162;
|
|
1243
1210
|
return prompts.confirm({
|
|
1244
1211
|
message: "Do you accept the following patch:\n".concat(s, "\n"),
|
|
1245
1212
|
"default": true
|
|
1246
1213
|
});
|
|
1247
|
-
case
|
|
1214
|
+
case 162:
|
|
1248
1215
|
_context3.t6 = _context3.sent;
|
|
1249
|
-
_context3.next =
|
|
1216
|
+
_context3.next = 166;
|
|
1250
1217
|
break;
|
|
1251
|
-
case
|
|
1218
|
+
case 165:
|
|
1252
1219
|
_context3.t6 = true;
|
|
1253
|
-
case
|
|
1220
|
+
case 166:
|
|
1254
1221
|
_answer6 = _context3.t6;
|
|
1255
1222
|
if (!_answer6) {
|
|
1256
1223
|
warn(NO_PATCH_WARNING);
|
|
@@ -1261,16 +1228,87 @@ function _plan() {
|
|
|
1261
1228
|
source: res
|
|
1262
1229
|
};
|
|
1263
1230
|
}
|
|
1264
|
-
_context3.next =
|
|
1231
|
+
_context3.next = 171;
|
|
1265
1232
|
break;
|
|
1266
|
-
case
|
|
1233
|
+
case 170:
|
|
1267
1234
|
warn(NO_PATCH_WARNING);
|
|
1268
|
-
case
|
|
1235
|
+
case 171:
|
|
1269
1236
|
if (analysis.pagesRouter) {
|
|
1270
1237
|
warn(NO_PATCH_WARNING);
|
|
1271
1238
|
}
|
|
1239
|
+
if (!analysis.valEslintVersion) {
|
|
1240
|
+
_context3.next = 203;
|
|
1241
|
+
break;
|
|
1242
|
+
}
|
|
1243
|
+
if (!analysis.isValEslintRulesConfigured) {
|
|
1244
|
+
_context3.next = 177;
|
|
1245
|
+
break;
|
|
1246
|
+
}
|
|
1247
|
+
warn(" @valbuild/eslint-plugin rules: already configured");
|
|
1248
|
+
_context3.next = 203;
|
|
1249
|
+
break;
|
|
1250
|
+
case 177:
|
|
1251
|
+
if (!analysis.eslintRcJsPath) {
|
|
1252
|
+
_context3.next = 181;
|
|
1253
|
+
break;
|
|
1254
|
+
}
|
|
1255
|
+
warn('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');
|
|
1256
|
+
_context3.next = 203;
|
|
1257
|
+
break;
|
|
1258
|
+
case 181:
|
|
1259
|
+
if (!analysis.eslintRcJsonPath) {
|
|
1260
|
+
_context3.next = 202;
|
|
1261
|
+
break;
|
|
1262
|
+
}
|
|
1263
|
+
if (defaultAnswers) {
|
|
1264
|
+
_context3.next = 188;
|
|
1265
|
+
break;
|
|
1266
|
+
}
|
|
1267
|
+
_context3.next = 185;
|
|
1268
|
+
return prompts.confirm({
|
|
1269
|
+
message: "Patch eslintrc.json to use the recommended Val eslint rules?",
|
|
1270
|
+
"default": true
|
|
1271
|
+
});
|
|
1272
|
+
case 185:
|
|
1273
|
+
_context3.t7 = _context3.sent;
|
|
1274
|
+
_context3.next = 189;
|
|
1275
|
+
break;
|
|
1276
|
+
case 188:
|
|
1277
|
+
_context3.t7 = true;
|
|
1278
|
+
case 189:
|
|
1279
|
+
_answer7 = _context3.t7;
|
|
1280
|
+
if (!_answer7) {
|
|
1281
|
+
_context3.next = 200;
|
|
1282
|
+
break;
|
|
1283
|
+
}
|
|
1284
|
+
currentEslintRc = fs__default["default"].readFileSync(analysis.eslintRcJsonPath, "utf-8");
|
|
1285
|
+
parsedEslint = JSON.parse(currentEslintRc);
|
|
1286
|
+
if (!(_typeof(parsedEslint) !== "object")) {
|
|
1287
|
+
_context3.next = 196;
|
|
1288
|
+
break;
|
|
1289
|
+
}
|
|
1290
|
+
error("Could not patch eslint: ".concat(analysis.eslintRcJsonPath, " was not an object"));
|
|
1291
|
+
return _context3.abrupt("return", {
|
|
1292
|
+
abort: true
|
|
1293
|
+
});
|
|
1294
|
+
case 196:
|
|
1295
|
+
if (typeof parsedEslint["extends"] === "string") {
|
|
1296
|
+
parsedEslint["extends"] = [parsedEslint["extends"]];
|
|
1297
|
+
}
|
|
1298
|
+
parsedEslint["extends"] = parsedEslint["extends"] || [];
|
|
1299
|
+
parsedEslint["extends"].push("plugin:@valbuild/recommended");
|
|
1300
|
+
plan.updateEslint = {
|
|
1301
|
+
path: analysis.eslintRcJsonPath,
|
|
1302
|
+
source: JSON.stringify(parsedEslint, null, 2) + "\n"
|
|
1303
|
+
};
|
|
1304
|
+
case 200:
|
|
1305
|
+
_context3.next = 203;
|
|
1306
|
+
break;
|
|
1307
|
+
case 202:
|
|
1308
|
+
warn("Cannot patch eslint: failed to find eslint config file");
|
|
1309
|
+
case 203:
|
|
1272
1310
|
return _context3.abrupt("return", plan);
|
|
1273
|
-
case
|
|
1311
|
+
case 204:
|
|
1274
1312
|
case "end":
|
|
1275
1313
|
return _context3.stop();
|
|
1276
1314
|
}
|