|
| 1 | +/** |
| 2 | + * Copyright 2017 Google Inc. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import * as path from 'path'; |
| 18 | +import * as pify from 'pify'; |
| 19 | +import * as rawFs from 'fs'; |
| 20 | +import * as rawMkdirp from 'mkdirp'; |
| 21 | +import * as rawNcp from 'ncp'; |
| 22 | + |
| 23 | +const fs = pify(rawFs); |
| 24 | +const mkdirp = pify(rawMkdirp); |
| 25 | +const ncp = pify(rawNcp); |
| 26 | + |
| 27 | +const TEST = 'test'; |
| 28 | +const SYSTEM_TEST = 'system-test'; |
| 29 | +const PACKAGE_JSON = 'package.json'; |
| 30 | + |
| 31 | +// For the transpiled code: |
| 32 | +// __dirname = <project root>/build/scripts/ |
| 33 | +const PROJECT_ROOT = path.join(__dirname, '..', '..'); |
| 34 | +const BUILD_DIR = path.join(PROJECT_ROOT, 'build'); |
| 35 | + |
| 36 | +const INPUT_TEST_DIR = path.join(PROJECT_ROOT, TEST); |
| 37 | +const INPUT_SYSTEM_TEST_DIR = path.join(PROJECT_ROOT, SYSTEM_TEST); |
| 38 | +const INPUT_PACKAGE_JSON = path.join(PROJECT_ROOT, PACKAGE_JSON); |
| 39 | + |
| 40 | +const OUTPUT_TEST_DIR = path.join(BUILD_DIR, TEST); |
| 41 | +const OUTPUT_SYSTEM_TEST_DIR = path.join(BUILD_DIR, SYSTEM_TEST); |
| 42 | +const OUTPUT_PACKAGE_JSON = path.join(BUILD_DIR, PACKAGE_JSON); |
| 43 | + |
| 44 | +async function setupUnitTests(): Promise<void> { |
| 45 | + await mkdirp(OUTPUT_TEST_DIR); |
| 46 | + await fs.writeFile(OUTPUT_PACKAGE_JSON, |
| 47 | + await fs.readFile(INPUT_PACKAGE_JSON)); |
| 48 | + await ncp(INPUT_TEST_DIR, OUTPUT_TEST_DIR); |
| 49 | +} |
| 50 | + |
| 51 | +async function setupSystemTests(): Promise<void> { |
| 52 | + await mkdirp(OUTPUT_SYSTEM_TEST_DIR); |
| 53 | + await ncp(INPUT_SYSTEM_TEST_DIR, OUTPUT_SYSTEM_TEST_DIR); |
| 54 | +} |
| 55 | + |
| 56 | +async function main(): Promise<void> { |
| 57 | + try { |
| 58 | + await setupUnitTests(); |
| 59 | + await setupSystemTests(); |
| 60 | + } |
| 61 | + catch (e) { |
| 62 | + console.error(e); |
| 63 | + process.exit(1); |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +main(); |
0 commit comments