1+ // add-vsx-to-monorepo.js
2+ // Run this in your existing monorepo to add the VSCode extension package
3+ const { execSync } = require ( 'child_process' ) ;
4+ const fs = require ( 'fs' ) ;
5+
6+ function run ( cmd , options = { } ) {
7+ console . log ( `$ ${ cmd } ` ) ;
8+ try {
9+ return execSync ( cmd , {
10+ stdio : options . silent ? 'pipe' : 'inherit' ,
11+ encoding : 'utf-8' ,
12+ ...options
13+ } ) ;
14+ } catch ( error ) {
15+ if ( ! options . allowFail ) {
16+ throw error ;
17+ }
18+ }
19+ }
20+
21+ function writeJSON ( file , data ) {
22+ fs . writeFileSync ( file , JSON . stringify ( data , null , 2 ) + '\n' ) ;
23+ }
24+
25+ console . log ( '=' . repeat ( 70 ) ) ;
26+ console . log ( 'ADDING VSCODE EXTENSION TO MONOREPO' ) ;
27+ console . log ( '=' . repeat ( 70 ) ) ;
28+
29+ // Step 1: Import vsx repo with history
30+ console . log ( '\n[1/5] Adding VSX repository as remote...' ) ;
31+ run ( 'git remote add vsx-origin ../lightning-flow-scanner-vsx' ) ;
32+ run ( 'git fetch vsx-origin' ) ;
33+
34+ console . log ( '\n[2/5] Merging VSX repository with full history...' ) ;
35+ run ( 'git merge -s ours --no-commit --allow-unrelated-histories vsx-origin/main' ) ;
36+ run ( 'git read-tree --prefix=packages/vsx/ -u vsx-origin/main' ) ;
37+ run ( 'git commit -m "Import VSX repository with full history into packages/vsx"' ) ;
38+ run ( 'git remote remove vsx-origin' ) ;
39+
40+ // Step 2: Update vsx package.json
41+ console . log ( '\n[3/5] Updating VSX package.json...' ) ;
42+ const vsxPkgPath = 'packages/vsx/package.json' ;
43+ if ( fs . existsSync ( vsxPkgPath ) ) {
44+ const vsxPkg = JSON . parse ( fs . readFileSync ( vsxPkgPath , 'utf-8' ) ) ;
45+
46+ // Update to use workspace dependency
47+ if ( vsxPkg . dependencies && vsxPkg . dependencies [ '@flow-scanner/lightning-flow-scanner-core' ] ) {
48+ vsxPkg . dependencies [ '@flow-scanner/lightning-flow-scanner-core' ] = 'workspace:*' ;
49+ }
50+
51+ // Update repository
52+ vsxPkg . repository = {
53+ type : "git" ,
54+ url : "git+https://github.com/Flow-Scanner/lightning-flow-scanner.git" ,
55+ directory : "packages/vsx"
56+ } ;
57+
58+ writeJSON ( vsxPkgPath , vsxPkg ) ;
59+ console . log ( '✓ Updated VSX package.json' ) ;
60+ }
61+
62+ // Step 3: Update .gitignore to allow vsx dist/
63+ console . log ( '\n[4/5] Updating .gitignore...' ) ;
64+ let gitignore = '' ;
65+ if ( fs . existsSync ( '.gitignore' ) ) {
66+ gitignore = fs . readFileSync ( '.gitignore' , 'utf8' ) ;
67+ }
68+
69+ if ( ! gitignore . includes ( '!packages/vsx/dist/' ) ) {
70+ gitignore += '\n# Allow VSCode extension dist (required for extension)\n!packages/vsx/dist/\n' ;
71+ fs . writeFileSync ( '.gitignore' , gitignore ) ;
72+ console . log ( '✓ Updated .gitignore to allow vsx dist/' ) ;
73+ }
74+
75+ // Step 4: Update root package.json scripts
76+ console . log ( '\n[5/5] Updating root package.json scripts...' ) ;
77+ const rootPkg = JSON . parse ( fs . readFileSync ( 'package.json' , 'utf-8' ) ) ;
78+ rootPkg . scripts = {
79+ ...rootPkg . scripts ,
80+ 'build:vsx' : 'pnpm --filter=lightning-flow-scanner-vsx run build' ,
81+ 'build:vsx:package' : 'pnpm --filter=lightning-flow-scanner-vsx run build:vsx' ,
82+ 'watch:vsx' : 'pnpm --filter=lightning-flow-scanner-vsx run watch'
83+ } ;
84+ writeJSON ( 'package.json' , rootPkg ) ;
85+
86+ run ( 'git add .' ) ;
87+ run ( 'git commit -m "Add VSCode extension package to monorepo"' ) ;
88+
89+ console . log ( '\n' + '=' . repeat ( 70 ) ) ;
90+ console . log ( '✅ VSCODE EXTENSION ADDED TO MONOREPO!' ) ;
91+ console . log ( '=' . repeat ( 70 ) ) ;
92+ console . log ( '\nNext steps:' ) ;
93+ console . log ( ' 1. Build core: pnpm build:core' ) ;
94+ console . log ( ' 2. Build VSX: pnpm build:vsx' ) ;
95+ console . log ( ' 3. Commit dist/: git add packages/vsx/dist && git commit -m "build: vsx dist"' ) ;
96+ console . log ( ' 4. Package extension: pnpm build:vsx:package' ) ;
97+ console . log ( '\nThe .vsix file will be in packages/vsx/' ) ;
98+ console . log ( 'Users can install it from VS Code Marketplace or manually.' ) ;
99+ console . log ( '' ) ;
0 commit comments