#!/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('..'); }