-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathconfirm-build.js
More file actions
157 lines (136 loc) · 4.91 KB
/
confirm-build.js
File metadata and controls
157 lines (136 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env node
/**
* Copyright 2025 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import glob from 'fast-glob';
import 'colors';
import { version } from '@spectrum-web-components/base/src/version.js';
const __dirname = dirname(fileURLToPath(import.meta.url));
const rootDir = path.join(__dirname, '..');
async function verifyCustomElementsJson() {
// Components that don't need their own custom-elements.json manifest
const customElementsIgnoreList = new Set([
'packages/modal',
'packages/iconset',
'packages/clear-button',
'packages/close-button',
]);
const packages = glob.sync('packages/*/', {
onlyDirectories: true,
cwd: rootDir,
});
const checks = packages.map(async (pkg) => {
const pkgPath = pkg.replace(/\/$/, '');
if (customElementsIgnoreList.has(pkgPath)) {
return;
}
const customElementsPath = path.join(
rootDir,
pkg,
'custom-elements.json'
);
if (!fs.existsSync(customElementsPath)) {
throw new Error(`Missing custom-elements.json in ${pkg}`);
}
});
return Promise.all(checks);
}
function verifyVersionSync() {
let basePackageJson;
try {
basePackageJson = JSON.parse(
fs.readFileSync(
path.join(rootDir, 'tools/base/package.json'),
'utf8'
)
);
} catch (error) {
throw new Error('Failed to read tools/base/package.json');
}
if (version !== basePackageJson.version) {
throw new Error(
`Version mismatch: version.js (${version}) does not match tools/base/package.json (${basePackageJson.version})`
);
}
}
async function verifyBuildArtifacts() {
const packages = glob.sync('packages/*/', {
onlyDirectories: true,
cwd: rootDir,
});
const requiredFilesIgnoreList = new Set([
'packages/clear-button', // extends button
'packages/close-button', // extends button
'packages/search-button', // extends button
'packages/icons-ui', // extends icon
'packages/icons-workflow', // extends icon
'packages/iconset', // extends icon
'packages/modal', // extends dialog
]);
// Required files for each package
const requiredFiles = [
['src/index.js', 'main compiled JS file'],
['src/index.dev.js', 'dev build file'],
['src/*.d.ts', 'TypeScript declaration files'],
['sp-*.js', 'component definition file'],
['sp-*.dev.js', 'dev component definition file'],
['sp-*.d.ts', 'component definition type file'],
];
const checks = packages.map(async (pkg) => {
const pkgPath = pkg.replace(/\/$/, '');
const srcPath = path.join(rootDir, pkg, 'src');
if (!fs.existsSync(srcPath)) {
throw new Error(`Missing src directory in ${pkg}`);
}
// Check if src directory is empty
const srcFiles = fs.readdirSync(srcPath);
if (srcFiles.length === 0) {
throw new Error(`src directory is empty in ${pkg}`);
}
if (requiredFilesIgnoreList.has(pkgPath)) {
return;
}
// Verify all required files exist for this package
for (const [filePattern, description] of requiredFiles) {
const pattern = path.join(rootDir, pkg, filePattern);
const files = glob.sync(pattern);
if (files.length === 0) {
throw new Error(
`Missing ${description} in ${pkg} (pattern: ${filePattern})`
);
}
}
});
await Promise.all(checks);
}
async function main() {
try {
console.log('Verifying custom-elements.json files...'.cyan);
await verifyCustomElementsJson();
console.log('Verifying version synchronization...'.cyan);
verifyVersionSync();
console.log('Verifying build artifacts...'.cyan);
await verifyBuildArtifacts();
console.log('All build artifacts verified successfully'.green.bold);
process.exit(0);
} catch (error) {
console.error(
'Build artifact verification failed:'.red.bold,
error.message.red
);
process.exit(1);
}
}
main();