@@ -9,10 +9,13 @@ import {
99 YAML_SERVICE_SCHEMA ,
1010 YAML_SYNC_RULES_SCHEMA
1111} from '@powersync/cli-core' ;
12- import { cpSync , existsSync , mkdirSync , readFileSync , writeFileSync } from 'node:fs' ;
12+ import { BaseServiceSelfHostedConfig } from '@powersync/cli-schemas' ;
13+ import { copyFileSync , existsSync , mkdirSync , readFileSync , writeFileSync } from 'node:fs' ;
1314import { dirname , join } from 'node:path' ;
1415import { fileURLToPath } from 'node:url' ;
1516
17+ import { buildServiceYaml } from '../../utils/build-service-yaml.js' ;
18+
1619const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
1720const TEMPLATES_DIR = join ( __dirname , '..' , '..' , '..' , 'templates' ) ;
1821
@@ -48,13 +51,38 @@ export default class InitSelfHosted extends InstanceCommand {
4851 }
4952
5053 mkdirSync ( targetDir , { recursive : true } ) ;
51- cpSync ( templatePath , targetDir , { recursive : true } ) ;
54+ copyFileSync ( join ( templatePath , CLI_FILENAME ) , join ( targetDir , CLI_FILENAME ) ) ;
55+ copyFileSync ( join ( templatePath , SYNC_FILENAME ) , join ( targetDir , SYNC_FILENAME ) ) ;
5256
5357 const servicePath = join ( targetDir , SERVICE_FILENAME ) ;
5458 const syncPath = join ( targetDir , SYNC_FILENAME ) ;
5559 const cliPath = join ( targetDir , CLI_FILENAME ) ;
5660
57- writeFileSync ( servicePath , `${ YAML_SERVICE_SCHEMA } \n\n${ readFileSync ( servicePath , 'utf8' ) } ` ) ;
61+ const serviceTemplatePath = join ( templatePath , 'service.template.yaml' ) ;
62+ const renderedServiceYaml = buildServiceYaml ( {
63+ baseConfig : {
64+ _type : 'self-hosted' ,
65+ api : {
66+ tokens : [ 'use_a_better_token_in_production' ]
67+ } ,
68+ replication : {
69+ connections : [ ]
70+ } ,
71+ // This is just used as a placeholder
72+ storage : { } as BaseServiceSelfHostedConfig [ 'storage' ] ,
73+ sync_config : {
74+ path : 'sync-config.yaml'
75+ } ,
76+ telemetry : {
77+ disable_telemetry_sharing : false
78+ }
79+ } ,
80+ schemaHeader : YAML_SERVICE_SCHEMA ,
81+ templatePath : serviceTemplatePath ,
82+ templateReplacementPaths : [ [ 'storage' ] ]
83+ } ) ;
84+
85+ writeFileSync ( servicePath , renderedServiceYaml ) ;
5886 writeFileSync ( syncPath , `${ YAML_SYNC_RULES_SCHEMA } \n\n${ readFileSync ( syncPath , 'utf8' ) } ` ) ;
5987 writeFileSync ( cliPath , `${ YAML_CLI_SCHEMA } \n\n${ readFileSync ( cliPath , 'utf8' ) } ` ) ;
6088
0 commit comments