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