@@ -7,7 +7,7 @@ import { defineCommand, runCommand } from 'citty'
77import { join , resolve , relative } from 'pathe'
88import { execa } from 'execa'
99import { 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'
1111import { getStorage , getPathsToDeploy , getFile , uploadAssetsToCloudflare , uploadWorkersAssetsToCloudflare , isMetaPath , isWorkerMetaPath , isServerPath , isWorkerServerPath , getPublicFiles , getWorkerPublicFiles } from '../utils/deploy.mjs'
1212import { createMigrationsTable , fetchRemoteMigrations , queryDatabase } from '../utils/database.mjs'
1313import login from './login.mjs'
@@ -40,6 +40,11 @@ export default defineCommand({
4040 description : 'Force the current deployment as preview.' ,
4141 default : false
4242 } ,
43+ env : {
44+ type : 'string' ,
45+ description : 'Force the environment of the current deployment. Available for Workers projects only.' ,
46+ default : ''
47+ } ,
4348 dotenv : {
4449 type : 'string' ,
4550 description : 'Point to another .env file to load, relative to the root directory.' ,
@@ -92,6 +97,7 @@ export default defineCommand({
9297 // Default to main branch
9398 git . branch = git . branch || 'main'
9499 let deployEnv = git . branch === linkedProject . productionBranch ? 'production' : 'preview'
100+
95101 if ( args . production ) {
96102 git . branch = linkedProject . productionBranch
97103 deployEnv = 'production'
@@ -100,21 +106,20 @@ export default defineCommand({
100106 git . branch += '-preview'
101107 }
102108 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 )
103113 }
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
105120 consola . success ( `Connected to ${ colors . blueBright ( linkedProject . teamSlug ) } team.` )
106121 consola . success ( `Linked to ${ colors . blueBright ( linkedProject . slug ) } project.` )
107122
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-
118123 // #region Build
119124 if ( args . build ) {
120125 consola . info ( 'Building the Nuxt project...' )
@@ -125,7 +130,15 @@ export default defineCommand({
125130 if ( args . dotenv ) {
126131 nuxiBuildArgs . push ( `--dotenv=${ args . dotenv } ` )
127132 }
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 } `
129142 . catch ( ( err ) => {
130143 if ( err . code === 'ENOENT' ) {
131144 consola . error ( '`nuxt` is not installed, please make sure that you are inside a Nuxt project.' )
0 commit comments