Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(913)

Unified Diff: third_party/WebKit/Source/devtools/scripts/utils.js

Issue 2413563002: DevTools: add "npm test" to run tests by fetching content shells (Closed)
Patch Set: nits Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/scripts/utils.js
diff --git a/third_party/WebKit/Source/devtools/scripts/utils.js b/third_party/WebKit/Source/devtools/scripts/utils.js
index c66e6a0d4c8ad7d37512ff482c1aa713bbfc8c84..a0df35a1f5f23aa987bec2b87ffa965ce2932bc0 100644
--- a/third_party/WebKit/Source/devtools/scripts/utils.js
+++ b/third_party/WebKit/Source/devtools/scripts/utils.js
@@ -5,6 +5,7 @@
var fs = require("fs");
var http = require("http");
var https = require("https");
+var path = require("path");
var parseURL = require("url").parse;
var Stream = require("stream").Transform;
@@ -45,18 +46,88 @@ function atob(str)
return new Buffer(str, "base64").toString("binary");
}
-
function isFile(path)
{
try {
return fs.statSync(path).isFile();
- } catch (e) {
+ } catch (error) {
+ return false;
+ }
+}
+
+function isDir(path)
+{
+ try {
+ return fs.statSync(path).isDirectory();
+ } catch (error) {
return false;
}
}
+function copy(src, dest)
+{
+ try {
+ var targetFilePath = path.resolve(dest, path.basename(src));
+ fs.writeFileSync(targetFilePath, fs.readFileSync(src));
+ } catch (error) {
+ throw new Error(`Received an error: [${error}] while trying to copy: ${src} -> ${dest}`);
+ }
+}
+
+function copyRecursive(src, dest)
+{
+ try {
+ var targetDirPath = path.resolve(dest, path.basename(src));
+ if (!fs.existsSync(targetDirPath))
+ fs.mkdirSync(targetDirPath);
+ if (isDir(src)) {
+ var files = fs.readdirSync(src);
+ for (var i = 0; i < files.length; i++) {
+ var childPath = path.resolve(src, files[i]);
+ if (isDir(childPath)) {
+ copyRecursive(childPath, targetDirPath);
+ } else {
+ var targetFilePath = path.resolve(targetDirPath, path.basename(childPath));
+ fs.writeFileSync(targetFilePath, fs.readFileSync(childPath));
+ }
+ }
+ }
+ } catch (error) {
+ throw new Error(`Received an error: [${error}] while trying to copy: ${src} -> ${dest}`);
+ }
+}
+
+function removeRecursive(filePath)
+{
+ try {
+ if (fs.existsSync(filePath)) {
+ var files = fs.readdirSync(filePath);
+ for (var i = 0; i < files.length; i++) {
+ var childPath = path.resolve(filePath, files[i]);
+ if (isDir(childPath))
+ removeRecursive(childPath);
+ else
+ fs.unlinkSync(childPath);
+ }
+ fs.rmdirSync(filePath);
+ }
+ } catch (error) {
+ throw new Error(`Received an error: [${error}] while trying to remove: ${filePath}`);
+ }
+}
+
+function includes(sequence, target)
+{
+ return sequence.indexOf(target) > -1;
+}
+
module.exports = {
fetch,
atob,
isFile,
+ isDir,
+ copy,
+ copyRecursive,
+ removeRecursive,
+ includes,
};

Powered by Google App Engine
This is Rietveld 408576698