forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy-assets.js
More file actions
185 lines (156 loc) · 4.99 KB
/
copy-assets.js
File metadata and controls
185 lines (156 loc) · 4.99 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
const {
tools: { makeBundle, symlinkTests, copyFile }
} = require("devtools-launchpad/index");
const path = require("path");
const minimist = require("minimist");
var fs = require("fs");
var fsExtra = require("fs-extra");
const rimraf = require("rimraf");
const feature = require("devtools-config");
const getConfig = require("./getConfig");
const writeReadme = require("./writeReadme");
const envConfig = getConfig();
feature.setConfig(envConfig);
const args = minimist(process.argv.slice(2), {
boolean: ["watch", "symlink", "assets"],
string: ["mc"]
});
const shouldSymLink = args.symlink;
const updateAssets = args.assets;
const watch = args.watch;
function updateFile(filename, cbk) {
var text = fs.readFileSync(filename, "utf-8");
fs.writeFileSync(filename, cbk(text), "utf-8");
}
function searchText(text, regexp) {
let matches = [];
let match;
do {
match = regexp.exec(text);
if (match) {
matches.push(match[1]);
}
} while (match);
return matches;
}
const walkSync = (dir, filelist = []) => {
fs.readdirSync(dir).forEach(file => {
filelist = fs.statSync(path.join(dir, file)).isDirectory()
? walkSync(path.join(dir, file), filelist)
: filelist.concat(path.join(dir, file));
});
return filelist;
};
function copySVGs({ projectPath, mcPath }) {
/*
* Copying SVGs
* We want to copy the SVGs that we include in our CSS into the
* MC devtools/client/themes directory. To do this, we look for the
* SVGs that are inlcuded in our CSS files and then copy the files
* and include them in the jar.mn file
*/
const projectImagesPath = path.join(projectPath, "assets/images/");
const mcImagesPath = path.join(
mcPath,
"devtools/client/themes/images/debugger"
);
let usedSvgs = [];
const svgTest = new RegExp(/url\(\/images\/(.*)\)/, "g");
const cssFiles = walkSync(path.join(projectPath, "src/components"))
.filter(file => file.match(/css$/))
.forEach(file =>
usedSvgs.push(...searchText(fs.readFileSync(file, "utf-8"), svgTest))
);
const files = fs
.readdirSync(projectImagesPath)
.filter(file => file.match(/svg$/))
.filter(file => usedSvgs.includes(file));
rimraf.sync(mcImagesPath);
files.forEach(file =>
fsExtra.copySync(
path.join(projectImagesPath, file),
path.join(mcImagesPath, `${file}`)
)
);
const newText =
files
.map(
file =>
` skin/images/debugger/${file} (themes/images/debugger/${file})`
)
.join("\n") + "\n";
const mcJarPath = path.join(mcPath, "devtools/client/jar.mn");
updateFile(mcJarPath, text => {
const newJar = text.replace(
/(.*skin\/images\/debugger\/.*$\n)+/gm,
newText
);
return newJar;
});
}
function copyTests({ mcPath, projectPath, mcModulePath, shouldSymLink }) {
const projectTestPath = path.join(projectPath, "src/test/mochitest");
const mcTestPath = path.join(mcPath, mcModulePath, "test/mochitest");
if (shouldSymLink) {
symlinkTests({ projectPath, mcTestPath, projectTestPath });
} else {
// we should rm the test dir first
rimraf.sync(mcTestPath);
copyFile(projectTestPath, mcTestPath, { cwd: projectPath });
}
}
function start() {
console.log("start: copy assets");
const projectPath = path.resolve(__dirname, "..");
const mcModulePath = "devtools/client/debugger/new";
let mcPath = args.mc ? args.mc : feature.getValue("firefox.mcPath");
process.env.NODE_ENV = "production";
// resolving against the project path in case it's relative. If it's absolute
// it will override whatever is in projectPath.
mcPath = path.resolve(projectPath, mcPath);
const config = { shouldSymLink, mcPath, projectPath, mcModulePath };
copyFile(
path.join(projectPath, "./assets/panel/debugger.properties"),
path.join(mcPath, "devtools/client/locales/en-US/debugger.properties"),
{ cwd: projectPath }
);
copyFile(
path.join(projectPath, "./assets/panel/prefs.js"),
path.join(mcPath, "devtools/client/preferences/debugger.js"),
{ cwd: projectPath }
);
copyFile(
path.join(projectPath, "./assets/panel/index.html"),
path.join(mcPath, "devtools/client/debugger/new/index.html"),
{ cwd: projectPath }
);
copyFile(
path.join(projectPath, "./assets/panel/panel.js"),
path.join(mcPath, "devtools/client/debugger/new/panel.js"),
{ cwd: projectPath }
);
copyFile(
path.join(projectPath, "./assets/panel/moz.build"),
path.join(mcPath, "devtools/client/debugger/new/moz.build"),
{ cwd: projectPath }
);
copySVGs(config);
copyTests(config);
writeReadme(path.join(mcPath, "devtools/client/debugger/new/README.mozilla"));
makeBundle({
outputPath: path.join(mcPath, mcModulePath),
projectPath,
watch,
updateAssets
})
.then(() => {
console.log("done: copy assets");
})
.catch(err => {
console.log(
"Uhoh, something went wrong. The error was written to assets-error.log"
);
fs.writeFileSync("assets-error.log", JSON.stringify(err, null, 2));
});
}
start();