11import { readFileSync } from "node:fs" ;
2- import { join } from "node:path" ;
2+ import { join , resolve } from "node:path" ;
3+ import { fileURLToPath } from "node:url" ;
34
45import { ROOT } from "./lib.mjs" ;
56import {
@@ -8,64 +9,79 @@ import {
89} from "./release-validation.mjs" ;
910import { collectStandaloneContentViolations } from "./standalone-content.mjs" ;
1011
11- const inputViolations = [ ] ;
12- const read = ( name ) => {
13- try {
14- return readFileSync ( join ( ROOT , name ) , "utf8" ) ;
15- } catch ( error ) {
16- const detail = error instanceof Error ? error . message : String ( error ) ;
17- inputViolations . push ( `${ name } could not be read: ${ detail } ` ) ;
18- return undefined ;
12+ export function collectPublicPreviewGateViolations ( root = ROOT ) {
13+ const inputViolations = [ ] ;
14+ const read = ( name ) => {
15+ try {
16+ return readFileSync ( join ( root , name ) , "utf8" ) ;
17+ } catch ( error ) {
18+ const detail = error instanceof Error ? error . message : String ( error ) ;
19+ inputViolations . push ( `${ name } could not be read: ${ detail } ` ) ;
20+ return undefined ;
21+ }
22+ } ;
23+
24+ let sourceManifest ;
25+ const packageText = read ( "package.json" ) ;
26+ if ( packageText !== undefined ) {
27+ try {
28+ sourceManifest = JSON . parse ( packageText ) ;
29+ } catch ( error ) {
30+ const detail = error instanceof Error ? error . message : String ( error ) ;
31+ inputViolations . push ( `package.json could not be parsed: ${ detail } ` ) ;
32+ }
1933 }
20- } ;
2134
22- let sourceManifest ;
23- const packageText = read ( "package.json" ) ;
24- if ( packageText !== undefined ) {
35+ const contentViolations = collectPublicPreviewViolations ( {
36+ documents : {
37+ agents : read ( "AGENTS.md" ) ,
38+ architecture : read ( "ARCHITECTURE.md" ) ,
39+ changelog : read ( "CHANGELOG.md" ) ,
40+ compatibility : read ( "COMPATIBILITY.md" ) ,
41+ conduct : read ( "CODE_OF_CONDUCT.md" ) ,
42+ contributing : read ( "CONTRIBUTING.md" ) ,
43+ license : read ( "LICENSE" ) ,
44+ readme : read ( "README.md" ) ,
45+ releasing : read ( "RELEASING.md" ) ,
46+ roadmap : read ( "ROADMAP.md" ) ,
47+ security : read ( "SECURITY.md" ) ,
48+ support : read ( "SUPPORT.md" ) ,
49+ } ,
50+ sourceManifest,
51+ } ) ;
52+
53+ const standaloneContentViolations = [ ] ;
2554 try {
26- sourceManifest = JSON . parse ( packageText ) ;
55+ standaloneContentViolations . push (
56+ ...collectStandaloneContentViolations ( root ) ,
57+ ) ;
2758 } catch ( error ) {
2859 const detail = error instanceof Error ? error . message : String ( error ) ;
29- inputViolations . push ( `package.json could not be parsed: ${ detail } ` ) ;
60+ standaloneContentViolations . push (
61+ `standalone content could not be checked: ${ detail } ` ,
62+ ) ;
3063 }
31- }
3264
33- const violations = collectPublicPreviewViolations ( {
34- documents : {
35- agents : read ( "AGENTS.md" ) ,
36- architecture : read ( "ARCHITECTURE.md" ) ,
37- changelog : read ( "CHANGELOG.md" ) ,
38- compatibility : read ( "COMPATIBILITY.md" ) ,
39- conduct : read ( "CODE_OF_CONDUCT.md" ) ,
40- contributing : read ( "CONTRIBUTING.md" ) ,
41- license : read ( "LICENSE" ) ,
42- readme : read ( "README.md" ) ,
43- releasing : read ( "RELEASING.md" ) ,
44- roadmap : read ( "ROADMAP.md" ) ,
45- security : read ( "SECURITY.md" ) ,
46- support : read ( "SUPPORT.md" ) ,
47- } ,
48- sourceManifest,
49- } ) ;
65+ return [
66+ ...inputViolations ,
67+ ...contentViolations ,
68+ ...standaloneContentViolations ,
69+ ] ;
70+ }
5071
51- const standaloneContentViolations = [ ] ;
52- try {
53- standaloneContentViolations . push ( ... collectStandaloneContentViolations ( ROOT ) ) ;
54- } catch ( error ) {
55- const detail = error instanceof Error ? error . message : String ( error ) ;
56- standaloneContentViolations . push (
57- `standalone content could not be checked: ${ detail } ` ,
58- ) ;
72+ function main ( ) {
73+ const violations = collectPublicPreviewGateViolations ( ) ;
74+ if ( violations . length > 0 ) {
75+ console . error ( formatPublicPreviewViolations ( violations ) ) ;
76+ process . exitCode = 1 ;
77+ } else {
78+ console . log ( "Public Preview content gate passed." ) ;
79+ }
5980}
6081
61- const allViolations = [
62- ...inputViolations ,
63- ...violations ,
64- ...standaloneContentViolations ,
65- ] ;
66- if ( allViolations . length > 0 ) {
67- console . error ( formatPublicPreviewViolations ( allViolations ) ) ;
68- process . exitCode = 1 ;
69- } else {
70- console . log ( "Public Preview content gate passed." ) ;
82+ if (
83+ process . argv [ 1 ] !== undefined &&
84+ resolve ( process . argv [ 1 ] ) === fileURLToPath ( import . meta. url )
85+ ) {
86+ main ( ) ;
7187}
0 commit comments