forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpackage-docs-content.ts
47 lines (40 loc) · 1.93 KB
/
package-docs-content.ts
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
/**
* Script that will be dispatched by the "package_docs_content" rule and is responsible for
* copying input files to a new location. The new location will be computed within the Bazel
* rule implementation so that we don't need to compute the output paths with their sections
* multiple times.
*/
import {readFileSync, writeFileSync, ensureDirSync, statSync, copySync} from 'fs-extra';
import {dirname} from 'path';
/**
* Determines the command line arguments for the current Bazel action. Since this action can
* have a large set of input files, Bazel may write the arguments into a parameter file.
* This function is responsible for handling normal argument passing or Bazel parameter files.
* Read more here: https://docs.bazel.build/versions/master/skylark/lib/Args.html#use_param_file
*/
function getBazelActionArguments() {
const args = process.argv.slice(2);
// If Bazel uses a parameter file, we've specified that it passes the file in the following
// format: "arg0 arg1 --param-file={path_to_param_file}"
if (args[0].startsWith('--param-file=')) {
return readFileSync(args[0].split('=')[1], 'utf8').trim().split('\n');
}
return args;
}
if (require.main === module) {
// Process all file pairs that have been passed to this executable. Each argument will
// consist of the input file path and the desired output location.
getBazelActionArguments().forEach(argument => {
// Each argument that has been passed consists of an input file path and the expected
// output path. e.g. {path_to_input_file},{expected_output_path}
const [execFilePath, expectedOutput] = argument.split(',', 2);
// Ensure the directory exists. Bazel does not create the tree
// artifact by default.
ensureDirSync(dirname(expectedOutput));
if (statSync(execFilePath).isDirectory()) {
copySync(execFilePath, expectedOutput);
} else {
writeFileSync(expectedOutput, readFileSync(execFilePath, 'utf8'));
}
});
}