This repository was archived by the owner on Mar 30, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +20
-46
lines changed Expand file tree Collapse file tree 3 files changed +20
-46
lines changed Original file line number Diff line number Diff line change @@ -158,8 +158,7 @@ describe("generator-biojs-webcomponents:app - Upgrade an existing component by i
158
158
} ) ;
159
159
160
160
describe ( "generator-biojs-webcomponents:app - Upgrade an existing component by installing component from npm package" , ( ) => {
161
- it ( "installs the latest component from its npm package if user enters a valid version" , async ( ) => {
162
- jest . setTimeout ( 10000 ) ; // Increases timeout for this test
161
+ it ( "throws an error if version entered does not exist" , async ( ) => {
163
162
let res = await validators . checkVersionAndInstallComponent ( "latest" , {
164
163
packageNameToInstallComponent : "is-odd"
165
164
} ) ;
Original file line number Diff line number Diff line change @@ -321,6 +321,7 @@ module.exports = class extends Generator {
321
321
if ( props . importFrom === upgradeComponentPrompts [ 0 ] . choices [ 0 ] ) {
322
322
return this . prompt ( installNpmPackagePrompts ) . then ( props => {
323
323
// If user chooses to go back and choose source of importing file again
324
+ this . npmProps = props ;
324
325
if ( props . changeImportSourceFromNpmPackage ) {
325
326
return recursivePromptExecution (
326
327
props . changeImportSourceFromNpmPackage
@@ -469,6 +470,21 @@ module.exports = class extends Generator {
469
470
this . destinationRoot ( "./" ) ;
470
471
}
471
472
473
+ installingNPMPackage ( ) {
474
+ if (
475
+ this . npmProps &&
476
+ this . npmProps . packageNameToInstallComponent &&
477
+ this . npmProps . checkVersionAndInstallComponent
478
+ ) {
479
+ this . npmInstall (
480
+ this . npmProps . packageNameToInstallComponent +
481
+ "@" +
482
+ this . npmProps . checkVersionAndInstallComponent ,
483
+ { "save-dev" : true }
484
+ ) ;
485
+ }
486
+ }
487
+
472
488
install ( ) {
473
489
this . installDependencies ( {
474
490
npm : true ,
Original file line number Diff line number Diff line change @@ -100,51 +100,13 @@ validators.version = async function(props, answers) {
100
100
validators . checkVersionAndInstallComponent = async function ( props , answers ) {
101
101
if ( props ) {
102
102
if ( props === "latest" ) {
103
- let res = await executeCommand (
104
- "cd " +
105
- projectDirectory +
106
- " && npm i " +
107
- answers . packageNameToInstallComponent +
108
- "@" +
109
- props +
110
- " --save-exact" ,
111
- "checkVersionAndInstallComponent"
112
- )
113
- . then ( ( ) => true )
114
- . catch ( err => {
115
- return chalk . red (
116
- `Oops! We encountered an error. Please see below for the more details - \n${ chalk . yellow (
117
- err
118
- ) } `
119
- ) ;
120
- } ) ;
121
- return res ;
103
+ return true ;
122
104
}
123
105
124
106
let command =
125
107
"npm view " + answers . packageNameToInstallComponent + "@" + props ;
126
108
let res = await executeCommand ( command , "version" )
127
- . then ( async ( ) => {
128
- let res = await executeCommand (
129
- "cd " +
130
- projectDirectory +
131
- " && npm i " +
132
- answers . packageNameToInstallComponent +
133
- "@" +
134
- props +
135
- " --save-exact" ,
136
- "checkVersionAndInstallComponent"
137
- )
138
- . then ( ( ) => true )
139
- . catch ( err => {
140
- return chalk . red (
141
- `Oops! We encountered an error. Please see below for the more details - \n${ chalk . yellow (
142
- err
143
- ) } `
144
- ) ;
145
- } ) ;
146
- return res ;
147
- } )
109
+ . then ( ( ) => true )
148
110
. catch ( ( ) =>
149
111
chalk . red (
150
112
"Sorry, the version - " +
@@ -305,10 +267,7 @@ function executeCommand(command, type) {
305
267
// The command couldn't be executed
306
268
spinner . stop ( ) ;
307
269
reject ( err ) ;
308
- } else if (
309
- type === "version" ||
310
- type === "checkVersionAndInstallComponent"
311
- ) {
270
+ } else if ( type === "version" ) {
312
271
// Command successfully executed
313
272
if ( stdout ) {
314
273
spinner . stop ( ) ;
You can’t perform that action at this time.
0 commit comments