diff --git a/package.json b/package.json index 9392ffbd80..2947c02545 100644 --- a/package.json +++ b/package.json @@ -29,13 +29,11 @@ }, "scripts": { "lint": "semistandard '**/*.js'", - "generate": "node ./scripts/generate", - "pretest": "npm run lint && node ./scripts/clean coverage", + "pretest": "npm run lint", "unit-cover": "nyc --cache npm test && nyc report --reporter=html", "system-cover": "nyc --cache npm run system-test && nyc report --reporter=html", "test": "npm run unit-test && npm run system-test", - "cover": "nyc --cache npm run test && nyc report --reporter=html", - "update-dependencies": "./scripts/update-dependencies.sh" + "cover": "nyc --cache npm run test && nyc report --reporter=html" }, "devDependencies": { "@google-cloud/nodejs-repo-tools": "^2.3.6", diff --git a/scripts/build b/scripts/build deleted file mode 100755 index 299f586194..0000000000 --- a/scripts/build +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env node - -/** - * Copyright 2017, 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 execSync = require('child_process').execSync; -const path = require('path'); - -let localPath = process.argv.slice(2)[0] || process.cwd(); - -let remainingArgs = []; - -process.argv.forEach((arg, i) => { - if (arg === '--' && i <= (process.argv.length - 1)) { - remainingArgs = process.argv.slice(i + 1).map((arg) => { - if (arg && arg.indexOf(' ') !== -1 && arg[0] !== `"` && arg[arg.length - 1] !== `"`) { - return `"${arg}"`; - } - return arg; - }); - } -}); - -if (!path.isAbsolute(localPath)) { - localPath = path.join(process.cwd(), localPath); -} - -const branch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim(); - -const command = `samples test build -l=${localPath} --async ${remainingArgs.join(' ')}`.trim(); - -console.log(`Command: ${command}`); - -if (branch === 'master' || process.env.RUN_ALL_BUILDS) { - execSync(command, { - stdio: 'inherit' - }); -} else { - const numChangedFiles = execSync('git diff-tree --no-commit-id --name-status -r HEAD') - .toString() - .trim() - .split('\n') - .filter((line) => line) - .filter((line) => !line.startsWith('D')) - .map((line) => line.replace(/^\w(\s)+/, '')) - .map((line) => path.resolve(line)) - .filter((line) => line.includes(localPath)) - .length; - - if (numChangedFiles) { - execSync(command, { - stdio: 'inherit' - }); - } else { - console.log(`Skipping ${localPath}`); - } -} diff --git a/scripts/clean b/scripts/clean deleted file mode 100755 index 1a1dc7f82b..0000000000 --- a/scripts/clean +++ /dev/null @@ -1,49 +0,0 @@ -#!/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. - -require('shelljs/global'); - -const storage = require('@google-cloud/storage')(); - -const args = process.argv.slice(2); - -if (!args.length || args[0] === 'coverage') { - rm('-rf', 'coverage'); -} else if (args[0] === 'buckets') { - const NAME_REG_EXP = /^docs-samples-gae-test-[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/; - - storage - .getBuckets() - .then(([buckets]) => { - let promise = Promise.resolve(); - - buckets - .filter((bucket) => NAME_REG_EXP.test(bucket.name)) - .forEach((bucket) => { - promise = promise.then(() => { - return bucket.deleteFiles() - .then(() => bucket.deleteFiles(), console.error) - .then(() => { - console.log(`Deleting ${bucket.name}`); - return bucket.delete(); - }, console.error) - .catch(console.error); - }); - }); - }) - .catch((err) => { - console.error('ERROR:', err); - }); -} diff --git a/scripts/generate b/scripts/generate deleted file mode 100755 index ec44cf9fe3..0000000000 --- a/scripts/generate +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env node - -/** - * Copyright 2017, 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. - */ - -'use strict'; - -const childProcess = require('child_process'); -const fs = require(`fs`); -const path = require(`path`); - -const PROJECT_ROOT = path.join(__dirname, `..`); - -function findSamples (directory, depth) { - // Limit recursion depth - if (depth < 0) { - return; - } - - // Skip module directories - if (directory.includes('node_modules')) { - return; - } - - // Get subdirectories - const dirs = fs.readdirSync(directory); - - // Record subdirectories that contain a package.json file - dirs - .filter((dir) => fs.existsSync(path.join(directory, dir, `package.json`))) - .forEach((dir) => { - const _path = path.join(directory, dir); - const pkg = JSON.parse(fs.readFileSync(path.join(_path, `package.json`))); - if (pkg['cloud-repo-tools'] && pkg['cloud-repo-tools'].samples && pkg['cloud-repo-tools'].samples.length > 0) { - const result = childProcess.spawnSync('node', ['./node_modules/@google-cloud/nodejs-repo-tools/bin/samples', 'generate', '--local-path', _path, '--build-pack', 'nodejs'], { - cwd: PROJECT_ROOT, - stdio: 'inherit' - }); - - if (result.error) { - throw result.error; - } - } - }); - - // Recurse - dirs - .filter((dir) => fs.statSync(path.join(directory, dir)).isDirectory()) - .forEach((dir) => { - findSamples(path.join(directory, dir), depth - 1); - }); -} - -findSamples(PROJECT_ROOT, 3); diff --git a/scripts/update-dependencies.sh b/scripts/update-dependencies.sh deleted file mode 100755 index 7fb44e898a..0000000000 --- a/scripts/update-dependencies.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -# Copyright 2017 Google Inc. All rights reserved. -# -# 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. - -# For all directories containing a package.json file that aren't in a "node_modules" folder: -# Update dependencies in package.json (ncu -u) -# If no files in that directory have changed, skip it (! git diff --quiet --exit-code .) -# Update dependencies in node_modules (yarn upgrade) -# Run tests, and skip that directory if they fail (yarn test -- --fail-fast) -# If the directory has not been skipped, add 'yarn.lock' and 'package.json' to the current commit -find . -name "package.json" -not -path "*/node_modules/*" -execdir sh -c "ncu -u && ! git diff --quiet --exit-code . && npm install && npm test && git add package.json" \; - -# Note: this script deliberately avoids including broken dependencies. \ No newline at end of file