Debian Codegraph @

extensions/VisualEditor/build/checkModules.js

raw symbols SCIP
1 'use strict';
2
3 const path = require( 'path' );
4
5 const extensionJson = require( '../extension.json' );
6 const modulesJson = require( '../lib/ve/build/modules.json' );
7
8 const ignored = [
9 'node_modules/',
10 'lib/',
11 'dist/',
12 'src/ve.track.js', // Re-implemented in MW
13 'tests/ve.qunit.local.js',
14 // Standalone / Demos
15 'demos/',
16 'src/init/sa/',
17 'tests/init/ve.init.sa.Platform.test.js',
18 'src/ui/dialogs/ve.ui.DiffDialog.js',
19 // Rebaser
20 'rebaser/',
21 // TODO: Put these is a folder
22 'tests/ve.FakePeer.test.js',
23 'tests/dm/ve.dm.TransactionSquasher.test.js',
24 'tests/dm/ve.dm.RebaseServer.test.js',
25 'tests/dm/ve.dm.FakeMongo.js',
26 'tests/dm/ve.dm.FakeSocket.js',
27 'tests/dm/ve.dm.DocumentStore.test.js',
28 'tests/dm/ve.dm.TransportServer.test.js'
29 ];
30
31 const unusedIgnores = new Set( ignored );
32
33 function addFilesToSet( files, set, basePath = '' ) {
34 if ( Array.isArray( files ) ) {
35 files.forEach( ( file ) => set.add( path.join( basePath, file.file || file ) ) );
36 } else if ( typeof files === 'string' ) {
37 set.add( path.join( basePath, files ) );
38 }
39 }
40
41 function isIgnored( filePath ) {
42 return ignored.some( ( ignorePath ) => {
43 const fullIgnorePath = path.join( 'lib/ve', ignorePath );
44 const match = filePath === fullIgnorePath || filePath.startsWith( fullIgnorePath );
45 if ( match ) {
46 unusedIgnores.delete( ignorePath );
47 }
48 return match;
49 } );
50 }
51
52 function addModulesToSet( modules, set, basePath = '' ) {
53 Object.values( modules ).forEach( ( module ) => {
54 [
55 'scripts',
56 'debugScripts',
57 'styles'
58 ].forEach( ( property ) => {
59 if ( module[ property ] ) {
60 addFilesToSet( module[ property ], set, basePath );
61 }
62 } );
63 if ( module.skinStyles ) {
64 Object.values( module.skinStyles ).forEach( ( files ) => {
65 addFilesToSet( files, set, basePath );
66 } );
67 }
68 } );
69 }
70
71 function checkFiles() {
72 const extensionFiles = new Set();
73 addModulesToSet( extensionJson.ResourceModules, extensionFiles );
74 addModulesToSet( { QUnitTestModule: extensionJson.QUnitTestModule }, extensionFiles );
75
76 const modulesFiles = new Set();
77 addModulesToSet( modulesJson, modulesFiles, 'lib/ve' );
78
79 const missingFiles = Array.from( modulesFiles ).filter( ( file ) => !extensionFiles.has( file ) && !isIgnored( file ) );
80
81 if ( unusedIgnores.size ) {
82 console.warn(
83 'Unused ignore path(s) in checkModules.js:\n\n' +
84 Array.from( unusedIgnores ).map( ( ignore ) => `* ${ ignore }\n` ).join( '' )
85 );
86 }
87
88 if ( missingFiles.length ) {
89 console.error(
90 `${ missingFiles.length } file(s) from lib/ve/modules.json are missing from extension.json:\n\n` +
91 missingFiles.map( ( file ) => `* ${ file }\n` ).join( '' ) +
92 '\nIf any of these files are not required, add them to the ignore list in build/checkModules.js.'
93 );
94 // eslint-disable-next-line n/no-process-exit
95 process.exit( 1 );
96 } else {
97 console.log( 'No missing files.' );
98 }
99 }
100
101 checkFiles();