forked from GoogleCloudPlatform/nodejs-docs-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun
More file actions
90 lines (80 loc) · 2.44 KB
/
run
File metadata and controls
90 lines (80 loc) · 2.44 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
#!/usr/bin/env node
/**
* Copyright 2016, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const async = require('async');
const path = require('path');
const command = process.argv.slice(2).shift();
require('shelljs/global');
// Run the command in up to 7 directories at a time
const queue = async.queue((directory, callback) => {
runForDirectory(directory, callback);
}, 4);
queueDirectories('appengine');
queue.push('bigquery');
queue.push('computeengine');
queue.push('datastore');
queue.push('debugger');
queue.push('dns');
queueDirectories('endpoints');
queueDirectories('functions');
queue.push('functions/ocr/app');
queue.push('language');
queue.push('language/slackbot');
queue.push('logging');
queue.push('monitoring');
queue.push('prediction');
queue.push('pubsub');
queue.push('resource');
queue.push('speech');
queue.push('storage');
queue.push('trace');
queue.push('translate');
queue.push('vision');
/**
* Run the command in the given directory
*
* @param {string} directory The name of the directory in which to run the
* command.
* @param {function} callback The callback function.
*/
function runForDirectory(directory, callback) {
console.log(`${directory}...running ${command}`);
exec(command, {
async: true,
cwd: path.join(__dirname, '../', directory)
}, function (err) {
console.log(`${directory}...done`);
callback(err);
});
}
/**
* Recursively run the command within a single directory.
*
* @param {string} directory The name of the directory in which to recursively
* run the command.
*/
function queueDirectories(directory) {
// Move into the directory
cd(directory);
// List the files in the directory
ls('-dl', '*')
// Find the directories within the directory
.filter((file) => file.isDirectory() && file.name !== 'test' && file.name !== 'system-test')
.forEach((file) => {
queue.push(path.join(directory, file.name));
});
// Move out of the directory
cd('..');
}