@@ -53,24 +53,48 @@ async function runNgCommand(commandArguments, commandOptions, commandConfig) {
5353}
5454
5555function localPackageExists ( packageName ) {
56- // Check local node_modules first
5756 const nodeModulesPath = path . join ( process . cwd ( ) , 'node_modules' ) ;
5857 if ( fs . existsSync ( nodeModulesPath ) ) {
5958 const packageJsonPath = path . join ( nodeModulesPath , packageName , 'package.json' ) ;
6059 if ( fs . existsSync ( packageJsonPath ) ) {
6160 return true ;
6261 }
6362 }
63+ return false ;
64+ }
65+
66+ function getLocalCollectionPath ( packageName ) {
67+ const nodeModulesPath = path . join ( process . cwd ( ) , 'node_modules' , packageName , 'src' , 'collection.json' ) ;
68+ if ( fs . existsSync ( nodeModulesPath ) ) {
69+ return nodeModulesPath ;
70+ }
71+ return null ;
72+ }
73+
74+ function getCollectionPath ( packageName ) {
75+ const localPath = getLocalCollectionPath ( packageName ) ;
76+ if ( localPath ) {
77+ return localPath ;
78+ }
6479
65- // Check if globally installed by trying to resolve the package
6680 try {
67- require . resolve ( `${ packageName } /package.json` ) ;
81+ const packageJsonPath = require . resolve ( `${ packageName } /package.json` ) ;
82+ const collectionPath = path . join ( path . dirname ( packageJsonPath ) , 'src' , 'collection.json' ) ;
83+ if ( fs . existsSync ( collectionPath ) ) {
84+ return collectionPath ;
85+ }
86+ } catch ( e ) { }
87+
88+ return null ;
89+ }
90+
91+ function schematicsCliExists ( ) {
92+ try {
93+ require . resolve ( '@angular-devkit/schematics-cli/package.json' ) ;
6894 return true ;
6995 } catch ( e ) {
70- // Package not found globally
96+ return false ;
7197 }
72-
73- return false ;
7498}
7599
76100const hasSutableNgCli = async ( ) => {
@@ -165,33 +189,22 @@ const addView = (viewName, options) => {
165189
166190const migrateConfigComponents = async ( options = { } ) => {
167191 const collectionName = 'devextreme-schematics' ;
192+ const collectionPath = getCollectionPath ( collectionName ) ;
168193
169- // Check if devextreme-schematics is installed
170- if ( ! localPackageExists ( collectionName ) ) {
194+ if ( ! collectionPath ) {
171195 const prompts = require ( 'prompts' ) ;
172196
173197 console . log ( `\nThe '${ collectionName } ' package is required to run this command.` ) ;
174198
175199 const response = await prompts ( {
176200 type : 'confirm' ,
177201 name : 'install' ,
178- message : `Would you like to install '${ collectionName } ' now ?` ,
202+ message : `Download '${ collectionName } @ ${ schematicsVersion } ' temporarily to run the migration ?` ,
179203 initial : true
180204 } ) ;
181205
182206 if ( ! response . install ) {
183- console . log ( 'Migration cancelled. Please install devextreme-schematics manually:' ) ;
184- console . log ( `npm install -g ${ collectionName } @${ schematicsVersion } ` ) ;
185- process . exit ( 1 ) ;
186- }
187-
188- console . log ( `Installing ${ collectionName } @${ schematicsVersion } ...` ) ;
189- try {
190- await runCommand ( 'npm' , [ 'install' , '-g' , `${ collectionName } @${ schematicsVersion } ` ] , { stdio : 'inherit' } ) ;
191- console . log ( 'Installation completed successfully.' ) ;
192- } catch ( error ) {
193- console . error ( 'Failed to install devextreme-schematics. Please install manually:' ) ;
194- console . error ( `npm install -g ${ collectionName } @${ schematicsVersion } ` ) ;
207+ console . log ( 'Migration cancelled. You can install devextreme-schematics locally or globally and rerun the command.' ) ;
195208 process . exit ( 1 ) ;
196209 }
197210 }
@@ -200,14 +213,22 @@ const migrateConfigComponents = async(options = {}) => {
200213 ...options
201214 } ;
202215
203- if ( schematicOptions . include && typeof schematicOptions . include === 'string' ) {
204- schematicOptions . include = schematicOptions . include . split ( ',' ) . map ( s => s . trim ( ) ) ;
216+ const hasSchematicsCli = schematicsCliExists ( ) ;
217+ const commandArguments = [ '--yes' ] ;
218+
219+ if ( ! hasSchematicsCli ) {
220+ commandArguments . push ( '-p' , '@angular-devkit/schematics-cli' ) ;
205221 }
206- if ( schematicOptions . scriptInclude && typeof schematicOptions . scriptInclude === 'string' ) {
207- schematicOptions . scriptInclude = schematicOptions . scriptInclude . split ( ',' ) . map ( s => s . trim ( ) ) ;
222+
223+ if ( ! collectionPath ) {
224+ commandArguments . push ( '-p' , `${ collectionName } @${ schematicsVersion } ` ) ;
208225 }
209226
210- const commandArguments = [ 'schematics' , `${ collectionName } :migrate-config-components` ] ;
227+ const collectionSpecifier = collectionPath
228+ ? `${ collectionPath . replace ( / \\ / g, '/' ) } :migrate-config-components`
229+ : `${ collectionName } :migrate-config-components` ;
230+
231+ commandArguments . push ( 'schematics' , collectionSpecifier ) ;
211232
212233 const { [ depsVersionTagOptionName ] : _ , ...optionsToArguments } = schematicOptions ; // eslint-disable-line no-unused-vars
213234 for ( let option in optionsToArguments ) {
0 commit comments