1- import { ux } from '@oclif/core' ;
1+ import { Flags , ux } from '@oclif/core' ;
22import { cpSync , existsSync , mkdirSync } from 'node:fs' ;
33import { dirname , join } from 'node:path' ;
44import { fileURLToPath } from 'node:url' ;
55
66import { InstanceCommand , PowerSyncCommand , SERVICE_FILENAME } from '@powersync/cli-core' ;
77
8- const __dirname = dirname ( fileURLToPath ( import . meta . url ) ) ;
8+ import { writeVscodeSettingsForYamlEnv } from '../../api/write-vscode-settings-for-yaml-env.js' ;
99
10+ const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
1011const TEMPLATES_DIR = join ( __dirname , '..' , '..' , '..' , 'templates' ) ;
1112
1213export default class InitSelfHosted extends PowerSyncCommand {
1314 static description =
1415 'Copy a self-hosted template into a config directory (default powersync/). Configure service.yaml with your self-hosted instance details.' ;
1516 static summary = 'Scaffold a PowerSync self-hosted config directory from a template.' ;
1617 static flags = {
17- ...InstanceCommand . flags
18+ ...InstanceCommand . flags ,
19+ vscode : Flags . boolean ( {
20+ description : 'Configure the workspace with .vscode settings for YAML custom tags (!env).' ,
21+ default : false
22+ } )
1823 } ;
1924
2025 async run ( ) : Promise < void > {
2126 const { flags } = await this . parse ( InitSelfHosted ) ;
22- const { directory } = flags ;
27+ const { directory, vscode } = flags ;
2328 const targetDir = this . resolveProjectDir ( flags ) ;
2429
2530 if ( existsSync ( targetDir ) ) {
@@ -38,22 +43,29 @@ export default class InitSelfHosted extends PowerSyncCommand {
3843 mkdirSync ( targetDir , { recursive : true } ) ;
3944 cpSync ( templatePath , targetDir , { recursive : true } ) ;
4045
46+ if ( vscode ) {
47+ writeVscodeSettingsForYamlEnv ( process . cwd ( ) ) ;
48+ }
49+
4150 const instructions = [
4251 'Self Hosted projects currently require external configuration for starting and deploying.' ,
4352 `Configure the ${ SERVICE_FILENAME } file with your self-hosted instance details.` ,
4453 `See the Docker topic, with ${ ux . colorize ( 'blue' , 'powersync docker --help' ) } for local development services.` ,
4554 'Please refer to the PowerSync Self-Hosted documentation for more information.'
4655 ] . join ( '\n' ) ;
4756
48- this . log (
49- [
50- ux . colorize ( 'green' , 'Created PowerSync self-hosted project!' ) ,
51- '' ,
52- ux . colorize ( 'gray' , 'Configuration files are located in:' ) ,
53- ux . colorize ( 'cyan' , targetDir ) ,
54- '' ,
55- ux . colorize ( 'yellow' , instructions )
56- ] . join ( '\n' )
57- ) ;
57+ const lines = [
58+ ux . colorize ( 'green' , 'Created PowerSync self-hosted project!' ) ,
59+ '' ,
60+ ux . colorize ( 'cyan' , 'Configuration files are located in:' ) ,
61+ ux . colorize ( 'gray' , targetDir ) ,
62+ '' ,
63+ ux . colorize ( 'yellow' , instructions )
64+ ] ;
65+ if ( vscode ) {
66+ lines . splice ( 5 , 0 , ux . colorize ( 'gray' , 'Added .vscode/settings.json for YAML !env tag support.' ) ) ;
67+ lines . splice ( 6 , 0 , '' ) ;
68+ }
69+ this . log ( lines . join ( '\n' ) ) ;
5870 }
5971}
0 commit comments