Skip to content

Commit a90acc8

Browse files
committed
chore: run prettier
1 parent f266538 commit a90acc8

3 files changed

Lines changed: 78 additions & 49 deletions

File tree

genMatrix.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const testFiles = [
1111
'versions.json',
1212
];
1313

14-
const areTestFilesChanged = (changedFiles) => changedFiles
15-
.some((file) => testFiles.includes(file));
14+
const areTestFilesChanged = (changedFiles) =>
15+
changedFiles.some((file) => testFiles.includes(file));
1616

1717
const getAffectedDockerfiles = (filesAdded, filesModified, filesRenamed) => {
1818
const files = [...filesAdded, ...filesModified, ...filesRenamed];

updateLib.js

Lines changed: 60 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const templateRepoMap = Object.freeze({
2323
});
2424

2525
// nodeVersions is sorted
26-
const getLatestNodeVersion = (nodeVersions, majorVersion) => nodeVersions
27-
.find((version) => version.startsWith(`${majorVersion}.`));
26+
const getLatestNodeVersion = (nodeVersions, majorVersion) =>
27+
nodeVersions.find((version) => version.startsWith(`${majorVersion}.`));
2828

2929
const getTemplate = (variant) => {
3030
if (variant.startsWith('alpine')) {
@@ -39,7 +39,10 @@ const getTemplate = (variant) => {
3939
};
4040

4141
const getDockerfileMetadata = (nodeVersions, file) => {
42-
const [nodeMajorVersion, variant] = path.dirname(file).split(path.sep).slice(-2);
42+
const [nodeMajorVersion, variant] = path
43+
.dirname(file)
44+
.split(path.sep)
45+
.slice(-2);
4346
const fileNodeVersion = getDockerfileNodeVersion(file);
4447

4548
return {
@@ -52,8 +55,8 @@ const getDockerfileMetadata = (nodeVersions, file) => {
5255
};
5356
};
5457

55-
const isDockerfileOutdated = ({ fileNodeVersion, latestVersion }) => fileNodeVersion
56-
!== latestVersion;
58+
const isDockerfileOutdated = ({ fileNodeVersion, latestVersion }) =>
59+
fileNodeVersion !== latestVersion;
5760

5861
const fetchLatestNodeVersions = async () => {
5962
const nodeDist = await fetch('https://nodejs.org/dist/index.json');
@@ -64,25 +67,27 @@ const fetchLatestNodeVersions = async () => {
6467
const findOutdated = async (updateAll) => {
6568
const nodeVersions = await fetchLatestNodeVersions();
6669

67-
const dockerfileMetadatas = getAllDockerfiles(__dirname)
68-
.map((file) => getDockerfileMetadata(nodeVersions, file));
70+
const dockerfileMetadatas = getAllDockerfiles(__dirname).map((file) =>
71+
getDockerfileMetadata(nodeVersions, file),
72+
);
6973

7074
return updateAll
7175
? dockerfileMetadatas
7276
: dockerfileMetadatas.filter(isDockerfileOutdated);
7377
};
7478

75-
const getKeys = (basename) => readFileSync(path.resolve(__dirname, 'keys', basename))
76-
.toString().trim().split('\n');
79+
const getKeys = (basename) =>
80+
readFileSync(path.resolve(__dirname, 'keys', basename))
81+
.toString()
82+
.trim()
83+
.split('\n');
7784

78-
const readTemplate = (template) => readFileSync(
79-
path.resolve(__dirname, templateFileMap[template]),
80-
).toString();
85+
const readTemplate = (template) =>
86+
readFileSync(path.resolve(__dirname, templateFileMap[template])).toString();
8187

8288
const getBaseImage = ({ template, variant }) => {
83-
const tag = template === templates.alpine
84-
? variant.replace(/alpine/, '')
85-
: variant;
89+
const tag =
90+
template === templates.alpine ? variant.replace(/alpine/, '') : variant;
8691

8792
return `${templateRepoMap[template]}:${tag}`;
8893
};
@@ -93,47 +98,65 @@ const formatTemplate = (nodeKeys, muslChecksum, base, metadata) => {
9398
const { latestVersion, template, nodeMajorVersion } = metadata;
9499
const baseImage = getBaseImage(metadata);
95100
const arches = versionJson[nodeMajorVersion].variants[metadata.variant];
96-
let initialFormat = base.replace(/^FROM.+$/m, `FROM ${baseImage}`)
101+
let initialFormat = base
102+
.replace(/^FROM.+$/m, `FROM ${baseImage}`)
97103
.replace(/^ENV NODE_VERSION=.+$/m, `ENV NODE_VERSION=${latestVersion}`)
98-
.replace(/^(\s*)"\${NODE_KEYS\[@]}".*$/m, formatKeys(nodeKeys))
104+
.replace(/^(\s*)"\${NODE_KEYS\[@]}".*$/m, formatKeys(nodeKeys));
99105

100106
if (parseInt(nodeMajorVersion, 10) >= 26) {
101107
initialFormat = initialFormat.replace(/ENV YARN_VERSION.*\*\n/s, '');
102108
}
103109

104110
if (template === templates.alpine) {
105111
let archString = '';
106-
if (arches.includes('amd64')) archString += `x86_64) ARCH='x64' CHECKSUM="${muslChecksum}" OPENSSL_ARCH=linux-x86_64;; \\\n `
107-
if (arches.includes('arm64v8')) archString += `aarch64) OPENSSL_ARCH=linux-aarch64;; \\\n `
108-
if (arches.includes('arm32v6') || arches.includes('arm32v7')) archString += `arm*) OPENSSL_ARCH=linux-armv4;; \\\n `
109-
if (arches.includes('ppc64le')) archString += `ppc64le) OPENSSL_ARCH=linux-ppc64le;; \\\n `
110-
if (arches.includes('s390x')) archString += `s390x) OPENSSL_ARCH=linux-s390x;; \\\n `
111-
archString += '*) ;; \\'
112-
113-
initialFormat = initialFormat.replace(/"\$\{ALPINE_ARCH\[@\]\}"/s, archString);
112+
if (arches.includes('amd64'))
113+
archString += `x86_64) ARCH='x64' CHECKSUM="${muslChecksum}" OPENSSL_ARCH=linux-x86_64;; \\\n `;
114+
if (arches.includes('arm64v8'))
115+
archString += `aarch64) OPENSSL_ARCH=linux-aarch64;; \\\n `;
116+
if (arches.includes('arm32v6') || arches.includes('arm32v7'))
117+
archString += `arm*) OPENSSL_ARCH=linux-armv4;; \\\n `;
118+
if (arches.includes('ppc64le'))
119+
archString += `ppc64le) OPENSSL_ARCH=linux-ppc64le;; \\\n `;
120+
if (arches.includes('s390x'))
121+
archString += `s390x) OPENSSL_ARCH=linux-s390x;; \\\n `;
122+
archString += '*) ;; \\';
123+
124+
initialFormat = initialFormat.replace(
125+
/"\$\{ALPINE_ARCH\[@\]\}"/s,
126+
archString,
127+
);
114128

115129
// Strip out rust and cargo packages for Node.js < 26
116130
if (parseInt(nodeMajorVersion, 10) < 26) {
117131
initialFormat = initialFormat.replace(/ rust \\.*cargo \\\s*/s, '');
118132
}
119133
} else if (template === templates.debianSlim) {
120134
let archString = '';
121-
if (arches.includes('amd64')) archString += `amd64) ARCH='x64' OPENSSL_ARCH='linux-x86_64';; \\\n `
122-
if (arches.includes('ppc64le')) archString += `ppc64el) ARCH='ppc64le' OPENSSL_ARCH='linux-ppc64le';; \\\n `
123-
if (arches.includes('s390x')) archString += `s390x) ARCH='s390x' OPENSSL_ARCH='linux*-s390x';; \\\n `
124-
if (arches.includes('arm64v8')) archString += `arm64) ARCH='arm64' OPENSSL_ARCH='linux-aarch64';; \\\n `
125-
if (arches.includes('arm32v7')) archString += `armhf) ARCH='armv7l' OPENSSL_ARCH='linux-armv4';; \\\n `
126-
archString += '*) echo "unsupported architecture"; exit 1 ;; \\'
135+
if (arches.includes('amd64'))
136+
archString += `amd64) ARCH='x64' OPENSSL_ARCH='linux-x86_64';; \\\n `;
137+
if (arches.includes('ppc64le'))
138+
archString += `ppc64el) ARCH='ppc64le' OPENSSL_ARCH='linux-ppc64le';; \\\n `;
139+
if (arches.includes('s390x'))
140+
archString += `s390x) ARCH='s390x' OPENSSL_ARCH='linux*-s390x';; \\\n `;
141+
if (arches.includes('arm64v8'))
142+
archString += `arm64) ARCH='arm64' OPENSSL_ARCH='linux-aarch64';; \\\n `;
143+
if (arches.includes('arm32v7'))
144+
archString += `armhf) ARCH='armv7l' OPENSSL_ARCH='linux-armv4';; \\\n `;
145+
archString += '*) echo "unsupported architecture"; exit 1 ;; \\';
127146

128147
initialFormat = initialFormat.replace(/"\$\{DEB_ARCH\[@\]\}"/s, archString);
129148
} else if (template === templates.debian) {
130149
let archString = '';
131-
if (arches.includes('amd64')) archString += `amd64) ARCH='x64';; \\\n `
132-
if (arches.includes('ppc64le')) archString += `ppc64el) ARCH='ppc64le';; \\\n `
133-
if (arches.includes('s390x')) archString += `s390x) ARCH='s390x';; \\\n `
134-
if (arches.includes('arm64v8')) archString += `arm64) ARCH='arm64';; \\\n `
135-
if (arches.includes('arm32v7')) archString += `armhf) ARCH='armv7l';; \\\n `
136-
archString += '*) echo "unsupported architecture"; exit 1 ;; \\'
150+
if (arches.includes('amd64')) archString += `amd64) ARCH='x64';; \\\n `;
151+
if (arches.includes('ppc64le'))
152+
archString += `ppc64el) ARCH='ppc64le';; \\\n `;
153+
if (arches.includes('s390x'))
154+
archString += `s390x) ARCH='s390x';; \\\n `;
155+
if (arches.includes('arm64v8'))
156+
archString += `arm64) ARCH='arm64';; \\\n `;
157+
if (arches.includes('arm32v7'))
158+
archString += `armhf) ARCH='armv7l';; \\\n `;
159+
archString += '*) echo "unsupported architecture"; exit 1 ;; \\';
137160

138161
initialFormat = initialFormat.replace(/"\$\{DEB_ARCH\[@\]\}"/s, archString);
139162
}

utils.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,27 @@ const { readFileSync, readdirSync } = require('fs');
55
const nodeDirRegex = /^\d+$/;
66

77
// Returns a list of the child directories in the given path
8-
const getChildDirectories = (parent) => readdirSync(parent, { withFileTypes: true })
9-
.filter((dirent) => dirent.isDirectory())
10-
.map(({ name }) => path.resolve(parent, name));
8+
const getChildDirectories = (parent) =>
9+
readdirSync(parent, { withFileTypes: true })
10+
.filter((dirent) => dirent.isDirectory())
11+
.map(({ name }) => path.resolve(parent, name));
1112

12-
const getNodeVersionDirs = (base) => getChildDirectories(base)
13-
.filter((childPath) => nodeDirRegex.test(path.basename(childPath)));
13+
const getNodeVersionDirs = (base) =>
14+
getChildDirectories(base).filter((childPath) =>
15+
nodeDirRegex.test(path.basename(childPath)),
16+
);
1417

1518
// Returns the paths of Dockerfiles that are at: base/*/Dockerfile
16-
const getDockerfilesInChildDirs = (base) => getChildDirectories(base)
17-
.map((childDir) => path.resolve(childDir, 'Dockerfile'));
19+
const getDockerfilesInChildDirs = (base) =>
20+
getChildDirectories(base).map((childDir) =>
21+
path.resolve(childDir, 'Dockerfile'),
22+
);
1823

19-
const getAllDockerfiles = (base) => getNodeVersionDirs(base).flatMap(getDockerfilesInChildDirs);
24+
const getAllDockerfiles = (base) =>
25+
getNodeVersionDirs(base).flatMap(getDockerfilesInChildDirs);
2026

21-
const getDockerfileNodeVersion = (file) => readFileSync(file, 'utf8')
22-
.match(/^ENV NODE_VERSION=(\d*\.*\d*\.\d*)/m)[1];
27+
const getDockerfileNodeVersion = (file) =>
28+
readFileSync(file, 'utf8').match(/^ENV NODE_VERSION=(\d*\.*\d*\.\d*)/m)[1];
2329

2430
module.exports = {
2531
getAllDockerfiles,

0 commit comments

Comments
 (0)