1
+ const walkSync = require ( 'walk-sync' ) ;
2
+ const { readFileSync, writeFileSync, existsSync, readdirSync } = require ( 'fs' ) ;
3
+ const { expect } = require ( 'chai' ) ;
4
+ const { basename} = require ( 'path' ) ;
5
+
6
+ const projectVersionPairs = require ( './helpers/project-versions' ) ;
7
+
8
+ const projects = {
9
+ 'ember' : projectVersionPairs . filter ( item => item [ 0 ] === 'ember' ) . map ( item => item [ 1 ] ) ,
10
+ 'ember-data' : projectVersionPairs . filter ( item => item [ 0 ] === 'ember-data' ) . map ( item => item [ 1 ] )
11
+ } ;
12
+
13
+
14
+ const folders = [ ] ;
15
+
16
+ // we only need the latest patch from a minor version
17
+ describe ( 'Prevent adding all patch versions of a minor' , function ( ) {
18
+
19
+ describe ( 'json-docs folders' , function ( ) {
20
+ for ( let project in projects ) {
21
+ const projectVersions = projects [ project ] ;
22
+ const jsonDocsFolders = readdirSync ( `json-docs/${ project } ` ) . filter ( item => item !== 'projects' ) ;
23
+
24
+ for ( let jsonDocsFolder of jsonDocsFolders ) {
25
+ it ( `json-docs folder should only have the latest patch: ${ project } ${ jsonDocsFolder } ` , function ( ) {
26
+ if ( ! projectVersions . includes ( jsonDocsFolder ) ) {
27
+ folders . push ( `json-docs/${ project } /${ jsonDocsFolder } ` ) ;
28
+ throw new Error ( "this is not the only patch version" ) ;
29
+ }
30
+ } )
31
+ }
32
+ }
33
+ } )
34
+
35
+ describe ( 's3-docs folders' , function ( ) {
36
+ for ( let project in projects ) {
37
+ const projectVersions = projects [ project ] ;
38
+ const s3Files = walkSync ( 's3-docs' ) . filter ( item => item . endsWith ( `${ project } -docs.json` ) ) ;
39
+
40
+ for ( let s3File of s3Files ) {
41
+ it ( `s3-docs file should only have the latest patch: ${ project } ${ s3File } ` , function ( ) {
42
+ let [ version ] = s3File . split ( '/' ) ;
43
+ version = version . replace ( / ^ v / , '' ) ;
44
+
45
+ if ( ! projectVersions . includes ( version ) ) {
46
+ folders . push ( `s3-docs/v${ version } /${ project } -docs.json` ) ;
47
+ throw new Error ( "this is not the only patch version" ) ;
48
+ }
49
+ } )
50
+ }
51
+ }
52
+ } )
53
+
54
+ describe ( 'rev-index files' , function ( ) {
55
+ for ( let project in projects ) {
56
+ const projectVersions = projects [ project ] ;
57
+ const revIndexFiles = readdirSync ( `rev-index` ) . filter ( item => item . match ( new RegExp ( `^${ project } -\\d` ) ) ) ;
58
+
59
+ for ( let revIndexFile of revIndexFiles ) {
60
+ it ( `rev-index file sould only have the latest patch: ${ project } ${ revIndexFile } ` , function ( ) {
61
+ const match = revIndexFile . match ( / [ \w - ] + - ( \d + \. \d + \. \d + ) .j s o n / )
62
+ if ( match && ! projectVersions . includes ( match [ 1 ] ) ) {
63
+
64
+ folders . push ( `rev-index/${ revIndexFile } ` ) ;
65
+ throw new Error ( "this is not the only patch version" ) ;
66
+ }
67
+ } )
68
+ }
69
+ }
70
+ } )
71
+
72
+
73
+
74
+ // if you want to bulk delete the duplicate files you can uncomment this
75
+ // and then run `cat unused-folders.txt | xargs rm -r` to delete them
76
+ after ( function ( ) {
77
+ writeFileSync ( 'unused-folders.txt' , folders . join ( '\n' ) ) ;
78
+ } )
79
+ } )
0 commit comments