@donotdev/cli 0.0.25 → 0.0.26
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/README.md +7 -295
- package/dependencies-matrix.json +46 -134
- package/dist/bin/commands/agent-setup.js +1 -1
- package/dist/bin/commands/build.js +143 -142
- package/dist/bin/commands/bump.js +145 -144
- package/dist/bin/commands/cacheout.js +142 -141
- package/dist/bin/commands/coach.js +156 -151
- package/dist/bin/commands/create-app.js +22 -22
- package/dist/bin/commands/create-project.js +165 -164
- package/dist/bin/commands/db.js +46704 -46703
- package/dist/bin/commands/deploy.js +674 -575
- package/dist/bin/commands/dev.js +179 -159
- package/dist/bin/commands/doctor.js +152 -151
- package/dist/bin/commands/emu.js +173 -167
- package/dist/bin/commands/format.js +142 -141
- package/dist/bin/commands/get-demo.js +1 -1
- package/dist/bin/commands/make-admin.js +64121 -64042
- package/dist/bin/commands/preview.js +178 -159
- package/dist/bin/commands/seed.js +46704 -46703
- package/dist/bin/commands/setup-cicd.js +164 -158
- package/dist/bin/commands/setup.js +409 -209
- package/dist/bin/commands/staging.js +674 -575
- package/dist/bin/commands/sync-secrets.js +142 -141
- package/dist/bin/commands/type-check.js +142 -141
- package/dist/bin/dndev.js +79 -1
- package/dist/index.js +705 -590
- package/package.json +1 -1
- package/templates/root-consumer/bunfig.toml.example +6 -49
- package/templates/root-consumer/guides/dndev/SETUP_VERCEL.md.example +26 -9
|
@@ -947,6 +947,148 @@ var init_cli_output = __esm({
|
|
|
947
947
|
}
|
|
948
948
|
});
|
|
949
949
|
|
|
950
|
+
// packages/tooling/src/utils/errors.ts
|
|
951
|
+
var DO_NOT_DEV_ERROR_CODES, DoNotDevError;
|
|
952
|
+
var init_errors = __esm({
|
|
953
|
+
"packages/tooling/src/utils/errors.ts"() {
|
|
954
|
+
"use strict";
|
|
955
|
+
init_utils();
|
|
956
|
+
DO_NOT_DEV_ERROR_CODES = {
|
|
957
|
+
CONFIGURATION_ERROR: "configuration-error",
|
|
958
|
+
CONFIG_NOT_FOUND: "config-not-found",
|
|
959
|
+
CONFIG_INVALID: "config-invalid",
|
|
960
|
+
PATH_RESOLUTION_ERROR: "path-resolution-error",
|
|
961
|
+
FILE_OPERATION_ERROR: "file-operation-error",
|
|
962
|
+
FILE_NOT_FOUND: "file-not-found",
|
|
963
|
+
PERMISSION_DENIED: "permission-denied",
|
|
964
|
+
GENERATION_ERROR: "generation-error",
|
|
965
|
+
TEMPLATE_ERROR: "template-error",
|
|
966
|
+
TEMPLATE_NOT_FOUND: "template-not-found",
|
|
967
|
+
CLI_EXECUTION_ERROR: "cli-execution-error",
|
|
968
|
+
COMMAND_NOT_FOUND: "command-not-found",
|
|
969
|
+
COMMAND_FAILED: "command-failed",
|
|
970
|
+
VALIDATION_ERROR: "validation-error",
|
|
971
|
+
SCHEMA_ERROR: "schema-error",
|
|
972
|
+
DEPENDENCY_ERROR: "dependency-error",
|
|
973
|
+
DEPENDENCY_NOT_FOUND: "dependency-not-found",
|
|
974
|
+
DEPENDENCY_VERSION_ERROR: "dependency-version-error",
|
|
975
|
+
INVALID_ARGUMENT: "invalid-argument",
|
|
976
|
+
MISSING_ARGUMENT: "missing-argument",
|
|
977
|
+
MISSING_PROJECT_ID: "missing-project-id",
|
|
978
|
+
FIREBASE_CLI_ERROR: "firebase-cli-error",
|
|
979
|
+
DEPLOYMENT_FAILED: "deployment-failed",
|
|
980
|
+
VERCEL_API_ERROR: "vercel-api-error",
|
|
981
|
+
OPERATION_CANCELLED: "operation-cancelled",
|
|
982
|
+
TIMEOUT_ERROR: "timeout-error",
|
|
983
|
+
UNKNOWN_ERROR: "unknown-error"
|
|
984
|
+
};
|
|
985
|
+
DoNotDevError = class _DoNotDevError extends Error {
|
|
986
|
+
/** The error code categorizing this error */
|
|
987
|
+
code;
|
|
988
|
+
/** Original error if this is wrapping another error */
|
|
989
|
+
originalError;
|
|
990
|
+
/** Additional context for the error */
|
|
991
|
+
context;
|
|
992
|
+
/** Whether this error should be displayed to the user */
|
|
993
|
+
displayable;
|
|
994
|
+
/**
|
|
995
|
+
* Creates a new DoNotDev error
|
|
996
|
+
*
|
|
997
|
+
* @param {string} message - Error message
|
|
998
|
+
* @param {DoNotDevErrorCode} code - Error code
|
|
999
|
+
* @param {object} [options] - Additional error options
|
|
1000
|
+
* @param {Error} [options.originalError] - Original error if wrapping
|
|
1001
|
+
* @param {Record<string, any>} [options.context] - Additional context data
|
|
1002
|
+
* @param {boolean} [options.displayable=true] - Whether this error should be displayed to the user
|
|
1003
|
+
*/
|
|
1004
|
+
constructor(message, code = DO_NOT_DEV_ERROR_CODES.UNKNOWN_ERROR, options) {
|
|
1005
|
+
super(message);
|
|
1006
|
+
this.name = "DoNotDevError";
|
|
1007
|
+
this.code = code;
|
|
1008
|
+
this.originalError = options?.originalError;
|
|
1009
|
+
this.context = options?.context;
|
|
1010
|
+
this.displayable = options?.displayable !== false;
|
|
1011
|
+
Object.setPrototypeOf(this, _DoNotDevError.prototype);
|
|
1012
|
+
if (Error.captureStackTrace) {
|
|
1013
|
+
Error.captureStackTrace(this, _DoNotDevError);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Formats the error for logging or display
|
|
1018
|
+
*
|
|
1019
|
+
* @returns {string} Formatted error message with code
|
|
1020
|
+
*/
|
|
1021
|
+
format() {
|
|
1022
|
+
return `[${this.code}] ${this.message}`;
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* Creates a wrapped error from another error
|
|
1026
|
+
*
|
|
1027
|
+
* @param {Error} error - Original error to wrap
|
|
1028
|
+
* @param {string} [context] - Additional context for the error
|
|
1029
|
+
* @param {DoNotDevErrorCode} [code='unknown-error'] - Error code
|
|
1030
|
+
* @param {object} [options] - Additional error options
|
|
1031
|
+
* @param {Record<string, any>} [options.context] - Additional context data
|
|
1032
|
+
* @param {boolean} [options.displayable=true] - Whether this error should be displayed to the user
|
|
1033
|
+
* @returns {DoNotDevError} New DoNotDev error wrapping the original
|
|
1034
|
+
*/
|
|
1035
|
+
static from(error2, context, code = DO_NOT_DEV_ERROR_CODES.UNKNOWN_ERROR, options) {
|
|
1036
|
+
if (!(error2 instanceof Error)) {
|
|
1037
|
+
return new _DoNotDevError(
|
|
1038
|
+
`Unknown error: ${String(error2)}`,
|
|
1039
|
+
code,
|
|
1040
|
+
options
|
|
1041
|
+
);
|
|
1042
|
+
}
|
|
1043
|
+
if (error2 instanceof _DoNotDevError) {
|
|
1044
|
+
if (!context) {
|
|
1045
|
+
return error2;
|
|
1046
|
+
}
|
|
1047
|
+
return new _DoNotDevError(`${context}: ${error2.message}`, error2.code, {
|
|
1048
|
+
originalError: error2.originalError || error2,
|
|
1049
|
+
context: { ...error2.context, ...options?.context || {} },
|
|
1050
|
+
displayable: options?.displayable ?? error2.displayable
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
const message = context ? `${context}: ${error2.message}` : error2.message;
|
|
1054
|
+
return new _DoNotDevError(message, code, {
|
|
1055
|
+
originalError: error2,
|
|
1056
|
+
context: options?.context,
|
|
1057
|
+
displayable: options?.displayable
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Maps common error types to DoNotDevErrorCode
|
|
1062
|
+
*
|
|
1063
|
+
* @param {Error} error - Error to analyze
|
|
1064
|
+
* @returns {DoNotDevErrorCode} Mapped error code
|
|
1065
|
+
*/
|
|
1066
|
+
static getErrorCodeFromError(error2) {
|
|
1067
|
+
if (error2 instanceof _DoNotDevError) {
|
|
1068
|
+
return error2.code;
|
|
1069
|
+
}
|
|
1070
|
+
const message = error2.message.toLowerCase();
|
|
1071
|
+
if (error2.name === "ValidationError" || message.includes("validation")) {
|
|
1072
|
+
return DO_NOT_DEV_ERROR_CODES.VALIDATION_ERROR;
|
|
1073
|
+
}
|
|
1074
|
+
if (message.includes("not found") || message.includes("no such file")) {
|
|
1075
|
+
return DO_NOT_DEV_ERROR_CODES.FILE_NOT_FOUND;
|
|
1076
|
+
}
|
|
1077
|
+
if (message.includes("permission") || message.includes("access denied")) {
|
|
1078
|
+
return DO_NOT_DEV_ERROR_CODES.PERMISSION_DENIED;
|
|
1079
|
+
}
|
|
1080
|
+
if (message.includes("timeout") || message.includes("timed out")) {
|
|
1081
|
+
return DO_NOT_DEV_ERROR_CODES.TIMEOUT_ERROR;
|
|
1082
|
+
}
|
|
1083
|
+
if (message.includes("dependency") || message.includes("module not found")) {
|
|
1084
|
+
return DO_NOT_DEV_ERROR_CODES.DEPENDENCY_ERROR;
|
|
1085
|
+
}
|
|
1086
|
+
return DO_NOT_DEV_ERROR_CODES.UNKNOWN_ERROR;
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
}
|
|
1090
|
+
});
|
|
1091
|
+
|
|
950
1092
|
// node_modules/.bun/fast-glob@3.3.3/node_modules/fast-glob/out/utils/array.js
|
|
951
1093
|
var require_array = __commonJS({
|
|
952
1094
|
"node_modules/.bun/fast-glob@3.3.3/node_modules/fast-glob/out/utils/array.js"(exports) {
|
|
@@ -7690,173 +7832,32 @@ var init_PathResolver = __esm({
|
|
|
7690
7832
|
}
|
|
7691
7833
|
});
|
|
7692
7834
|
|
|
7693
|
-
// packages/tooling/src/utils/
|
|
7694
|
-
|
|
7695
|
-
|
|
7696
|
-
|
|
7835
|
+
// packages/tooling/src/utils/pathResolver.ts
|
|
7836
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
7837
|
+
import {
|
|
7838
|
+
join as join2,
|
|
7839
|
+
dirname as dirname2,
|
|
7840
|
+
basename as basename2,
|
|
7841
|
+
extname as extname2,
|
|
7842
|
+
relative as relative2,
|
|
7843
|
+
resolve as resolve2,
|
|
7844
|
+
parse,
|
|
7845
|
+
isAbsolute as pathIsAbsolute
|
|
7846
|
+
} from "node:path";
|
|
7847
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
7848
|
+
function readdirSync2(dirPath, options) {
|
|
7849
|
+
return pathResolverInstance.readdirSync(dirPath, options);
|
|
7850
|
+
}
|
|
7851
|
+
var pathResolverInstance, resolvePackage, normalizePath, pathExists, readSync, writeSync, removeSync, statSync2, ensureDirSync, getRelativePathBetween, getDirname, joinPath;
|
|
7852
|
+
var init_pathResolver = __esm({
|
|
7853
|
+
"packages/tooling/src/utils/pathResolver.ts"() {
|
|
7697
7854
|
"use strict";
|
|
7698
7855
|
init_utils();
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
|
|
7702
|
-
|
|
7703
|
-
|
|
7704
|
-
FILE_OPERATION_ERROR: "file-operation-error",
|
|
7705
|
-
FILE_NOT_FOUND: "file-not-found",
|
|
7706
|
-
PERMISSION_DENIED: "permission-denied",
|
|
7707
|
-
GENERATION_ERROR: "generation-error",
|
|
7708
|
-
TEMPLATE_ERROR: "template-error",
|
|
7709
|
-
TEMPLATE_NOT_FOUND: "template-not-found",
|
|
7710
|
-
CLI_EXECUTION_ERROR: "cli-execution-error",
|
|
7711
|
-
COMMAND_NOT_FOUND: "command-not-found",
|
|
7712
|
-
COMMAND_FAILED: "command-failed",
|
|
7713
|
-
VALIDATION_ERROR: "validation-error",
|
|
7714
|
-
SCHEMA_ERROR: "schema-error",
|
|
7715
|
-
DEPENDENCY_ERROR: "dependency-error",
|
|
7716
|
-
DEPENDENCY_NOT_FOUND: "dependency-not-found",
|
|
7717
|
-
DEPENDENCY_VERSION_ERROR: "dependency-version-error",
|
|
7718
|
-
INVALID_ARGUMENT: "invalid-argument",
|
|
7719
|
-
MISSING_ARGUMENT: "missing-argument",
|
|
7720
|
-
MISSING_PROJECT_ID: "missing-project-id",
|
|
7721
|
-
FIREBASE_CLI_ERROR: "firebase-cli-error",
|
|
7722
|
-
DEPLOYMENT_FAILED: "deployment-failed",
|
|
7723
|
-
OPERATION_CANCELLED: "operation-cancelled",
|
|
7724
|
-
TIMEOUT_ERROR: "timeout-error",
|
|
7725
|
-
UNKNOWN_ERROR: "unknown-error"
|
|
7726
|
-
};
|
|
7727
|
-
DoNotDevError = class _DoNotDevError extends Error {
|
|
7728
|
-
/** The error code categorizing this error */
|
|
7729
|
-
code;
|
|
7730
|
-
/** Original error if this is wrapping another error */
|
|
7731
|
-
originalError;
|
|
7732
|
-
/** Additional context for the error */
|
|
7733
|
-
context;
|
|
7734
|
-
/** Whether this error should be displayed to the user */
|
|
7735
|
-
displayable;
|
|
7736
|
-
/**
|
|
7737
|
-
* Creates a new DoNotDev error
|
|
7738
|
-
*
|
|
7739
|
-
* @param {string} message - Error message
|
|
7740
|
-
* @param {DoNotDevErrorCode} code - Error code
|
|
7741
|
-
* @param {object} [options] - Additional error options
|
|
7742
|
-
* @param {Error} [options.originalError] - Original error if wrapping
|
|
7743
|
-
* @param {Record<string, any>} [options.context] - Additional context data
|
|
7744
|
-
* @param {boolean} [options.displayable=true] - Whether this error should be displayed to the user
|
|
7745
|
-
*/
|
|
7746
|
-
constructor(message, code = DO_NOT_DEV_ERROR_CODES.UNKNOWN_ERROR, options) {
|
|
7747
|
-
super(message);
|
|
7748
|
-
this.name = "DoNotDevError";
|
|
7749
|
-
this.code = code;
|
|
7750
|
-
this.originalError = options?.originalError;
|
|
7751
|
-
this.context = options?.context;
|
|
7752
|
-
this.displayable = options?.displayable !== false;
|
|
7753
|
-
Object.setPrototypeOf(this, _DoNotDevError.prototype);
|
|
7754
|
-
if (Error.captureStackTrace) {
|
|
7755
|
-
Error.captureStackTrace(this, _DoNotDevError);
|
|
7756
|
-
}
|
|
7757
|
-
}
|
|
7758
|
-
/**
|
|
7759
|
-
* Formats the error for logging or display
|
|
7760
|
-
*
|
|
7761
|
-
* @returns {string} Formatted error message with code
|
|
7762
|
-
*/
|
|
7763
|
-
format() {
|
|
7764
|
-
return `[${this.code}] ${this.message}`;
|
|
7765
|
-
}
|
|
7766
|
-
/**
|
|
7767
|
-
* Creates a wrapped error from another error
|
|
7768
|
-
*
|
|
7769
|
-
* @param {Error} error - Original error to wrap
|
|
7770
|
-
* @param {string} [context] - Additional context for the error
|
|
7771
|
-
* @param {DoNotDevErrorCode} [code='unknown-error'] - Error code
|
|
7772
|
-
* @param {object} [options] - Additional error options
|
|
7773
|
-
* @param {Record<string, any>} [options.context] - Additional context data
|
|
7774
|
-
* @param {boolean} [options.displayable=true] - Whether this error should be displayed to the user
|
|
7775
|
-
* @returns {DoNotDevError} New DoNotDev error wrapping the original
|
|
7776
|
-
*/
|
|
7777
|
-
static from(error2, context, code = DO_NOT_DEV_ERROR_CODES.UNKNOWN_ERROR, options) {
|
|
7778
|
-
if (!(error2 instanceof Error)) {
|
|
7779
|
-
return new _DoNotDevError(
|
|
7780
|
-
`Unknown error: ${String(error2)}`,
|
|
7781
|
-
code,
|
|
7782
|
-
options
|
|
7783
|
-
);
|
|
7784
|
-
}
|
|
7785
|
-
if (error2 instanceof _DoNotDevError) {
|
|
7786
|
-
if (!context) {
|
|
7787
|
-
return error2;
|
|
7788
|
-
}
|
|
7789
|
-
return new _DoNotDevError(`${context}: ${error2.message}`, error2.code, {
|
|
7790
|
-
originalError: error2.originalError || error2,
|
|
7791
|
-
context: { ...error2.context, ...options?.context || {} },
|
|
7792
|
-
displayable: options?.displayable ?? error2.displayable
|
|
7793
|
-
});
|
|
7794
|
-
}
|
|
7795
|
-
const message = context ? `${context}: ${error2.message}` : error2.message;
|
|
7796
|
-
return new _DoNotDevError(message, code, {
|
|
7797
|
-
originalError: error2,
|
|
7798
|
-
context: options?.context,
|
|
7799
|
-
displayable: options?.displayable
|
|
7800
|
-
});
|
|
7801
|
-
}
|
|
7802
|
-
/**
|
|
7803
|
-
* Maps common error types to DoNotDevErrorCode
|
|
7804
|
-
*
|
|
7805
|
-
* @param {Error} error - Error to analyze
|
|
7806
|
-
* @returns {DoNotDevErrorCode} Mapped error code
|
|
7807
|
-
*/
|
|
7808
|
-
static getErrorCodeFromError(error2) {
|
|
7809
|
-
if (error2 instanceof _DoNotDevError) {
|
|
7810
|
-
return error2.code;
|
|
7811
|
-
}
|
|
7812
|
-
const message = error2.message.toLowerCase();
|
|
7813
|
-
if (error2.name === "ValidationError" || message.includes("validation")) {
|
|
7814
|
-
return DO_NOT_DEV_ERROR_CODES.VALIDATION_ERROR;
|
|
7815
|
-
}
|
|
7816
|
-
if (message.includes("not found") || message.includes("no such file")) {
|
|
7817
|
-
return DO_NOT_DEV_ERROR_CODES.FILE_NOT_FOUND;
|
|
7818
|
-
}
|
|
7819
|
-
if (message.includes("permission") || message.includes("access denied")) {
|
|
7820
|
-
return DO_NOT_DEV_ERROR_CODES.PERMISSION_DENIED;
|
|
7821
|
-
}
|
|
7822
|
-
if (message.includes("timeout") || message.includes("timed out")) {
|
|
7823
|
-
return DO_NOT_DEV_ERROR_CODES.TIMEOUT_ERROR;
|
|
7824
|
-
}
|
|
7825
|
-
if (message.includes("dependency") || message.includes("module not found")) {
|
|
7826
|
-
return DO_NOT_DEV_ERROR_CODES.DEPENDENCY_ERROR;
|
|
7827
|
-
}
|
|
7828
|
-
return DO_NOT_DEV_ERROR_CODES.UNKNOWN_ERROR;
|
|
7829
|
-
}
|
|
7830
|
-
};
|
|
7831
|
-
}
|
|
7832
|
-
});
|
|
7833
|
-
|
|
7834
|
-
// packages/tooling/src/utils/pathResolver.ts
|
|
7835
|
-
import { createRequire as createRequire2 } from "node:module";
|
|
7836
|
-
import {
|
|
7837
|
-
join as join2,
|
|
7838
|
-
dirname as dirname2,
|
|
7839
|
-
basename as basename2,
|
|
7840
|
-
extname as extname2,
|
|
7841
|
-
relative as relative2,
|
|
7842
|
-
resolve as resolve2,
|
|
7843
|
-
parse,
|
|
7844
|
-
isAbsolute as pathIsAbsolute
|
|
7845
|
-
} from "node:path";
|
|
7846
|
-
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
7847
|
-
function readdirSync2(dirPath, options) {
|
|
7848
|
-
return pathResolverInstance.readdirSync(dirPath, options);
|
|
7849
|
-
}
|
|
7850
|
-
var pathResolverInstance, resolvePackage, normalizePath, pathExists, readSync, writeSync, removeSync, statSync2, ensureDirSync, getRelativePathBetween, getDirname, joinPath;
|
|
7851
|
-
var init_pathResolver = __esm({
|
|
7852
|
-
"packages/tooling/src/utils/pathResolver.ts"() {
|
|
7853
|
-
"use strict";
|
|
7854
|
-
init_utils();
|
|
7855
|
-
init_PathResolver();
|
|
7856
|
-
pathResolverInstance = PathResolver.getInstance({ debug: false });
|
|
7857
|
-
resolvePackage = (spec, from) => pathResolverInstance.resolvePackage(spec, from || null);
|
|
7858
|
-
normalizePath = (...pathSegments) => {
|
|
7859
|
-
return pathResolverInstance.normalizePath(join2(...pathSegments));
|
|
7856
|
+
init_PathResolver();
|
|
7857
|
+
pathResolverInstance = PathResolver.getInstance({ debug: false });
|
|
7858
|
+
resolvePackage = (spec, from) => pathResolverInstance.resolvePackage(spec, from || null);
|
|
7859
|
+
normalizePath = (...pathSegments) => {
|
|
7860
|
+
return pathResolverInstance.normalizePath(join2(...pathSegments));
|
|
7860
7861
|
};
|
|
7861
7862
|
pathExists = (filePath, silent = false) => pathResolverInstance.pathExists(filePath, silent);
|
|
7862
7863
|
readSync = (filePath, options) => pathResolverInstance.readSync(filePath, options);
|
|
@@ -7964,8 +7965,8 @@ var init_typed_file_operations = __esm({
|
|
|
7964
7965
|
"packages/tooling/src/utils/typed-file-operations.ts"() {
|
|
7965
7966
|
"use strict";
|
|
7966
7967
|
init_utils();
|
|
7967
|
-
init_pathResolver();
|
|
7968
7968
|
init_errors();
|
|
7969
|
+
init_pathResolver();
|
|
7969
7970
|
}
|
|
7970
7971
|
});
|
|
7971
7972
|
|
|
@@ -8145,7 +8146,7 @@ function checkTsx() {
|
|
|
8145
8146
|
return checkCLI("tsx");
|
|
8146
8147
|
}
|
|
8147
8148
|
function getCLIInstallInstructions(tool) {
|
|
8148
|
-
const
|
|
8149
|
+
const platform2 = process.platform;
|
|
8149
8150
|
const instructions = {
|
|
8150
8151
|
[CLI_TOOLS.BUN]: {
|
|
8151
8152
|
win32: [
|
|
@@ -8261,7 +8262,7 @@ function getCLIInstallInstructions(tool) {
|
|
|
8261
8262
|
linux: ["bun install -g tsx"]
|
|
8262
8263
|
}
|
|
8263
8264
|
};
|
|
8264
|
-
const platformInstructions = instructions[tool]?.[
|
|
8265
|
+
const platformInstructions = instructions[tool]?.[platform2] || instructions[tool]?.linux || [];
|
|
8265
8266
|
return platformInstructions.join("\n \u2022 ");
|
|
8266
8267
|
}
|
|
8267
8268
|
function formatCLIMissingError(tool, additionalContext) {
|
|
@@ -8276,9 +8277,9 @@ function formatCLIMissingError(tool, additionalContext) {
|
|
|
8276
8277
|
M2.info(`
|
|
8277
8278
|
${additionalContext}`);
|
|
8278
8279
|
}
|
|
8279
|
-
const
|
|
8280
|
+
const platform2 = process.platform;
|
|
8280
8281
|
M2.info("\nIf already installed, ensure it's in your PATH:");
|
|
8281
|
-
if (
|
|
8282
|
+
if (platform2 === "win32") {
|
|
8282
8283
|
M2.message(" \u2022 Check with: where " + tool);
|
|
8283
8284
|
M2.message(
|
|
8284
8285
|
" \u2022 Common location: C:\\Users\\<username>\\AppData\\Roaming\\npm\\"
|
|
@@ -8335,153 +8336,6 @@ var init_cli_tools = __esm({
|
|
|
8335
8336
|
}
|
|
8336
8337
|
});
|
|
8337
8338
|
|
|
8338
|
-
// packages/tooling/src/utils/secrets-resolver.ts
|
|
8339
|
-
function parseEnvFile(filePath) {
|
|
8340
|
-
if (!pathExists(filePath)) return {};
|
|
8341
|
-
const content = readSync(filePath, { format: "text" });
|
|
8342
|
-
if (typeof content !== "string" || !content) return {};
|
|
8343
|
-
const result = {};
|
|
8344
|
-
for (const line of content.split(/\r?\n/)) {
|
|
8345
|
-
const trimmed = line.trim();
|
|
8346
|
-
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
8347
|
-
const eqIdx = trimmed.indexOf("=");
|
|
8348
|
-
if (eqIdx === -1) continue;
|
|
8349
|
-
const key = trimmed.slice(0, eqIdx).trim();
|
|
8350
|
-
let value = trimmed.slice(eqIdx + 1).trim();
|
|
8351
|
-
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
8352
|
-
value = value.slice(1, -1);
|
|
8353
|
-
}
|
|
8354
|
-
if (key && value) {
|
|
8355
|
-
result[key] = value;
|
|
8356
|
-
}
|
|
8357
|
-
}
|
|
8358
|
-
return result;
|
|
8359
|
-
}
|
|
8360
|
-
function readEnvVar(filePath, varName) {
|
|
8361
|
-
if (!pathExists(filePath)) return null;
|
|
8362
|
-
const content = readSync(filePath, { format: "text" });
|
|
8363
|
-
if (typeof content !== "string") return null;
|
|
8364
|
-
for (const line of content.split(/\r?\n/)) {
|
|
8365
|
-
const trimmed = line.trim();
|
|
8366
|
-
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
8367
|
-
if (trimmed.startsWith(`${varName}=`)) {
|
|
8368
|
-
let val = trimmed.substring(`${varName}=`.length).trim();
|
|
8369
|
-
if (val.startsWith('"') && val.endsWith('"') || val.startsWith("'") && val.endsWith("'")) {
|
|
8370
|
-
val = val.slice(1, -1);
|
|
8371
|
-
}
|
|
8372
|
-
return val || null;
|
|
8373
|
-
}
|
|
8374
|
-
}
|
|
8375
|
-
return null;
|
|
8376
|
-
}
|
|
8377
|
-
function loadDndevSecrets(projectRoot) {
|
|
8378
|
-
const secretsPath = joinPath(projectRoot, ".dndev.secrets");
|
|
8379
|
-
if (cachedSecretsPath === secretsPath && cachedSecrets) {
|
|
8380
|
-
return cachedSecrets;
|
|
8381
|
-
}
|
|
8382
|
-
cachedSecrets = parseEnvFile(secretsPath);
|
|
8383
|
-
cachedSecretsPath = secretsPath;
|
|
8384
|
-
return cachedSecrets;
|
|
8385
|
-
}
|
|
8386
|
-
function resolveSecret(name, projectRoot, opts) {
|
|
8387
|
-
const appDir = opts?.appDir ?? projectRoot;
|
|
8388
|
-
const envValue = process.env[name];
|
|
8389
|
-
if (envValue) {
|
|
8390
|
-
return { value: envValue, source: "process.env" };
|
|
8391
|
-
}
|
|
8392
|
-
const secrets = loadDndevSecrets(projectRoot);
|
|
8393
|
-
if (secrets[name]) {
|
|
8394
|
-
return { value: secrets[name], source: ".dndev.secrets" };
|
|
8395
|
-
}
|
|
8396
|
-
if (name === "SUPABASE_SECRET_KEY" && secrets["SUPABASE_SERVICE_ROLE_KEY"]) {
|
|
8397
|
-
return {
|
|
8398
|
-
value: secrets["SUPABASE_SERVICE_ROLE_KEY"],
|
|
8399
|
-
source: ".dndev.secrets"
|
|
8400
|
-
};
|
|
8401
|
-
}
|
|
8402
|
-
const legacyPaths = LEGACY_PATHS[name];
|
|
8403
|
-
if (legacyPaths) {
|
|
8404
|
-
for (const relPath of legacyPaths) {
|
|
8405
|
-
const fullPath = joinPath(appDir, relPath);
|
|
8406
|
-
const value = readEnvVar(fullPath, name);
|
|
8407
|
-
if (value) {
|
|
8408
|
-
if (!opts?.silent && !warnedLegacy.has(name)) {
|
|
8409
|
-
warnedLegacy.add(name);
|
|
8410
|
-
log.warn(
|
|
8411
|
-
`${name} found in ${relPath} (legacy). Move it to .dndev.secrets at project root.`
|
|
8412
|
-
);
|
|
8413
|
-
}
|
|
8414
|
-
return { value, source: "legacy", legacyPath: relPath };
|
|
8415
|
-
}
|
|
8416
|
-
if (name === "SUPABASE_SECRET_KEY") {
|
|
8417
|
-
const aliasValue = readEnvVar(fullPath, "SUPABASE_SERVICE_ROLE_KEY");
|
|
8418
|
-
if (aliasValue) {
|
|
8419
|
-
if (!opts?.silent && !warnedLegacy.has(name)) {
|
|
8420
|
-
warnedLegacy.add(name);
|
|
8421
|
-
log.warn(
|
|
8422
|
-
`${name} found in ${relPath} (legacy). Move it to .dndev.secrets at project root.`
|
|
8423
|
-
);
|
|
8424
|
-
}
|
|
8425
|
-
return { value: aliasValue, source: "legacy", legacyPath: relPath };
|
|
8426
|
-
}
|
|
8427
|
-
}
|
|
8428
|
-
}
|
|
8429
|
-
}
|
|
8430
|
-
return null;
|
|
8431
|
-
}
|
|
8432
|
-
var LEGACY_PATHS, warnedLegacy, cachedSecretsPath, cachedSecrets;
|
|
8433
|
-
var init_secrets_resolver = __esm({
|
|
8434
|
-
"packages/tooling/src/utils/secrets-resolver.ts"() {
|
|
8435
|
-
"use strict";
|
|
8436
|
-
init_utils();
|
|
8437
|
-
init_pathResolver();
|
|
8438
|
-
init_cli_output();
|
|
8439
|
-
LEGACY_PATHS = {
|
|
8440
|
-
VERCEL_TOKEN: [".env.local"],
|
|
8441
|
-
SUPABASE_SECRET_KEY: ["supabase/functions/.env", "functions/.env"],
|
|
8442
|
-
SUPABASE_DB_URL: ["supabase/functions/.env", "functions/.env"],
|
|
8443
|
-
SUPABASE_ACCESS_TOKEN: ["supabase/functions/.env", "functions/.env"],
|
|
8444
|
-
STRIPE_SECRET_KEY: ["supabase/functions/.env", "functions/.env"],
|
|
8445
|
-
STRIPE_WEBHOOK_SECRET: ["supabase/functions/.env", "functions/.env"]
|
|
8446
|
-
};
|
|
8447
|
-
warnedLegacy = /* @__PURE__ */ new Set();
|
|
8448
|
-
cachedSecretsPath = null;
|
|
8449
|
-
cachedSecrets = null;
|
|
8450
|
-
}
|
|
8451
|
-
});
|
|
8452
|
-
|
|
8453
|
-
// packages/tooling/src/cli/setup/vercel-token.ts
|
|
8454
|
-
function resolvePerAppVar(appDir, varName) {
|
|
8455
|
-
if (process.env[varName]) return process.env[varName];
|
|
8456
|
-
const fromLocal = readEnvVar(joinPath(appDir, ".env.local"), varName);
|
|
8457
|
-
if (fromLocal) return fromLocal;
|
|
8458
|
-
const fromEnv = readEnvVar(joinPath(appDir, ".env"), varName);
|
|
8459
|
-
if (fromEnv) return fromEnv;
|
|
8460
|
-
return null;
|
|
8461
|
-
}
|
|
8462
|
-
function resolveVercelCredentials(appDir, projectRoot) {
|
|
8463
|
-
const root = projectRoot ?? process.cwd();
|
|
8464
|
-
const token = resolveSecret("VERCEL_TOKEN", root, { appDir })?.value ?? null;
|
|
8465
|
-
const orgId = resolvePerAppVar(appDir, "VERCEL_ORG_ID");
|
|
8466
|
-
const projectId = resolvePerAppVar(appDir, "VERCEL_PROJECT_ID");
|
|
8467
|
-
const missing = [];
|
|
8468
|
-
if (!token) missing.push("VERCEL_TOKEN");
|
|
8469
|
-
if (!orgId) missing.push("VERCEL_ORG_ID");
|
|
8470
|
-
if (!projectId) missing.push("VERCEL_PROJECT_ID");
|
|
8471
|
-
if (missing.length > 0) return { missing };
|
|
8472
|
-
return {
|
|
8473
|
-
credentials: { token, orgId, projectId }
|
|
8474
|
-
};
|
|
8475
|
-
}
|
|
8476
|
-
var init_vercel_token = __esm({
|
|
8477
|
-
"packages/tooling/src/cli/setup/vercel-token.ts"() {
|
|
8478
|
-
"use strict";
|
|
8479
|
-
init_utils();
|
|
8480
|
-
init_secrets_resolver();
|
|
8481
|
-
init_pathResolver();
|
|
8482
|
-
}
|
|
8483
|
-
});
|
|
8484
|
-
|
|
8485
8339
|
// node_modules/.bun/yaml@2.8.2/node_modules/yaml/dist/nodes/identity.js
|
|
8486
8340
|
var require_identity = __commonJS({
|
|
8487
8341
|
"node_modules/.bun/yaml@2.8.2/node_modules/yaml/dist/nodes/identity.js"(exports) {
|
|
@@ -15866,38 +15720,267 @@ var init_error_handling = __esm({
|
|
|
15866
15720
|
}
|
|
15867
15721
|
});
|
|
15868
15722
|
|
|
15869
|
-
// packages/tooling/src/apps/
|
|
15870
|
-
|
|
15871
|
-
|
|
15872
|
-
|
|
15873
|
-
|
|
15874
|
-
|
|
15875
|
-
|
|
15876
|
-
|
|
15877
|
-
|
|
15878
|
-
}
|
|
15879
|
-
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
15880
|
-
function parseEnvFile2(filePath) {
|
|
15881
|
-
if (!pathExists(filePath)) {
|
|
15882
|
-
throw new DoNotDevError(
|
|
15883
|
-
`Environment file not found: ${filePath}`,
|
|
15884
|
-
"file-not-found",
|
|
15885
|
-
{ context: { filePath } }
|
|
15886
|
-
);
|
|
15723
|
+
// packages/tooling/src/apps/vercel-api.ts
|
|
15724
|
+
function formatVercelError(status, body, context) {
|
|
15725
|
+
let vercelCode;
|
|
15726
|
+
let vercelMessage;
|
|
15727
|
+
try {
|
|
15728
|
+
const parsed = JSON.parse(body);
|
|
15729
|
+
const err = parsed.error ?? parsed;
|
|
15730
|
+
vercelCode = err.code;
|
|
15731
|
+
vercelMessage = err.message;
|
|
15732
|
+
} catch {
|
|
15887
15733
|
}
|
|
15888
|
-
|
|
15889
|
-
|
|
15890
|
-
|
|
15734
|
+
let message;
|
|
15735
|
+
switch (status) {
|
|
15736
|
+
case 401:
|
|
15737
|
+
message = "Vercel token is invalid or expired. Generate a new one at https://vercel.com/account/tokens and update .dndev.secrets";
|
|
15738
|
+
break;
|
|
15739
|
+
case 403:
|
|
15740
|
+
if (vercelCode === "team_unauthorized" || body.includes("teamId")) {
|
|
15741
|
+
message = "Vercel token does not have access to this team. Hobby/free accounts: remove VERCEL_ORG_ID from your .env (it causes 403). Team accounts: ensure the token is scoped to the correct team.";
|
|
15742
|
+
} else {
|
|
15743
|
+
message = `Vercel access denied: ${vercelMessage ?? "check token scope and permissions"}`;
|
|
15744
|
+
}
|
|
15745
|
+
break;
|
|
15746
|
+
case 404:
|
|
15747
|
+
message = "Vercel project not found. Check VERCEL_PROJECT_ID in apps/<app>/.env \u2014 it should match the Project ID from Vercel Dashboard > Project > Settings > General.";
|
|
15748
|
+
break;
|
|
15749
|
+
case 400:
|
|
15750
|
+
if (vercelCode === "invalid_project_name") {
|
|
15751
|
+
message = "Vercel rejected the project name. This is a framework bug \u2014 please report it.";
|
|
15752
|
+
} else {
|
|
15753
|
+
message = `Vercel rejected the request: ${vercelMessage ?? body}`;
|
|
15754
|
+
}
|
|
15755
|
+
break;
|
|
15756
|
+
case 429:
|
|
15757
|
+
message = "Vercel rate limit hit. Wait a few minutes and try again.";
|
|
15758
|
+
break;
|
|
15759
|
+
default:
|
|
15760
|
+
message = `Vercel API error during ${context} (${status}): ${vercelMessage ?? body}`;
|
|
15891
15761
|
}
|
|
15892
|
-
return
|
|
15762
|
+
return new DoNotDevError(message, DO_NOT_DEV_ERROR_CODES.VERCEL_API_ERROR, {
|
|
15763
|
+
context: { status, vercelCode, context }
|
|
15764
|
+
});
|
|
15893
15765
|
}
|
|
15894
|
-
function
|
|
15895
|
-
const
|
|
15896
|
-
|
|
15897
|
-
|
|
15898
|
-
|
|
15899
|
-
|
|
15900
|
-
|
|
15766
|
+
async function validateToken(token) {
|
|
15767
|
+
const res = await fetch(`${VERCEL_API}/v2/user`, {
|
|
15768
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
15769
|
+
});
|
|
15770
|
+
if (!res.ok) {
|
|
15771
|
+
const body = await res.text();
|
|
15772
|
+
throw formatVercelError(res.status, body, "validate token");
|
|
15773
|
+
}
|
|
15774
|
+
const data = await res.json();
|
|
15775
|
+
return { username: data.user.username, email: data.user.email };
|
|
15776
|
+
}
|
|
15777
|
+
async function validateProject(token, projectId, orgId) {
|
|
15778
|
+
const q2 = orgId ? `?teamId=${encodeURIComponent(orgId)}` : "";
|
|
15779
|
+
const res = await fetch(
|
|
15780
|
+
`${VERCEL_API}/v9/projects/${encodeURIComponent(projectId)}${q2}`,
|
|
15781
|
+
{
|
|
15782
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
15783
|
+
}
|
|
15784
|
+
);
|
|
15785
|
+
if (!res.ok) {
|
|
15786
|
+
const body = await res.text();
|
|
15787
|
+
throw formatVercelError(res.status, body, "validate project");
|
|
15788
|
+
}
|
|
15789
|
+
const data = await res.json();
|
|
15790
|
+
return { projectName: data.name };
|
|
15791
|
+
}
|
|
15792
|
+
var VERCEL_API;
|
|
15793
|
+
var init_vercel_api = __esm({
|
|
15794
|
+
"packages/tooling/src/apps/vercel-api.ts"() {
|
|
15795
|
+
"use strict";
|
|
15796
|
+
init_utils();
|
|
15797
|
+
init_errors();
|
|
15798
|
+
VERCEL_API = "https://api.vercel.com";
|
|
15799
|
+
}
|
|
15800
|
+
});
|
|
15801
|
+
|
|
15802
|
+
// packages/tooling/src/utils/secrets-resolver.ts
|
|
15803
|
+
function parseEnvFile(filePath) {
|
|
15804
|
+
if (!pathExists(filePath)) return {};
|
|
15805
|
+
const content = readSync(filePath, { format: "text" });
|
|
15806
|
+
if (typeof content !== "string" || !content) return {};
|
|
15807
|
+
const result = {};
|
|
15808
|
+
for (const line of content.split(/\r?\n/)) {
|
|
15809
|
+
const trimmed = line.trim();
|
|
15810
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
15811
|
+
const eqIdx = trimmed.indexOf("=");
|
|
15812
|
+
if (eqIdx === -1) continue;
|
|
15813
|
+
const key = trimmed.slice(0, eqIdx).trim();
|
|
15814
|
+
let value = trimmed.slice(eqIdx + 1).trim();
|
|
15815
|
+
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
15816
|
+
value = value.slice(1, -1);
|
|
15817
|
+
}
|
|
15818
|
+
if (key && value) {
|
|
15819
|
+
result[key] = value;
|
|
15820
|
+
}
|
|
15821
|
+
}
|
|
15822
|
+
return result;
|
|
15823
|
+
}
|
|
15824
|
+
function readEnvVar(filePath, varName) {
|
|
15825
|
+
if (!pathExists(filePath)) return null;
|
|
15826
|
+
const content = readSync(filePath, { format: "text" });
|
|
15827
|
+
if (typeof content !== "string") return null;
|
|
15828
|
+
for (const line of content.split(/\r?\n/)) {
|
|
15829
|
+
const trimmed = line.trim();
|
|
15830
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
15831
|
+
if (trimmed.startsWith(`${varName}=`)) {
|
|
15832
|
+
let val = trimmed.substring(`${varName}=`.length).trim();
|
|
15833
|
+
if (val.startsWith('"') && val.endsWith('"') || val.startsWith("'") && val.endsWith("'")) {
|
|
15834
|
+
val = val.slice(1, -1);
|
|
15835
|
+
}
|
|
15836
|
+
return val || null;
|
|
15837
|
+
}
|
|
15838
|
+
}
|
|
15839
|
+
return null;
|
|
15840
|
+
}
|
|
15841
|
+
function loadDndevSecrets(projectRoot) {
|
|
15842
|
+
const secretsPath = joinPath(projectRoot, ".dndev.secrets");
|
|
15843
|
+
if (cachedSecretsPath === secretsPath && cachedSecrets) {
|
|
15844
|
+
return cachedSecrets;
|
|
15845
|
+
}
|
|
15846
|
+
cachedSecrets = parseEnvFile(secretsPath);
|
|
15847
|
+
cachedSecretsPath = secretsPath;
|
|
15848
|
+
return cachedSecrets;
|
|
15849
|
+
}
|
|
15850
|
+
function resolveSecret(name, projectRoot, opts) {
|
|
15851
|
+
const appDir = opts?.appDir ?? projectRoot;
|
|
15852
|
+
const secrets = loadDndevSecrets(projectRoot);
|
|
15853
|
+
if (secrets[name]) {
|
|
15854
|
+
return { value: secrets[name], source: ".dndev.secrets" };
|
|
15855
|
+
}
|
|
15856
|
+
if (name === "SUPABASE_SECRET_KEY" && secrets["SUPABASE_SERVICE_ROLE_KEY"]) {
|
|
15857
|
+
return {
|
|
15858
|
+
value: secrets["SUPABASE_SERVICE_ROLE_KEY"],
|
|
15859
|
+
source: ".dndev.secrets"
|
|
15860
|
+
};
|
|
15861
|
+
}
|
|
15862
|
+
const envValue = process.env[name];
|
|
15863
|
+
if (envValue) {
|
|
15864
|
+
return { value: envValue, source: "process.env" };
|
|
15865
|
+
}
|
|
15866
|
+
const legacyPaths = LEGACY_PATHS[name];
|
|
15867
|
+
if (legacyPaths) {
|
|
15868
|
+
for (const relPath of legacyPaths) {
|
|
15869
|
+
const fullPath = joinPath(appDir, relPath);
|
|
15870
|
+
const value = readEnvVar(fullPath, name);
|
|
15871
|
+
if (value) {
|
|
15872
|
+
if (!opts?.silent && !warnedLegacy.has(name)) {
|
|
15873
|
+
warnedLegacy.add(name);
|
|
15874
|
+
log.warn(
|
|
15875
|
+
`${name} found in ${relPath} (legacy). Move it to .dndev.secrets at project root.`
|
|
15876
|
+
);
|
|
15877
|
+
}
|
|
15878
|
+
return { value, source: "legacy", legacyPath: relPath };
|
|
15879
|
+
}
|
|
15880
|
+
if (name === "SUPABASE_SECRET_KEY") {
|
|
15881
|
+
const aliasValue = readEnvVar(fullPath, "SUPABASE_SERVICE_ROLE_KEY");
|
|
15882
|
+
if (aliasValue) {
|
|
15883
|
+
if (!opts?.silent && !warnedLegacy.has(name)) {
|
|
15884
|
+
warnedLegacy.add(name);
|
|
15885
|
+
log.warn(
|
|
15886
|
+
`${name} found in ${relPath} (legacy). Move it to .dndev.secrets at project root.`
|
|
15887
|
+
);
|
|
15888
|
+
}
|
|
15889
|
+
return { value: aliasValue, source: "legacy", legacyPath: relPath };
|
|
15890
|
+
}
|
|
15891
|
+
}
|
|
15892
|
+
}
|
|
15893
|
+
}
|
|
15894
|
+
return null;
|
|
15895
|
+
}
|
|
15896
|
+
var LEGACY_PATHS, warnedLegacy, cachedSecretsPath, cachedSecrets;
|
|
15897
|
+
var init_secrets_resolver = __esm({
|
|
15898
|
+
"packages/tooling/src/utils/secrets-resolver.ts"() {
|
|
15899
|
+
"use strict";
|
|
15900
|
+
init_utils();
|
|
15901
|
+
init_cli_output();
|
|
15902
|
+
init_pathResolver();
|
|
15903
|
+
LEGACY_PATHS = {
|
|
15904
|
+
VERCEL_TOKEN: [".env.local"],
|
|
15905
|
+
SUPABASE_SECRET_KEY: ["supabase/functions/.env", "functions/.env"],
|
|
15906
|
+
SUPABASE_DB_URL: ["supabase/functions/.env", "functions/.env"],
|
|
15907
|
+
SUPABASE_ACCESS_TOKEN: ["supabase/functions/.env", "functions/.env"],
|
|
15908
|
+
STRIPE_SECRET_KEY: ["supabase/functions/.env", "functions/.env"],
|
|
15909
|
+
STRIPE_WEBHOOK_SECRET: ["supabase/functions/.env", "functions/.env"]
|
|
15910
|
+
};
|
|
15911
|
+
warnedLegacy = /* @__PURE__ */ new Set();
|
|
15912
|
+
cachedSecretsPath = null;
|
|
15913
|
+
cachedSecrets = null;
|
|
15914
|
+
}
|
|
15915
|
+
});
|
|
15916
|
+
|
|
15917
|
+
// packages/tooling/src/cli/setup/vercel-token.ts
|
|
15918
|
+
function resolvePerAppVar(appDir, varName) {
|
|
15919
|
+
const fromLocal = readEnvVar(joinPath(appDir, ".env.local"), varName);
|
|
15920
|
+
if (fromLocal) return fromLocal;
|
|
15921
|
+
const fromEnv = readEnvVar(joinPath(appDir, ".env"), varName);
|
|
15922
|
+
if (fromEnv) return fromEnv;
|
|
15923
|
+
if (process.env[varName]) return process.env[varName];
|
|
15924
|
+
return null;
|
|
15925
|
+
}
|
|
15926
|
+
function resolveVercelCredentials(appDir, projectRoot) {
|
|
15927
|
+
const root = projectRoot ?? process.cwd();
|
|
15928
|
+
const token = resolveSecret("VERCEL_TOKEN", root, { appDir })?.value ?? null;
|
|
15929
|
+
const orgId = resolvePerAppVar(appDir, "VERCEL_ORG_ID");
|
|
15930
|
+
const projectId = resolvePerAppVar(appDir, "VERCEL_PROJECT_ID");
|
|
15931
|
+
const missing = [];
|
|
15932
|
+
if (!token) missing.push("VERCEL_TOKEN");
|
|
15933
|
+
if (!projectId) missing.push("VERCEL_PROJECT_ID");
|
|
15934
|
+
if (missing.length > 0) return { missing };
|
|
15935
|
+
return {
|
|
15936
|
+
credentials: {
|
|
15937
|
+
token,
|
|
15938
|
+
orgId: orgId ?? void 0,
|
|
15939
|
+
projectId
|
|
15940
|
+
}
|
|
15941
|
+
};
|
|
15942
|
+
}
|
|
15943
|
+
var init_vercel_token = __esm({
|
|
15944
|
+
"packages/tooling/src/cli/setup/vercel-token.ts"() {
|
|
15945
|
+
"use strict";
|
|
15946
|
+
init_utils();
|
|
15947
|
+
init_pathResolver();
|
|
15948
|
+
init_secrets_resolver();
|
|
15949
|
+
}
|
|
15950
|
+
});
|
|
15951
|
+
|
|
15952
|
+
// packages/tooling/src/apps/sync-secrets.ts
|
|
15953
|
+
var sync_secrets_exports = {};
|
|
15954
|
+
__export(sync_secrets_exports, {
|
|
15955
|
+
default: () => sync_secrets_default,
|
|
15956
|
+
detectGitHubRepo: () => detectGitHubRepo,
|
|
15957
|
+
main: () => main,
|
|
15958
|
+
parseSecretsWithFallback: () => parseSecretsWithFallback,
|
|
15959
|
+
setGitHubSecret: () => setGitHubSecret,
|
|
15960
|
+
uploadServiceAccountToGitHub: () => uploadServiceAccountToGitHub
|
|
15961
|
+
});
|
|
15962
|
+
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
15963
|
+
function parseEnvFile2(filePath) {
|
|
15964
|
+
if (!pathExists(filePath)) {
|
|
15965
|
+
throw new DoNotDevError(
|
|
15966
|
+
`Environment file not found: ${filePath}`,
|
|
15967
|
+
"file-not-found",
|
|
15968
|
+
{ context: { filePath } }
|
|
15969
|
+
);
|
|
15970
|
+
}
|
|
15971
|
+
const result = parseEnvFile(filePath);
|
|
15972
|
+
if (Object.keys(result).length === 0) {
|
|
15973
|
+
log.debug(`No key-value pairs found in ${filePath}`);
|
|
15974
|
+
}
|
|
15975
|
+
return result;
|
|
15976
|
+
}
|
|
15977
|
+
function parseSecretsWithFallback(envFilePath, projectRoot) {
|
|
15978
|
+
const dndevSecretsPath = joinPath(projectRoot, ".dndev.secrets");
|
|
15979
|
+
if (pathExists(dndevSecretsPath)) {
|
|
15980
|
+
const secrets = parseEnvFile(dndevSecretsPath);
|
|
15981
|
+
if (Object.keys(secrets).length > 0) {
|
|
15982
|
+
log.info(`Reading secrets from: ${dndevSecretsPath}`);
|
|
15983
|
+
return secrets;
|
|
15901
15984
|
}
|
|
15902
15985
|
}
|
|
15903
15986
|
return parseEnvFile2(envFilePath);
|
|
@@ -16382,11 +16465,11 @@ Examples:
|
|
|
16382
16465
|
}
|
|
16383
16466
|
return 0;
|
|
16384
16467
|
}
|
|
16385
|
-
const
|
|
16468
|
+
const platform2 = config.platform || detectPlatform();
|
|
16386
16469
|
if (config.verbose) {
|
|
16387
16470
|
log.debug(`Working directory: ${currentDir}`);
|
|
16388
16471
|
log.debug(`Environment file: ${envFilePath}`);
|
|
16389
|
-
log.debug(`Platform: ${
|
|
16472
|
+
log.debug(`Platform: ${platform2}`);
|
|
16390
16473
|
log.debug(`Dry run mode: ${config.dryRun}`);
|
|
16391
16474
|
}
|
|
16392
16475
|
const secrets = parseSecretsWithFallback(envFilePath, currentDir);
|
|
@@ -16395,7 +16478,7 @@ Examples:
|
|
|
16395
16478
|
log.info("No secrets found in .env file");
|
|
16396
16479
|
return 0;
|
|
16397
16480
|
}
|
|
16398
|
-
log.info(`Found ${secretKeys.length} secrets to sync to ${
|
|
16481
|
+
log.info(`Found ${secretKeys.length} secrets to sync to ${platform2}:`);
|
|
16399
16482
|
secretKeys.forEach((key) => {
|
|
16400
16483
|
if (config.verbose) {
|
|
16401
16484
|
const value = secrets[key];
|
|
@@ -16406,12 +16489,12 @@ Examples:
|
|
|
16406
16489
|
log.info(` ${key}`);
|
|
16407
16490
|
}
|
|
16408
16491
|
});
|
|
16409
|
-
const finalFirebaseProjectDir =
|
|
16492
|
+
const finalFirebaseProjectDir = platform2 === "firebase" ? firebaseProjectDir || findFirebaseProjectDir(config.envFile) : void 0;
|
|
16410
16493
|
if (config.verbose && finalFirebaseProjectDir) {
|
|
16411
16494
|
log.debug(`Firebase project directory: ${finalFirebaseProjectDir}`);
|
|
16412
16495
|
}
|
|
16413
16496
|
for (const [key, value] of Object.entries(secrets)) {
|
|
16414
|
-
if (
|
|
16497
|
+
if (platform2 === "firebase") {
|
|
16415
16498
|
await setFirebaseSecret(
|
|
16416
16499
|
key,
|
|
16417
16500
|
value,
|
|
@@ -16419,18 +16502,18 @@ Examples:
|
|
|
16419
16502
|
config.dryRun,
|
|
16420
16503
|
finalFirebaseProjectDir
|
|
16421
16504
|
);
|
|
16422
|
-
} else if (
|
|
16505
|
+
} else if (platform2 === "vercel") {
|
|
16423
16506
|
setVercelSecret(key, value, config.vercelProjectId, config.dryRun);
|
|
16424
16507
|
}
|
|
16425
16508
|
}
|
|
16426
16509
|
if (config.dryRun) {
|
|
16427
16510
|
log.success(
|
|
16428
16511
|
`
|
|
16429
|
-
Dry run completed. No secrets were actually set to ${
|
|
16512
|
+
Dry run completed. No secrets were actually set to ${platform2}.`
|
|
16430
16513
|
);
|
|
16431
16514
|
} else {
|
|
16432
16515
|
log.success(`
|
|
16433
|
-
All secrets synced successfully to ${
|
|
16516
|
+
All secrets synced successfully to ${platform2}!`);
|
|
16434
16517
|
}
|
|
16435
16518
|
return 0;
|
|
16436
16519
|
} catch (err) {
|
|
@@ -16524,10 +16607,10 @@ var init_deploy_supabase_functions = __esm({
|
|
|
16524
16607
|
"packages/tooling/src/apps/deploy-supabase-functions.ts"() {
|
|
16525
16608
|
"use strict";
|
|
16526
16609
|
init_utils();
|
|
16527
|
-
init_pathResolver();
|
|
16528
16610
|
init_cli_output();
|
|
16529
16611
|
init_cli_tools();
|
|
16530
16612
|
init_errors();
|
|
16613
|
+
init_pathResolver();
|
|
16531
16614
|
}
|
|
16532
16615
|
});
|
|
16533
16616
|
|
|
@@ -16545,7 +16628,12 @@ init_utils();
|
|
|
16545
16628
|
init_cli_output();
|
|
16546
16629
|
init_errors();
|
|
16547
16630
|
init_pathResolver();
|
|
16548
|
-
import {
|
|
16631
|
+
import {
|
|
16632
|
+
spawn,
|
|
16633
|
+
spawnSync,
|
|
16634
|
+
execSync
|
|
16635
|
+
} from "node:child_process";
|
|
16636
|
+
import { platform } from "node:os";
|
|
16549
16637
|
function clearConflictingAuth(env) {
|
|
16550
16638
|
const cleaned = { ...env };
|
|
16551
16639
|
delete cleaned.FIREBASE_TOKEN;
|
|
@@ -16650,232 +16738,60 @@ function safeRemove(path, options = {}) {
|
|
|
16650
16738
|
try {
|
|
16651
16739
|
removeSync(path);
|
|
16652
16740
|
if (options.logSuccess) {
|
|
16653
|
-
log.debug(options.successMessage ?? `Removed: ${path}`);
|
|
16654
|
-
}
|
|
16655
|
-
return true;
|
|
16656
|
-
} catch (error2) {
|
|
16657
|
-
const message = options.failureMessage ?? `Could not remove ${path}: ${error2 instanceof Error ? error2.message : String(error2)}`;
|
|
16658
|
-
if (options.silent !== false) {
|
|
16659
|
-
log.warn(message);
|
|
16660
|
-
}
|
|
16661
|
-
return false;
|
|
16662
|
-
}
|
|
16663
|
-
}
|
|
16664
|
-
|
|
16665
|
-
// packages/tooling/src/apps/deploy.ts
|
|
16666
|
-
init_utils();
|
|
16667
|
-
import { execSync as execSync4 } from "node:child_process";
|
|
16668
|
-
|
|
16669
|
-
// packages/tooling/src/apps/deploy-frontend.ts
|
|
16670
|
-
init_utils();
|
|
16671
|
-
async function deployFrontend(appDir, serviceAccountPath, projectId, config) {
|
|
16672
|
-
const s = Y2();
|
|
16673
|
-
s.start("Deploying frontend to Firebase Hosting...");
|
|
16674
|
-
const args = buildFirebaseDeployArgs(
|
|
16675
|
-
"hosting",
|
|
16676
|
-
projectId,
|
|
16677
|
-
config.debug,
|
|
16678
|
-
config.force ?? true
|
|
16679
|
-
);
|
|
16680
|
-
const result = executeFirebaseCommand(args, {
|
|
16681
|
-
cwd: appDir,
|
|
16682
|
-
serviceAccountPath,
|
|
16683
|
-
projectId,
|
|
16684
|
-
debug: config.debug
|
|
16685
|
-
});
|
|
16686
|
-
if (result.error) {
|
|
16687
|
-
s.stop("Deployment failed");
|
|
16688
|
-
throw result.error;
|
|
16689
|
-
}
|
|
16690
|
-
if (!result.success) {
|
|
16691
|
-
s.stop("Deployment failed");
|
|
16692
|
-
handleDeploymentFailure(
|
|
16693
|
-
result,
|
|
16694
|
-
`firebase ${args.join(" ")}`,
|
|
16695
|
-
serviceAccountPath
|
|
16696
|
-
);
|
|
16697
|
-
}
|
|
16698
|
-
s.stop("Frontend deployed successfully");
|
|
16699
|
-
}
|
|
16700
|
-
|
|
16701
|
-
// packages/tooling/src/apps/deploy-vercel-frontend.ts
|
|
16702
|
-
init_utils();
|
|
16703
|
-
init_cli_output();
|
|
16704
|
-
init_vercel_token();
|
|
16705
|
-
init_pathResolver();
|
|
16706
|
-
import { createHash } from "node:crypto";
|
|
16707
|
-
import { readFile, readdir } from "node:fs/promises";
|
|
16708
|
-
import { join as join3, relative as relative3 } from "node:path";
|
|
16709
|
-
var VERCEL_API = "https://api.vercel.com";
|
|
16710
|
-
var UPLOAD_BATCH_SIZE = 10;
|
|
16711
|
-
var POLL_INTERVAL_MS = 3e3;
|
|
16712
|
-
var POLL_MAX_ATTEMPTS = 100;
|
|
16713
|
-
function apiHeaders(token, extra) {
|
|
16714
|
-
return { Authorization: `Bearer ${token}`, ...extra };
|
|
16715
|
-
}
|
|
16716
|
-
function teamQuery(orgId) {
|
|
16717
|
-
return `?teamId=${encodeURIComponent(orgId)}`;
|
|
16718
|
-
}
|
|
16719
|
-
async function collectDistFiles(distDir) {
|
|
16720
|
-
const files = [];
|
|
16721
|
-
async function walk(dir) {
|
|
16722
|
-
const entries = await readdir(dir, { withFileTypes: true });
|
|
16723
|
-
for (const entry of entries) {
|
|
16724
|
-
const fullPath = join3(dir, entry.name);
|
|
16725
|
-
if (entry.isDirectory()) {
|
|
16726
|
-
await walk(fullPath);
|
|
16727
|
-
} else {
|
|
16728
|
-
const content = await readFile(fullPath);
|
|
16729
|
-
const sha = createHash("sha1").update(content).digest("hex");
|
|
16730
|
-
const rel = relative3(distDir, fullPath).split("\\").join("/");
|
|
16731
|
-
files.push({
|
|
16732
|
-
relativePath: rel,
|
|
16733
|
-
content,
|
|
16734
|
-
sha,
|
|
16735
|
-
size: content.byteLength
|
|
16736
|
-
});
|
|
16737
|
-
}
|
|
16738
|
-
}
|
|
16739
|
-
}
|
|
16740
|
-
await walk(distDir);
|
|
16741
|
-
return files;
|
|
16742
|
-
}
|
|
16743
|
-
async function uploadFiles(files, token, orgId) {
|
|
16744
|
-
const q2 = teamQuery(orgId);
|
|
16745
|
-
for (let i = 0; i < files.length; i += UPLOAD_BATCH_SIZE) {
|
|
16746
|
-
const batch = files.slice(i, i + UPLOAD_BATCH_SIZE);
|
|
16747
|
-
await Promise.all(
|
|
16748
|
-
batch.map(async (file) => {
|
|
16749
|
-
const res = await fetch(`${VERCEL_API}/v2/files${q2}`, {
|
|
16750
|
-
method: "POST",
|
|
16751
|
-
headers: apiHeaders(token, {
|
|
16752
|
-
"Content-Type": "application/octet-stream",
|
|
16753
|
-
"x-vercel-digest": file.sha,
|
|
16754
|
-
"Content-Length": String(file.size)
|
|
16755
|
-
}),
|
|
16756
|
-
body: new Uint8Array(file.content)
|
|
16757
|
-
});
|
|
16758
|
-
if (!res.ok) {
|
|
16759
|
-
const body = await res.text();
|
|
16760
|
-
log.warn(`Upload failed: ${file.relativePath} (${res.status})`);
|
|
16761
|
-
log.warn(` URL: ${VERCEL_API}/v2/files${q2}`);
|
|
16762
|
-
log.warn(` SHA: ${file.sha}, Size: ${file.size}`);
|
|
16763
|
-
log.warn(` Response: ${body}`);
|
|
16764
|
-
throw new Error(
|
|
16765
|
-
`File upload failed for ${file.relativePath} (${res.status}): ${body}`
|
|
16766
|
-
);
|
|
16767
|
-
}
|
|
16768
|
-
})
|
|
16769
|
-
);
|
|
16770
|
-
}
|
|
16771
|
-
}
|
|
16772
|
-
async function createDeployment(files, token, orgId, projectId) {
|
|
16773
|
-
const q2 = teamQuery(orgId);
|
|
16774
|
-
const body = {
|
|
16775
|
-
name: projectId,
|
|
16776
|
-
project: projectId,
|
|
16777
|
-
target: "production",
|
|
16778
|
-
files: files.map((f) => ({
|
|
16779
|
-
file: f.relativePath,
|
|
16780
|
-
sha: f.sha,
|
|
16781
|
-
size: f.size
|
|
16782
|
-
})),
|
|
16783
|
-
projectSettings: {
|
|
16784
|
-
buildCommand: "",
|
|
16785
|
-
installCommand: "",
|
|
16786
|
-
outputDirectory: "."
|
|
16787
|
-
}
|
|
16788
|
-
};
|
|
16789
|
-
const res = await fetch(`${VERCEL_API}/v13/deployments${q2}`, {
|
|
16790
|
-
method: "POST",
|
|
16791
|
-
headers: apiHeaders(token, { "Content-Type": "application/json" }),
|
|
16792
|
-
body: JSON.stringify(body)
|
|
16793
|
-
});
|
|
16794
|
-
if (!res.ok) {
|
|
16795
|
-
const text = await res.text();
|
|
16796
|
-
throw new Error(`Create deployment failed (${res.status}): ${text}`);
|
|
16797
|
-
}
|
|
16798
|
-
return await res.json();
|
|
16799
|
-
}
|
|
16800
|
-
async function waitForReady(deploymentId, token, orgId) {
|
|
16801
|
-
const q2 = teamQuery(orgId);
|
|
16802
|
-
for (let attempt = 0; attempt < POLL_MAX_ATTEMPTS; attempt++) {
|
|
16803
|
-
const res = await fetch(
|
|
16804
|
-
`${VERCEL_API}/v13/deployments/${deploymentId}${q2}`,
|
|
16805
|
-
{ headers: apiHeaders(token) }
|
|
16806
|
-
);
|
|
16807
|
-
if (!res.ok) {
|
|
16808
|
-
const text = await res.text();
|
|
16809
|
-
throw new Error(
|
|
16810
|
-
`Deployment status check failed (${res.status}): ${text}`
|
|
16811
|
-
);
|
|
16812
|
-
}
|
|
16813
|
-
const data = await res.json();
|
|
16814
|
-
if (data.readyState === "READY") return data;
|
|
16815
|
-
if (data.readyState === "ERROR") {
|
|
16816
|
-
throw new Error(
|
|
16817
|
-
`Deployment failed: ${data.errorMessage || "Unknown error"}`
|
|
16818
|
-
);
|
|
16741
|
+
log.debug(options.successMessage ?? `Removed: ${path}`);
|
|
16819
16742
|
}
|
|
16820
|
-
|
|
16821
|
-
|
|
16743
|
+
return true;
|
|
16744
|
+
} catch (error2) {
|
|
16745
|
+
const message = options.failureMessage ?? `Could not remove ${path}: ${error2 instanceof Error ? error2.message : String(error2)}`;
|
|
16746
|
+
if (options.silent !== false) {
|
|
16747
|
+
log.warn(message);
|
|
16822
16748
|
}
|
|
16823
|
-
|
|
16749
|
+
return false;
|
|
16824
16750
|
}
|
|
16825
|
-
throw new Error("Deployment timed out (5+ minutes)");
|
|
16826
16751
|
}
|
|
16827
|
-
|
|
16828
|
-
|
|
16829
|
-
|
|
16830
|
-
|
|
16831
|
-
|
|
16832
|
-
|
|
16833
|
-
|
|
16834
|
-
|
|
16835
|
-
|
|
16836
|
-
|
|
16837
|
-
|
|
16838
|
-
|
|
16839
|
-
|
|
16840
|
-
|
|
16841
|
-
|
|
16842
|
-
const { token, orgId, projectId } = result.credentials;
|
|
16843
|
-
const distDir = joinPath(appDir, "dist");
|
|
16844
|
-
if (!pathExists(distDir)) {
|
|
16845
|
-
throw new Error(`dist/ not found at ${distDir}. Run build first.`);
|
|
16846
|
-
}
|
|
16847
|
-
log.debug("Using Vercel REST API (token-based, no CLI)");
|
|
16848
|
-
log.info(`Vercel org: ${orgId}`);
|
|
16849
|
-
log.info(`Vercel project: ${projectId}`);
|
|
16850
|
-
log.info(
|
|
16851
|
-
`Token: ${token.slice(0, 6)}...${token.slice(-4)} (${token.length} chars)`
|
|
16752
|
+
|
|
16753
|
+
// packages/tooling/src/apps/deploy.ts
|
|
16754
|
+
init_utils();
|
|
16755
|
+
import { execSync as execSync4 } from "node:child_process";
|
|
16756
|
+
|
|
16757
|
+
// packages/tooling/src/apps/deploy-frontend.ts
|
|
16758
|
+
init_utils();
|
|
16759
|
+
async function deployFrontend(appDir, serviceAccountPath, projectId, config) {
|
|
16760
|
+
const s = Y2();
|
|
16761
|
+
s.start("Deploying frontend to Firebase Hosting...");
|
|
16762
|
+
const args = buildFirebaseDeployArgs(
|
|
16763
|
+
"hosting",
|
|
16764
|
+
projectId,
|
|
16765
|
+
config.debug,
|
|
16766
|
+
config.force ?? true
|
|
16852
16767
|
);
|
|
16853
|
-
|
|
16854
|
-
|
|
16855
|
-
|
|
16856
|
-
|
|
16768
|
+
const result = executeFirebaseCommand(args, {
|
|
16769
|
+
cwd: appDir,
|
|
16770
|
+
serviceAccountPath,
|
|
16771
|
+
projectId,
|
|
16772
|
+
debug: config.debug
|
|
16773
|
+
});
|
|
16774
|
+
if (result.error) {
|
|
16775
|
+
s.stop("Deployment failed");
|
|
16776
|
+
throw result.error;
|
|
16857
16777
|
}
|
|
16858
|
-
|
|
16859
|
-
|
|
16860
|
-
|
|
16861
|
-
|
|
16862
|
-
|
|
16863
|
-
|
|
16864
|
-
|
|
16865
|
-
const ready = await waitForReady(deployment.id, token, orgId);
|
|
16866
|
-
const prodUrl = `https://${ready.url}`;
|
|
16867
|
-
log.success(`Production: ${prodUrl}`);
|
|
16868
|
-
if (ready.alias?.length) {
|
|
16869
|
-
log.info(`Aliases: ${ready.alias.join(", ")}`);
|
|
16778
|
+
if (!result.success) {
|
|
16779
|
+
s.stop("Deployment failed");
|
|
16780
|
+
handleDeploymentFailure(
|
|
16781
|
+
result,
|
|
16782
|
+
`firebase ${args.join(" ")}`,
|
|
16783
|
+
serviceAccountPath
|
|
16784
|
+
);
|
|
16870
16785
|
}
|
|
16786
|
+
s.stop("Frontend deployed successfully");
|
|
16871
16787
|
}
|
|
16872
16788
|
|
|
16873
16789
|
// packages/tooling/src/apps/deploy-functions.ts
|
|
16874
16790
|
init_utils();
|
|
16875
16791
|
var import_yaml = __toESM(require_dist(), 1);
|
|
16876
16792
|
import { execSync as execSync2, spawnSync as spawnSync3 } from "node:child_process";
|
|
16877
|
-
init_pathResolver();
|
|
16878
16793
|
init_cli_tools();
|
|
16794
|
+
init_pathResolver();
|
|
16879
16795
|
init_typed_file_operations();
|
|
16880
16796
|
function backupFiles(functionsDir) {
|
|
16881
16797
|
const backupDir = joinPath(functionsDir, ".deploy-backup");
|
|
@@ -17366,9 +17282,9 @@ async function deployRules(appDir, serviceAccountPath, projectId, config, option
|
|
|
17366
17282
|
// packages/tooling/src/apps/deploy-utils.ts
|
|
17367
17283
|
init_utils();
|
|
17368
17284
|
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
17285
|
+
init_error_handling();
|
|
17369
17286
|
init_pathResolver();
|
|
17370
17287
|
init_typed_file_operations();
|
|
17371
|
-
init_error_handling();
|
|
17372
17288
|
function detectAvailableApps() {
|
|
17373
17289
|
const currentDir = process.cwd();
|
|
17374
17290
|
const appsDir = joinPath(currentDir, "apps");
|
|
@@ -17601,6 +17517,195 @@ function clearFirebaseCache(appDir) {
|
|
|
17601
17517
|
}
|
|
17602
17518
|
}
|
|
17603
17519
|
|
|
17520
|
+
// packages/tooling/src/apps/deploy-vercel-frontend.ts
|
|
17521
|
+
init_utils();
|
|
17522
|
+
init_vercel_api();
|
|
17523
|
+
init_vercel_token();
|
|
17524
|
+
init_cli_output();
|
|
17525
|
+
init_pathResolver();
|
|
17526
|
+
import { createHash } from "node:crypto";
|
|
17527
|
+
import { readFile, readdir } from "node:fs/promises";
|
|
17528
|
+
import { join as join3, relative as relative3 } from "node:path";
|
|
17529
|
+
var VERCEL_API2 = "https://api.vercel.com";
|
|
17530
|
+
var UPLOAD_BATCH_SIZE = 10;
|
|
17531
|
+
var POLL_INTERVAL_MS = 3e3;
|
|
17532
|
+
var POLL_MAX_ATTEMPTS = 100;
|
|
17533
|
+
function apiHeaders(token, extra) {
|
|
17534
|
+
return { Authorization: `Bearer ${token}`, ...extra };
|
|
17535
|
+
}
|
|
17536
|
+
function teamQuery(orgId) {
|
|
17537
|
+
if (!orgId) return "";
|
|
17538
|
+
return `?teamId=${encodeURIComponent(orgId)}`;
|
|
17539
|
+
}
|
|
17540
|
+
async function collectDistFiles(distDir) {
|
|
17541
|
+
const files = [];
|
|
17542
|
+
async function walk(dir) {
|
|
17543
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
17544
|
+
for (const entry of entries) {
|
|
17545
|
+
const fullPath = join3(dir, entry.name);
|
|
17546
|
+
if (entry.isDirectory()) {
|
|
17547
|
+
await walk(fullPath);
|
|
17548
|
+
} else {
|
|
17549
|
+
const content = await readFile(fullPath);
|
|
17550
|
+
const sha = createHash("sha1").update(content).digest("hex");
|
|
17551
|
+
const rel = relative3(distDir, fullPath).split("\\").join("/");
|
|
17552
|
+
files.push({
|
|
17553
|
+
relativePath: rel,
|
|
17554
|
+
content,
|
|
17555
|
+
sha,
|
|
17556
|
+
size: content.byteLength
|
|
17557
|
+
});
|
|
17558
|
+
}
|
|
17559
|
+
}
|
|
17560
|
+
}
|
|
17561
|
+
await walk(distDir);
|
|
17562
|
+
return files;
|
|
17563
|
+
}
|
|
17564
|
+
async function uploadFiles(files, token, orgId) {
|
|
17565
|
+
const q2 = teamQuery(orgId);
|
|
17566
|
+
for (let i = 0; i < files.length; i += UPLOAD_BATCH_SIZE) {
|
|
17567
|
+
const batch = files.slice(i, i + UPLOAD_BATCH_SIZE);
|
|
17568
|
+
await Promise.all(
|
|
17569
|
+
batch.map(async (file) => {
|
|
17570
|
+
const res = await fetch(`${VERCEL_API2}/v2/files${q2}`, {
|
|
17571
|
+
method: "POST",
|
|
17572
|
+
headers: apiHeaders(token, {
|
|
17573
|
+
"Content-Type": "application/octet-stream",
|
|
17574
|
+
"x-vercel-digest": file.sha,
|
|
17575
|
+
"Content-Length": String(file.size)
|
|
17576
|
+
}),
|
|
17577
|
+
body: new Uint8Array(file.content)
|
|
17578
|
+
});
|
|
17579
|
+
if (!res.ok) {
|
|
17580
|
+
const body = await res.text();
|
|
17581
|
+
throw formatVercelError(
|
|
17582
|
+
res.status,
|
|
17583
|
+
body,
|
|
17584
|
+
`upload file ${file.relativePath}`
|
|
17585
|
+
);
|
|
17586
|
+
}
|
|
17587
|
+
})
|
|
17588
|
+
);
|
|
17589
|
+
}
|
|
17590
|
+
}
|
|
17591
|
+
async function createDeployment(files, token, orgId, projectId, projectName) {
|
|
17592
|
+
const q2 = teamQuery(orgId);
|
|
17593
|
+
const body = {
|
|
17594
|
+
name: projectName,
|
|
17595
|
+
project: projectId,
|
|
17596
|
+
target: "production",
|
|
17597
|
+
files: files.map((f) => ({
|
|
17598
|
+
file: f.relativePath,
|
|
17599
|
+
sha: f.sha,
|
|
17600
|
+
size: f.size
|
|
17601
|
+
})),
|
|
17602
|
+
projectSettings: {
|
|
17603
|
+
buildCommand: "",
|
|
17604
|
+
installCommand: "",
|
|
17605
|
+
outputDirectory: "."
|
|
17606
|
+
}
|
|
17607
|
+
};
|
|
17608
|
+
const res = await fetch(`${VERCEL_API2}/v13/deployments${q2}`, {
|
|
17609
|
+
method: "POST",
|
|
17610
|
+
headers: apiHeaders(token, { "Content-Type": "application/json" }),
|
|
17611
|
+
body: JSON.stringify(body)
|
|
17612
|
+
});
|
|
17613
|
+
if (!res.ok) {
|
|
17614
|
+
const text = await res.text();
|
|
17615
|
+
throw formatVercelError(res.status, text, "create deployment");
|
|
17616
|
+
}
|
|
17617
|
+
return await res.json();
|
|
17618
|
+
}
|
|
17619
|
+
async function waitForReady(deploymentId, token, orgId) {
|
|
17620
|
+
const q2 = teamQuery(orgId);
|
|
17621
|
+
for (let attempt = 0; attempt < POLL_MAX_ATTEMPTS; attempt++) {
|
|
17622
|
+
const res = await fetch(
|
|
17623
|
+
`${VERCEL_API2}/v13/deployments/${deploymentId}${q2}`,
|
|
17624
|
+
{ headers: apiHeaders(token) }
|
|
17625
|
+
);
|
|
17626
|
+
if (!res.ok) {
|
|
17627
|
+
const text = await res.text();
|
|
17628
|
+
throw formatVercelError(res.status, text, "check deployment status");
|
|
17629
|
+
}
|
|
17630
|
+
const data = await res.json();
|
|
17631
|
+
if (data.readyState === "READY") return data;
|
|
17632
|
+
if (data.readyState === "ERROR") {
|
|
17633
|
+
throw new Error(
|
|
17634
|
+
`Deployment failed: ${data.errorMessage || "Unknown error"}`
|
|
17635
|
+
);
|
|
17636
|
+
}
|
|
17637
|
+
if (data.readyState === "CANCELED") {
|
|
17638
|
+
throw new Error("Deployment was canceled");
|
|
17639
|
+
}
|
|
17640
|
+
await new Promise((r2) => setTimeout(r2, POLL_INTERVAL_MS));
|
|
17641
|
+
}
|
|
17642
|
+
throw new Error("Deployment timed out (5+ minutes)");
|
|
17643
|
+
}
|
|
17644
|
+
async function deployVercelFrontend(appDir, _config) {
|
|
17645
|
+
const result = resolveVercelCredentials(appDir);
|
|
17646
|
+
if (result.missing) {
|
|
17647
|
+
const secretVars = result.missing.filter((v2) => v2 === "VERCEL_TOKEN");
|
|
17648
|
+
const appVars = result.missing.filter((v2) => v2 !== "VERCEL_TOKEN");
|
|
17649
|
+
const hints = [];
|
|
17650
|
+
if (secretVars.length > 0)
|
|
17651
|
+
hints.push("Add VERCEL_TOKEN to .dndev.secrets at project root.");
|
|
17652
|
+
if (appVars.length > 0)
|
|
17653
|
+
hints.push(`Add ${appVars.join(", ")} to apps/<app>/.env`);
|
|
17654
|
+
throw new Error(
|
|
17655
|
+
`Missing Vercel credentials: ${result.missing.join(", ")}
|
|
17656
|
+
` + hints.join("\n") + "\nSee guides/dndev/SETUP_VERCEL.md"
|
|
17657
|
+
);
|
|
17658
|
+
}
|
|
17659
|
+
const { token, orgId, projectId } = result.credentials;
|
|
17660
|
+
const distDir = joinPath(appDir, "dist");
|
|
17661
|
+
if (!pathExists(distDir)) {
|
|
17662
|
+
throw new Error(`dist/ not found at ${distDir}. Run build first.`);
|
|
17663
|
+
}
|
|
17664
|
+
log.debug("Using Vercel REST API (token-based, no CLI)");
|
|
17665
|
+
log.info(`Vercel org: ${orgId ?? "(personal account)"}`);
|
|
17666
|
+
log.info(`Vercel project: ${projectId}`);
|
|
17667
|
+
log.info(
|
|
17668
|
+
`Token: ${token.slice(0, 6)}...${token.slice(-4)} (${token.length} chars)`
|
|
17669
|
+
);
|
|
17670
|
+
log.info("Validating Vercel credentials...");
|
|
17671
|
+
const user = await validateToken(token);
|
|
17672
|
+
log.success(`Token valid (${user.username})`);
|
|
17673
|
+
const project = await validateProject(token, projectId, orgId);
|
|
17674
|
+
log.success(`Project accessible (${project.projectName})`);
|
|
17675
|
+
log.info("Collecting dist/ files...");
|
|
17676
|
+
const files = await collectDistFiles(distDir);
|
|
17677
|
+
if (files.length === 0) {
|
|
17678
|
+
throw new Error("dist/ is empty \u2014 nothing to deploy.");
|
|
17679
|
+
}
|
|
17680
|
+
log.info(`Found ${files.length} files`);
|
|
17681
|
+
log.info("Uploading files to Vercel...");
|
|
17682
|
+
await uploadFiles(files, token, orgId);
|
|
17683
|
+
log.success(`${files.length} files uploaded`);
|
|
17684
|
+
log.info("Creating production deployment...");
|
|
17685
|
+
const deployment = await createDeployment(
|
|
17686
|
+
files,
|
|
17687
|
+
token,
|
|
17688
|
+
orgId,
|
|
17689
|
+
projectId,
|
|
17690
|
+
project.projectName
|
|
17691
|
+
);
|
|
17692
|
+
log.info(`Deployment ${deployment.id} created, waiting...`);
|
|
17693
|
+
const ready = await waitForReady(deployment.id, token, orgId);
|
|
17694
|
+
const prodUrl = `https://${ready.url}`;
|
|
17695
|
+
log.success(`Production: ${prodUrl}`);
|
|
17696
|
+
if (ready.alias?.length) {
|
|
17697
|
+
log.info(`Aliases: ${ready.alias.join(", ")}`);
|
|
17698
|
+
}
|
|
17699
|
+
}
|
|
17700
|
+
|
|
17701
|
+
// packages/tooling/src/apps/deploy.ts
|
|
17702
|
+
init_cli_input();
|
|
17703
|
+
init_cli_output();
|
|
17704
|
+
init_cli_output();
|
|
17705
|
+
init_cli_tools();
|
|
17706
|
+
init_errors();
|
|
17707
|
+
init_pathResolver();
|
|
17708
|
+
|
|
17604
17709
|
// packages/tooling/src/utils/provider-detection.ts
|
|
17605
17710
|
init_utils();
|
|
17606
17711
|
init_pathResolver();
|
|
@@ -17685,12 +17790,6 @@ function detectProvider(appDir) {
|
|
|
17685
17790
|
}
|
|
17686
17791
|
|
|
17687
17792
|
// packages/tooling/src/apps/deploy.ts
|
|
17688
|
-
init_cli_input();
|
|
17689
|
-
init_cli_output();
|
|
17690
|
-
init_cli_output();
|
|
17691
|
-
init_cli_tools();
|
|
17692
|
-
init_errors();
|
|
17693
|
-
init_pathResolver();
|
|
17694
17793
|
async function main2(options = {}) {
|
|
17695
17794
|
const isStaging = options.staging ?? false;
|
|
17696
17795
|
const config = {
|