PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.7.2
Defender Security – Malware Scanner, Login Security & Firewall v5.7.2
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / extra / shared-tasks / files.js

files.js in Defender Security – Malware Scanner, Login Security & Firewall 5.7.2, at extra/shared-tasks/files.js

173 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 module.exports = function (grunt) {
2 'use strict';
3
4 var _lists = ['all', 'free', 'full', 'dev', 'temp', 'submodules', 'clean', 'external'],
5 _raw_lists = {
6 all: ['**/*'],
7 free: [],
8 full: ['readme.txt', 'screenshot*.png'],
9 dev: [
10 'bin/**/*', 'tests/**/*', 'logs/**/*', 'doc/**/*', 'docs/**/*', // Dev directories
11 'Gruntfile.js', 'GruntFile.js', 'gulpfile.js', 'Gulpfile.js', 'package.json', 'package-lock.json', 'README.md', // Dev files
12 'phpunit.xml', 'phpcs.ruleset.xml', // Dev files
13 '.git*', 'bitbucket-pipelines.yml' // Repo-specific stuff
14 ],
15 temp: [
16 '.tags*', 'tags*',
17 'dist/**/*', '*.zip', 'builds/**/*', // Build artifacts
18 '.sass-cache/**/*', 'node_modules/**/*', // Cache and transient stuff
19 ],
20 clean: ['dist', '*.zip'],
21 external: ['**/vendor/**/*'],
22 },
23 _files_get = function (list, cback) {
24 cback = cback || function (a) { return a; };
25 return function () {
26 return ((list || {}).files || []).map(cback);
27 };
28 },
29 _files_add = function (list) {
30 return function (path) {
31 list.files = list.files || [];
32 list.files.push(path);
33 };
34 },
35
36 _file_lists = {},
37 _mkpath = function (raw) {
38 var sfx = !!raw.match(/\/[^\/]+\.[a-zA-Z]{2,4}/) ? '' : '/**/*';
39 return raw.replace(/\/$/, '') + sfx;
40 },
41 _from_module = function (what, modules) {
42 var rx = new RegExp('submodule "([^"]+)"[^]+?' + what + '\\.git'),
43 found = ''
44 ;
45 modules.split('[').forEach(function (line) {
46 if (found) return true;
47 var path = line.match(rx);
48 if (path && path[1]) found = path[1];
49 });
50 return found;
51 }
52 ;
53
54 _lists.forEach(function (list) {
55 _file_lists[list] = _raw_lists[list] ? {files: _raw_lists[list]} : {files: []};
56 _file_lists[list].get = _files_get(_file_lists[list]);
57 _file_lists[list].not = _files_get(_file_lists[list], function (a) { return '!' + a; });
58 _file_lists[list].add = _files_add(_file_lists[list]);
59 });
60
61 var files = {
62 gather: function () {
63 var result = [],
64 lists = _lists,
65 method = 'get'
66 ;
67 if (arguments.length > 1) {
68 // lists, method
69 lists = typeof [] === typeof arguments[0] && arguments[0] ? arguments[0] : lists;
70 method = typeof '' === typeof arguments[1] && arguments[1] ? arguments[1] : method;
71 } else if (arguments.length === 1) {
72 if (typeof [] === typeof arguments[0]) lists = arguments[0];
73 if (typeof '' === typeof arguments[0]) method = arguments[0];
74 }
75 lists.forEach(function (list) {
76 result = result.concat(_file_lists[list][method]());
77 });
78 return result;
79 },
80 get_meta: function () {
81 return files.gather([
82 'free', 'full',
83 'dev', 'temp', 'clean',
84 'external'
85 ]);
86 },
87 not_meta: function () {
88 return files.gather([
89 'free', 'full',
90 'dev', 'temp', 'clean',
91 'external'
92 ], 'not');
93 },
94 get: function (lst) {
95 return _file_lists[lst].get();
96 },
97 not: function (lst) {
98 return _file_lists[lst].not();
99 },
100 add: function (list, what) {
101 return _file_lists[list].add(what);
102 },
103 find: function (list, what) {
104 var finds = [],
105 rx = new RegExp(what)
106 ;
107 _file_lists[list].get().forEach(function (path) {
108 if (path.match(rx)) finds.push(path);
109 });
110 return finds;
111 },
112 find_path: function (list, what) {
113 var finds = files.find(list, what);
114 if (!finds.length || !finds[0]) return false;
115
116 return finds[0];
117 },
118 stem_path: function (list, what) {
119 var path = files.find_path(list, what);
120 if (!path) return false;
121
122 return path.replace(/\*\*\/\*/g, '');
123 }
124 };
125
126 grunt.verbose.subhead("Dynamically populate exclusion paths");
127
128 grunt.verbose.write("Adding source SASS files to dev list...");
129 grunt.file.expand(['**/*.scss', '!node_modules/**/*']).map(_mkpath).forEach(function (path) {
130 files.add('dev', path);
131 });
132 grunt.verbose.writeln("OK".green);
133
134 if (grunt.file.exists(".gitmodules")) {
135 var modules = grunt.file.read(".gitmodules").replace(/\r\n/, "\n").replace(/\r/, "\n"),
136 target = false
137 ;
138
139 grunt.verbose.write("Adding WPMU DEV Dashboard to free distribution exclusions...");
140 target = _from_module('wpmudev-dashboard-notification', modules);
141 if (target) {
142 files.add('free', _mkpath(target));
143 grunt.verbose.writeln("OK".green);
144 } else {
145 grunt.verbose.writeln("Skip".yellow);
146 }
147
148 grunt.verbose.write("Adding shared tasks to non-dev distribution exclusions...");
149 target = _from_module('shared-tasks', modules);
150 if (target) {
151 files.add('dev', _mkpath(target));
152 grunt.verbose.writeln("OK".green);
153 } else {
154 grunt.verbose.writeln("Skip".yellow);
155 }
156
157 grunt.verbose.writeln("Adding all stuff from git submodules to externals...");
158 modules.split('[').forEach(function (sbm) {
159 if (!sbm) return true;
160 var path = sbm.match(/submodule ('|")([^'"]+?)('|")/);
161 if (path && path[2]) {
162 files.add('external', _mkpath(path[2]));
163 grunt.verbose.writeln("Adding git submodule path", path[2], "OK".green);
164 }
165 });
166 }
167
168 grunt.verbose.writeln("Exclusions populated".blue);
169
170 return files;
171
172 };
173