Update
parent
2b9c956517
commit
409b7dfb5b
|
@ -1,4 +1,12 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
var __importStar = (this && this.__importStar) || function (mod) {
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
if (mod && mod.__esModule) return mod;
|
if (mod && mod.__esModule) return mod;
|
||||||
var result = {};
|
var result = {};
|
||||||
|
@ -7,27 +15,26 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const fs = __importStar(require("fs"));
|
|
||||||
const os = __importStar(require("os"));
|
|
||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
|
const exec = __importStar(require("@actions/exec"));
|
||||||
function configAuth(registryUrl) {
|
function configAuth(registryUrl) {
|
||||||
let npmrc = path.resolve(process.cwd(), '.npmrc');
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
let yarnrc = path.resolve(process.cwd(), '.yarnrc');
|
let npmrc = path.resolve(process.cwd(), '.npmrc');
|
||||||
writeRegistryToFile(registryUrl, npmrc, 'NPM_TOKEN');
|
let yarnrc = path.resolve(process.cwd(), '.yarnrc');
|
||||||
writeRegistryToFile(registryUrl, yarnrc, 'YARN_TOKEN');
|
writeRegistryToFile(registryUrl, 'npm', 'NPM_TOKEN');
|
||||||
|
writeRegistryToFile(registryUrl, 'yarn', 'YARN_TOKEN');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
exports.configAuth = configAuth;
|
exports.configAuth = configAuth;
|
||||||
function writeRegistryToFile(registryUrl, fileLocation, authTokenName) {
|
function writeRegistryToFile(registryUrl, packageManager, authTokenName) {
|
||||||
let newContents = '';
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
if (fs.existsSync(fileLocation)) {
|
yield exec.exec(`${packageManager} config set registry=${registryUrl}`);
|
||||||
const curContents = fs.readFileSync(fileLocation, 'utf8');
|
yield exec.exec(`${packageManager} config set always-auth=true`);
|
||||||
curContents.split(os.EOL).forEach((line) => {
|
yield exec.exec(packageManager +
|
||||||
// Add current contents unless they are setting the registry
|
' config set ' +
|
||||||
if (!line.startsWith('registry')) {
|
registryUrl.replace(/(^\w+:|^)/, '') +
|
||||||
newContents += line + os.EOL;
|
':_authToken ${' +
|
||||||
}
|
authTokenName +
|
||||||
});
|
'}');
|
||||||
}
|
});
|
||||||
newContents += 'registry=' + registryUrl + os.EOL + 'always-auth=true' + os.EOL + registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${' + authTokenName + '}';
|
|
||||||
fs.writeFileSync(fileLocation, newContents);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,39 +1,29 @@
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as exec from '@actions/exec';
|
||||||
|
|
||||||
export function configAuth(registryUrl: string) {
|
export async function configAuth(registryUrl: string) {
|
||||||
let npmrc: string = path.resolve(process.cwd(), '.npmrc');
|
let npmrc: string = path.resolve(process.cwd(), '.npmrc');
|
||||||
let yarnrc: string = path.resolve(process.cwd(), '.yarnrc');
|
let yarnrc: string = path.resolve(process.cwd(), '.yarnrc');
|
||||||
|
|
||||||
writeRegistryToFile(registryUrl, npmrc, 'NPM_TOKEN');
|
writeRegistryToFile(registryUrl, 'npm', 'NPM_TOKEN');
|
||||||
writeRegistryToFile(registryUrl, yarnrc, 'YARN_TOKEN');
|
writeRegistryToFile(registryUrl, 'yarn', 'YARN_TOKEN');
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeRegistryToFile(
|
async function writeRegistryToFile(
|
||||||
registryUrl: string,
|
registryUrl: string,
|
||||||
fileLocation: string,
|
packageManager: string,
|
||||||
authTokenName: string
|
authTokenName: string
|
||||||
) {
|
) {
|
||||||
let newContents = '';
|
await exec.exec(`${packageManager} config set registry=${registryUrl}`);
|
||||||
if (fs.existsSync(fileLocation)) {
|
await exec.exec(`${packageManager} config set always-auth=true`);
|
||||||
const curContents = fs.readFileSync(fileLocation, 'utf8');
|
await exec.exec(
|
||||||
curContents.split(os.EOL).forEach((line: string) => {
|
packageManager +
|
||||||
// Add current contents unless they are setting the registry
|
' config set ' +
|
||||||
if (!line.startsWith('registry')) {
|
registryUrl.replace(/(^\w+:|^)/, '') +
|
||||||
newContents += line + os.EOL;
|
':_authToken ${' +
|
||||||
}
|
authTokenName +
|
||||||
});
|
'}'
|
||||||
}
|
);
|
||||||
newContents +=
|
|
||||||
'registry=' +
|
|
||||||
registryUrl +
|
|
||||||
os.EOL +
|
|
||||||
'always-auth=true' +
|
|
||||||
os.EOL +
|
|
||||||
registryUrl.replace(/(^\w+:|^)/, '') +
|
|
||||||
':_authToken=${' +
|
|
||||||
authTokenName +
|
|
||||||
'}';
|
|
||||||
fs.writeFileSync(fileLocation, newContents);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue