mirror of
https://code.forgejo.org/actions/setup-node.git
synced 2025-06-10 06:01:11 +00:00
Updates
This commit is contained in:
parent
9bb7038a07
commit
2b9c956517
6 changed files with 113 additions and 0 deletions
33
lib/authutil.js
Normal file
33
lib/authutil.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
"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 });
|
||||
const fs = __importStar(require("fs"));
|
||||
const os = __importStar(require("os"));
|
||||
const path = __importStar(require("path"));
|
||||
function configAuth(registryUrl) {
|
||||
let npmrc = path.resolve(process.cwd(), '.npmrc');
|
||||
let yarnrc = path.resolve(process.cwd(), '.yarnrc');
|
||||
writeRegistryToFile(registryUrl, npmrc, 'NPM_TOKEN');
|
||||
writeRegistryToFile(registryUrl, yarnrc, 'YARN_TOKEN');
|
||||
}
|
||||
exports.configAuth = configAuth;
|
||||
function writeRegistryToFile(registryUrl, fileLocation, authTokenName) {
|
||||
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 + registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${' + authTokenName + '}';
|
||||
fs.writeFileSync(fileLocation, newContents);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue