Skip to content

Commit c07f2f0

Browse files
committed
Consolidate
1 parent acdeb19 commit c07f2f0

3 files changed

Lines changed: 31 additions & 54 deletions

File tree

build/check-image-tags.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@
99

1010
import * as fs from 'fs';
1111
import * as path from 'path';
12+
import { IMAGE_REF_PATTERN, TEMPLATE_OPTION_PATTERN, TemplateJson, findFiles } from './utils';
1213

1314
const RED = '\x1b[0;31m';
1415
const GREEN = '\x1b[0;32m';
1516
const YELLOW = '\x1b[0;33m';
1617
const NC = '\x1b[0m';
1718

18-
const MCR_PREFIX = 'mcr.microsoft.com/devcontainers/';
19-
const IMAGE_REF_PATTERN = /mcr\.microsoft\.com\/devcontainers\/([^"]+)/g;
20-
const TEMPLATE_OPTION_PATTERN = /\$\{templateOption:([^}]+)\}/;
21-
2219
interface ImageManifest {
2320
version: string;
2421
variants?: string[];
@@ -28,13 +25,6 @@ interface ImageManifest {
2825
};
2926
}
3027

31-
interface TemplateJson {
32-
options?: Record<string, {
33-
default?: string;
34-
proposals?: string[];
35-
}>;
36-
}
37-
3828
interface TemplateTag {
3929
templateName: string;
4030
relFile: string;
@@ -110,22 +100,6 @@ function computeImageTags(imagesRepo: string): Set<string> {
110100

111101
// --- Step 2: Compute all tags that templates would produce ---
112102

113-
function findFiles(dir: string, names: string[]): string[] {
114-
const results: string[] = [];
115-
function walk(d: string) {
116-
for (const entry of fs.readdirSync(d, { withFileTypes: true })) {
117-
const full = path.join(d, entry.name);
118-
if (entry.isDirectory()) {
119-
walk(full);
120-
} else if (names.includes(entry.name) || names.some(n => n.startsWith('*.') && entry.name.endsWith(n.slice(1)))) {
121-
results.push(full);
122-
}
123-
}
124-
}
125-
walk(dir);
126-
return results;
127-
}
128-
129103
function computeTemplateTags(templatesDir: string): TemplateTag[] {
130104
const results: TemplateTag[] = [];
131105

build/list-template-images.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,7 @@
77

88
import * as fs from 'fs';
99
import * as path from 'path';
10-
11-
const MCR_PREFIX = 'mcr.microsoft.com/devcontainers/';
12-
const IMAGE_REF_PATTERN = /mcr\.microsoft\.com\/devcontainers\/([^"]+)/g;
13-
const TEMPLATE_OPTION_PATTERN = /\$\{templateOption:([^}]+)\}/;
14-
15-
interface TemplateJson {
16-
options?: Record<string, {
17-
default?: string;
18-
proposals?: string[];
19-
}>;
20-
}
21-
22-
function findFiles(dir: string, names: string[]): string[] {
23-
const results: string[] = [];
24-
function walk(d: string) {
25-
for (const entry of fs.readdirSync(d, { withFileTypes: true })) {
26-
const full = path.join(d, entry.name);
27-
if (entry.isDirectory()) {
28-
walk(full);
29-
} else if (names.includes(entry.name) || names.some(n => n.startsWith('*.') && entry.name.endsWith(n.slice(1)))) {
30-
results.push(full);
31-
}
32-
}
33-
}
34-
walk(dir);
35-
return results;
36-
}
10+
import { MCR_PREFIX, IMAGE_REF_PATTERN, TEMPLATE_OPTION_PATTERN, TemplateJson, findFiles } from './utils';
3711

3812
function main() {
3913
const templatesDir = path.resolve(__dirname, '..', 'src');

build/utils.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as fs from 'fs';
2+
import * as path from 'path';
3+
4+
export const MCR_PREFIX = 'mcr.microsoft.com/devcontainers/';
5+
export const IMAGE_REF_PATTERN = /mcr\.microsoft\.com\/devcontainers\/([^"]+)/g;
6+
export const TEMPLATE_OPTION_PATTERN = /\$\{templateOption:([^}]+)\}/;
7+
8+
export interface TemplateJson {
9+
options?: Record<string, {
10+
default?: string;
11+
proposals?: string[];
12+
}>;
13+
}
14+
15+
export function findFiles(dir: string, names: string[]): string[] {
16+
const results: string[] = [];
17+
function walk(d: string) {
18+
for (const entry of fs.readdirSync(d, { withFileTypes: true })) {
19+
const full = path.join(d, entry.name);
20+
if (entry.isDirectory()) {
21+
walk(full);
22+
} else if (names.includes(entry.name) || names.some(n => n.startsWith('*.') && entry.name.endsWith(n.slice(1)))) {
23+
results.push(full);
24+
}
25+
}
26+
}
27+
walk(dir);
28+
return results;
29+
}

0 commit comments

Comments
 (0)