| 
									
										
										
										
											2019-08-05 11:35:39 -04:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | var __importStar = (this && this.__importStar) || function (mod) { | 
					
						
							|  |  |  |     if (mod && mod.__esModule) return mod; | 
					
						
							|  |  |  |     var result = {}; | 
					
						
							|  |  |  |     if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | 
					
						
							|  |  |  |     result["default"] = mod; | 
					
						
							|  |  |  |     return result; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | Object.defineProperty(exports, "__esModule", { value: true }); | 
					
						
							| 
									
										
										
										
											2019-08-05 11:51:04 -04:00
										 |  |  | const fs = __importStar(require("fs")); | 
					
						
							|  |  |  | const os = __importStar(require("os")); | 
					
						
							| 
									
										
										
										
											2019-08-05 11:35:39 -04:00
										 |  |  | const path = __importStar(require("path")); | 
					
						
							| 
									
										
										
										
											2019-08-05 11:51:04 -04:00
										 |  |  | const core = __importStar(require("@actions/core")); | 
					
						
							| 
									
										
										
										
											2019-08-05 11:35:39 -04:00
										 |  |  | function configAuth(registryUrl) { | 
					
						
							| 
									
										
										
										
											2019-08-05 11:51:04 -04:00
										 |  |  |     let npmrc = path.resolve(process.cwd(), '.npmrc'); | 
					
						
							|  |  |  |     let yarnrc = path.resolve(process.cwd(), '.yarnrc'); | 
					
						
							| 
									
										
										
										
											2019-08-05 11:57:53 -04:00
										 |  |  |     writeRegistryToFile(registryUrl, npmrc); | 
					
						
							|  |  |  |     writeRegistryToFile(registryUrl, yarnrc); | 
					
						
							| 
									
										
										
										
											2019-08-05 11:35:39 -04:00
										 |  |  | } | 
					
						
							|  |  |  | exports.configAuth = configAuth; | 
					
						
							| 
									
										
										
										
											2019-08-05 11:57:53 -04:00
										 |  |  | function writeRegistryToFile(registryUrl, fileLocation) { | 
					
						
							| 
									
										
										
										
											2019-08-05 11:51:04 -04:00
										 |  |  |     core.debug(`Setting auth in ${fileLocation}`); | 
					
						
							|  |  |  |     let newContents = ''; | 
					
						
							|  |  |  |     if (fs.existsSync(fileLocation)) { | 
					
						
							|  |  |  |         const curContents = fs.readFileSync(fileLocation, 'utf8'); | 
					
						
							|  |  |  |         curContents.split(os.EOL).forEach((line) => { | 
					
						
							|  |  |  |             // Add current contents unless they are setting the registry
 | 
					
						
							|  |  |  |             if (!line.startsWith('registry')) { | 
					
						
							|  |  |  |                 newContents += line + os.EOL; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     newContents += | 
					
						
							|  |  |  |         'registry=' + | 
					
						
							|  |  |  |             registryUrl + | 
					
						
							|  |  |  |             os.EOL + | 
					
						
							|  |  |  |             'always-auth=true' + | 
					
						
							|  |  |  |             os.EOL + | 
					
						
							| 
									
										
										
										
											2019-08-05 11:44:04 -04:00
										 |  |  |             registryUrl.replace(/(^\w+:|^)/, '') + | 
					
						
							| 
									
										
										
										
											2019-08-05 11:57:53 -04:00
										 |  |  |             ':_authToken=${NODE_AUTH_TOKEN}'; | 
					
						
							| 
									
										
										
										
											2019-08-05 11:51:04 -04:00
										 |  |  |     fs.writeFileSync(fileLocation, newContents); | 
					
						
							| 
									
										
										
										
											2019-08-05 11:35:39 -04:00
										 |  |  | } |