@@ -7,7 +7,7 @@ import { defineCommand, runCommand } from 'citty'
7
7
import { join , resolve , relative } from 'pathe'
8
8
import { execa } from 'execa'
9
9
import { setupDotenv } from 'c12'
10
- import { $api , fetchUser , selectTeam , selectProject , projectPath , fetchProject , linkProject , gitInfo } from '../utils/index.mjs'
10
+ import { $api , fetchUser , selectTeam , selectProject , projectPath , fetchProject , linkProject , gitInfo , determineEnvironment } from '../utils/index.mjs'
11
11
import { getStorage , getPathsToDeploy , getFile , uploadAssetsToCloudflare , uploadWorkersAssetsToCloudflare , isMetaPath , isWorkerMetaPath , isServerPath , isWorkerServerPath , getPublicFiles , getWorkerPublicFiles } from '../utils/deploy.mjs'
12
12
import { createMigrationsTable , fetchRemoteMigrations , queryDatabase } from '../utils/database.mjs'
13
13
import login from './login.mjs'
@@ -40,6 +40,11 @@ export default defineCommand({
40
40
description : 'Force the current deployment as preview.' ,
41
41
default : false
42
42
} ,
43
+ env : {
44
+ type : 'string' ,
45
+ description : 'Force the environment of the current deployment. Available for Workers projects only.' ,
46
+ default : ''
47
+ } ,
43
48
dotenv : {
44
49
type : 'string' ,
45
50
description : 'Point to another .env file to load, relative to the root directory.' ,
@@ -92,6 +97,7 @@ export default defineCommand({
92
97
// Default to main branch
93
98
git . branch = git . branch || 'main'
94
99
let deployEnv = git . branch === linkedProject . productionBranch ? 'production' : 'preview'
100
+
95
101
if ( args . production ) {
96
102
git . branch = linkedProject . productionBranch
97
103
deployEnv = 'production'
@@ -100,21 +106,20 @@ export default defineCommand({
100
106
git . branch += '-preview'
101
107
}
102
108
deployEnv = 'preview'
109
+ } else if ( linkedProject . type === 'worker' && args . env ) {
110
+ deployEnv = args . env
111
+ } else if ( linkedProject . type === 'worker' && git . branch !== linkedProject . productionBranch ) {
112
+ deployEnv = await determineEnvironment ( linkedProject . teamSlug , linkedProject . slug , git . branch )
103
113
}
104
- const deployEnvColored = deployEnv === 'production' ? colors . greenBright ( deployEnv ) : colors . yellowBright ( deployEnv )
114
+
115
+ const deployEnvColored = deployEnv === 'production'
116
+ ? colors . greenBright ( deployEnv )
117
+ : deployEnv === 'preview'
118
+ ? colors . yellowBright ( deployEnv )
119
+ : colors . blueBright ( deployEnv ) // additional environments
105
120
consola . success ( `Connected to ${ colors . blueBright ( linkedProject . teamSlug ) } team.` )
106
121
consola . success ( `Linked to ${ colors . blueBright ( linkedProject . slug ) } project.` )
107
122
108
- if ( linkedProject . type === 'worker' && deployEnv === 'preview' ) {
109
- consola . warn ( 'Currently NuxtHub on Workers (BETA) does not support preview environments.' )
110
- const shouldDeploy = await confirm ( {
111
- message : `Deploy ${ colors . blueBright ( projectPath ( ) ) } to production instead?`
112
- } )
113
- if ( ! shouldDeploy || isCancel ( shouldDeploy ) ) {
114
- return consola . log ( 'Cancelled.' )
115
- }
116
- }
117
-
118
123
// #region Build
119
124
if ( args . build ) {
120
125
consola . info ( 'Building the Nuxt project...' )
@@ -125,7 +130,15 @@ export default defineCommand({
125
130
if ( args . dotenv ) {
126
131
nuxiBuildArgs . push ( `--dotenv=${ args . dotenv } ` )
127
132
}
128
- await execa ( { stdio : 'inherit' , preferLocal : true , cwd, extendEnv : false , env : { } } ) `nuxi build ${ nuxiBuildArgs } `
133
+ await execa ( {
134
+ stdio : 'inherit' ,
135
+ preferLocal : true ,
136
+ cwd,
137
+ extendEnv : false ,
138
+ env : {
139
+ REMOTE_PROJECT_TYPE : linkedProject . type === 'worker' ? 'workers' : 'pages'
140
+ }
141
+ } ) `nuxi build ${ nuxiBuildArgs } `
129
142
. catch ( ( err ) => {
130
143
if ( err . code === 'ENOENT' ) {
131
144
consola . error ( '`nuxt` is not installed, please make sure that you are inside a Nuxt project.' )
0 commit comments