Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nsisodiya
Last active September 30, 2020 06:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nsisodiya/aea76052762ff1c764d41f0fcf0bc57e to your computer and use it in GitHub Desktop.
Save nsisodiya/aea76052762ff1c764d41f0fcf0bc57e to your computer and use it in GitHub Desktop.
./system/npm/fix-version-lock.js
const fs = require('fs');
const YAML = require('yamljs');
const replaceFirstLineOfFile = require('file-firstline-replace');
const pkgJson = require('../../package.json');
var filename = 'Dockerfile';
var newHeader = `FROM node:${pkgJson.nodeVersionLock} as builder\n`;
replaceFirstLineOfFile(filename, newHeader, function (error) {
if (error) {
throw error;
}
console.warn('Dockerfile updated');
});
// Replace in gitlab ci file.
var gitlabCiYml = fs.readFileSync('.github/workflows/node.js.yml', 'utf8');
// parse YAML string
var gitlabCiJSON = YAML.parse(gitlabCiYml);
gitlabCiJSON.jobs.build.strategy.matrix['node-version'][0] = pkgJson.nodeVersionLock;
var spaces = 4;
var gitlabCiYmlUpdated = YAML.stringify(gitlabCiJSON, spaces);
fs.writeFileSync('.github/workflows/node.js.yml', gitlabCiYmlUpdated, 'utf8');
console.warn('github CI file updated');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment