@@ -11,6 +11,7 @@ const ROOT = process.cwd();
1111const DEFAULT_CONFIG_PATH = path . join ( ROOT , "defaults" , "v8s-local-config.json" ) ;
1212const CUSTOM_CONFIG_PATH = path . join ( ROOT , "custom" , "v8s-local-config.json" ) ;
1313const HELPER_SOURCE_PATH = path . join ( ROOT , "scripts" , "v8s.sh" ) ;
14+ const LNK_SOURCE_PATH = path . join ( ROOT , "scripts" , "lnk" ) ;
1415const START_MARKER = "# >>> V8S >>>" ;
1516const END_MARKER = "# <<< V8S <<<" ;
1617
@@ -92,6 +93,10 @@ function mergeConfig(base, local) {
9293 ...( base . shell_helper || { } ) ,
9394 ...( local . shell_helper || { } )
9495 } ,
96+ link_cli : {
97+ ...( base . link_cli || { } ) ,
98+ ...( local . link_cli || { } )
99+ } ,
95100 registry : {
96101 ...( base . registry || { } ) ,
97102 ...( local . registry || { } )
@@ -118,6 +123,9 @@ async function promptConfig(config, args) {
118123 repository : {
119124 ...config . repository ,
120125 path : config . repository ?. path || ROOT
126+ } ,
127+ link_cli : {
128+ ...config . link_cli
121129 }
122130 } ;
123131 }
@@ -131,6 +139,9 @@ async function promptConfig(config, args) {
131139 ...config . shell_helper ,
132140 enabled
133141 } ,
142+ link_cli : {
143+ ...config . link_cli
144+ } ,
134145 registry : {
135146 ...config . registry
136147 } ,
@@ -142,6 +153,7 @@ async function promptConfig(config, args) {
142153 if ( ! enabled ) return next ;
143154
144155 next . shell_helper . install_path = await question ( rl , "Shell helper install path" , next . shell_helper . install_path ) ;
156+ next . link_cli . install_path = await question ( rl , "lnk CLI install path" , next . link_cli . install_path ) ;
145157 next . shell_helper . rc_file = await question ( rl , "Shell rc file to update" , next . shell_helper . rc_file ) ;
146158 next . registry . local_path = await question ( rl , "Local registry path" , next . registry . local_path ) ;
147159 next . repository . path = await question ( rl , "Local repository path" , next . repository . path || ROOT ) ;
@@ -182,23 +194,27 @@ function shellQuote(value) {
182194
183195function installHelper ( config , args ) {
184196 if ( config . shell_helper ?. enabled !== true ) {
185- console . log ( "Shell helper disabled; local config written only." ) ;
197+ console . log ( "Shell helper disabled; installing lnk CLI only." ) ;
198+ installLnkCli ( config , args ) ;
186199 return ;
187200 }
188201
189202 const helperTarget = expandLocalPath ( config . shell_helper . install_path ) ;
203+ const lnkTarget = expandLocalPath ( config . link_cli ?. install_path || "$XDG_CONFIG_HOME/bin/lnk" ) ;
190204 const rcFile = expandLocalPath ( config . shell_helper . rc_file ) ;
191205 const registryPath = expandLocalPath ( config . registry ?. local_path || "~/.v8s.json" ) ;
192206 const repoPath = expandLocalPath ( config . repository ?. path || ROOT ) ;
193207
194208 if ( args . dryRun ) {
195209 console . log ( `[dry-run] would copy scripts/v8s.sh to ${ helperTarget } ` ) ;
210+ console . log ( `[dry-run] would copy scripts/lnk to ${ lnkTarget } ` ) ;
196211 console . log ( `[dry-run] would update ${ rcFile } ` ) ;
197212 return ;
198213 }
199214
200215 fs . mkdirSync ( path . dirname ( helperTarget ) , { recursive : true } ) ;
201216 fs . copyFileSync ( HELPER_SOURCE_PATH , helperTarget ) ;
217+ copyExecutable ( LNK_SOURCE_PATH , lnkTarget ) ;
202218
203219 const block = [
204220 START_MARKER ,
@@ -218,9 +234,28 @@ function installHelper(config, args) {
218234
219235 fs . writeFileSync ( rcFile , next ) ;
220236 console . log ( `Installed V8S shell helper to ${ helperTarget } ` ) ;
237+ console . log ( `Installed lnk CLI to ${ lnkTarget } ` ) ;
221238 console . log ( `Updated ${ rcFile } ` ) ;
222239}
223240
241+ function installLnkCli ( config , args ) {
242+ const lnkTarget = expandLocalPath ( config . link_cli ?. install_path || "$XDG_CONFIG_HOME/bin/lnk" ) ;
243+
244+ if ( args . dryRun ) {
245+ console . log ( `[dry-run] would copy scripts/lnk to ${ lnkTarget } ` ) ;
246+ return ;
247+ }
248+
249+ copyExecutable ( LNK_SOURCE_PATH , lnkTarget ) ;
250+ console . log ( `Installed lnk CLI to ${ lnkTarget } ` ) ;
251+ }
252+
253+ function copyExecutable ( sourcePath , targetPath ) {
254+ fs . mkdirSync ( path . dirname ( targetPath ) , { recursive : true } ) ;
255+ fs . copyFileSync ( sourcePath , targetPath ) ;
256+ fs . chmodSync ( targetPath , 0o755 ) ;
257+ }
258+
224259function escapeRegExp ( value ) {
225260 return value . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, "\\$&" ) ;
226261}
0 commit comments