@itwin/build-tools 3.0.0-dev.84 → 3.0.0-dev.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nycrc +29 -29
- package/CHANGELOG.md +1026 -1026
- package/README.md +59 -59
- package/bin/betools.js +148 -148
- package/package.json +2 -2
- package/scripts/config/paths.js +27 -27
- package/scripts/docs.js +100 -100
- package/scripts/extract-api.js +134 -134
- package/scripts/extract.js +72 -72
- package/scripts/pseudolocalize.js +106 -106
- package/scripts/rush/utils.js +38 -38
- package/scripts/utils/simpleSpawn.js +85 -85
- package/scripts/utils/validateTags.js +120 -120
- package/tsconfig-base.json +27 -27
- package/tsconfig.json +19 -19
package/scripts/docs.js
CHANGED
@@ -1,100 +1,100 @@
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
2
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
3
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
4
|
-
*--------------------------------------------------------------------------------------------*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
process.env.NODE_ENV = "prod";
|
8
|
-
|
9
|
-
const paths = require("./config/paths");
|
10
|
-
const path = require("path");
|
11
|
-
const cpx = require("cpx");
|
12
|
-
const fs = require("fs");
|
13
|
-
const { spawn, handleInterrupts } = require("./utils/simpleSpawn");
|
14
|
-
const { validateTags } = require("./utils/validateTags");
|
15
|
-
const argv = require("yargs").argv;
|
16
|
-
|
17
|
-
// Makes the script crash on unhandled rejections instead of silently
|
18
|
-
// ignoring them. In the future, promise rejections that are not handled will
|
19
|
-
// terminate the Node.js process with a non-zero exit code.
|
20
|
-
process.on("unhandledRejection", err => {
|
21
|
-
throw err;
|
22
|
-
});
|
23
|
-
|
24
|
-
const source = (argv.source === undefined) ? paths.appSrc : argv.source;
|
25
|
-
const out = (argv.out === undefined) ? paths.appDocs : argv.out;
|
26
|
-
const json = (argv.json === undefined) ? paths.appJsonDocs : argv.json;
|
27
|
-
|
28
|
-
const baseUrlOptions = (argv.baseUrl === undefined) ? [] : ["--baseUrl", argv.baseUrl];
|
29
|
-
console.log("Input: " + argv)
|
30
|
-
const includeOptions = (argv.includes === undefined) ? [] : ["--includes", argv.includes];
|
31
|
-
|
32
|
-
let excludeList = "**/node_modules/**/*,**/*test*/**/*";
|
33
|
-
if (argv.excludes !== undefined)
|
34
|
-
excludeList += ",**/" + argv.excludes + "/**/*";
|
35
|
-
if (argv.excludeGlob !== undefined)
|
36
|
-
excludeList += "," + argv.excludeGlob;
|
37
|
-
|
38
|
-
let outputOptions = [
|
39
|
-
"--json", json
|
40
|
-
];
|
41
|
-
|
42
|
-
if (argv.onlyJson === undefined)
|
43
|
-
outputOptions = outputOptions.concat(["--out", out]);
|
44
|
-
|
45
|
-
const readmeOption = (argv.readme === undefined) ? "none" : argv.readme;
|
46
|
-
|
47
|
-
const options = [
|
48
|
-
"--excludePrivate",
|
49
|
-
"--experimentalDecorators",
|
50
|
-
"--excludeExternals",
|
51
|
-
"--excludeNotExported",
|
52
|
-
"--ignoreCompilerErrors",
|
53
|
-
"--hideGenerator",
|
54
|
-
];
|
55
|
-
|
56
|
-
if (argv.name) options.push("--name", argv.name);
|
57
|
-
|
58
|
-
if (argv.theme) options.push("--theme", argv.theme);
|
59
|
-
|
60
|
-
const args = [
|
61
|
-
path.resolve(process.cwd(), source),
|
62
|
-
...options,
|
63
|
-
"--exclude", [excludeList],
|
64
|
-
...outputOptions,
|
65
|
-
"--mode", "modules",
|
66
|
-
"--readme", readmeOption,
|
67
|
-
"--module", "commonjs",
|
68
|
-
"--plugin", "typedoc-plugin-external-module-name,typedoc-plugin-internal-external",
|
69
|
-
"--external-aliases", "alpha,internal",
|
70
|
-
"--internal-aliases", "UNUSED",
|
71
|
-
...baseUrlOptions,
|
72
|
-
...includeOptions
|
73
|
-
];
|
74
|
-
|
75
|
-
console.log("Arguments to TypeDoc: " + JSON.stringify(args, null, 2));
|
76
|
-
|
77
|
-
spawn(require.resolve(".bin/typedoc"), args).then((code) => {
|
78
|
-
// Copy index.ts file to json output folder and rename to index.ts if a file is specified. Needed to add descriptions within the barrel file.
|
79
|
-
const outputDir = path.parse(json).dir;
|
80
|
-
if (argv.tsIndexFile) {
|
81
|
-
cpx.copySync(path.join(source, argv.tsIndexFile), outputDir);
|
82
|
-
fs.renameSync(path.join(outputDir, argv.tsIndexFile), path.join(outputDir, 'index.ts'));
|
83
|
-
}
|
84
|
-
// Copy CHANGELOG.json to json output folder
|
85
|
-
if (fs.existsSync(path.join(process.cwd(), 'CHANGELOG.json'))) {
|
86
|
-
cpx.copySync(path.join(process.cwd(), 'CHANGELOG.json'), outputDir);
|
87
|
-
}
|
88
|
-
|
89
|
-
if (code === 0) {
|
90
|
-
let tagErrors = validateTags(json);
|
91
|
-
if (tagErrors.toString()) {
|
92
|
-
console.error(`JSON contains invalid tags: ${JSON.stringify(tagErrors)}`);
|
93
|
-
fs.unlink(json);
|
94
|
-
console.log(`JSON removed from ${json}`)
|
95
|
-
code = 5;
|
96
|
-
}
|
97
|
-
}
|
98
|
-
process.exit(code)
|
99
|
-
});
|
100
|
-
handleInterrupts();
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
process.env.NODE_ENV = "prod";
|
8
|
+
|
9
|
+
const paths = require("./config/paths");
|
10
|
+
const path = require("path");
|
11
|
+
const cpx = require("cpx");
|
12
|
+
const fs = require("fs");
|
13
|
+
const { spawn, handleInterrupts } = require("./utils/simpleSpawn");
|
14
|
+
const { validateTags } = require("./utils/validateTags");
|
15
|
+
const argv = require("yargs").argv;
|
16
|
+
|
17
|
+
// Makes the script crash on unhandled rejections instead of silently
|
18
|
+
// ignoring them. In the future, promise rejections that are not handled will
|
19
|
+
// terminate the Node.js process with a non-zero exit code.
|
20
|
+
process.on("unhandledRejection", err => {
|
21
|
+
throw err;
|
22
|
+
});
|
23
|
+
|
24
|
+
const source = (argv.source === undefined) ? paths.appSrc : argv.source;
|
25
|
+
const out = (argv.out === undefined) ? paths.appDocs : argv.out;
|
26
|
+
const json = (argv.json === undefined) ? paths.appJsonDocs : argv.json;
|
27
|
+
|
28
|
+
const baseUrlOptions = (argv.baseUrl === undefined) ? [] : ["--baseUrl", argv.baseUrl];
|
29
|
+
console.log("Input: " + argv)
|
30
|
+
const includeOptions = (argv.includes === undefined) ? [] : ["--includes", argv.includes];
|
31
|
+
|
32
|
+
let excludeList = "**/node_modules/**/*,**/*test*/**/*";
|
33
|
+
if (argv.excludes !== undefined)
|
34
|
+
excludeList += ",**/" + argv.excludes + "/**/*";
|
35
|
+
if (argv.excludeGlob !== undefined)
|
36
|
+
excludeList += "," + argv.excludeGlob;
|
37
|
+
|
38
|
+
let outputOptions = [
|
39
|
+
"--json", json
|
40
|
+
];
|
41
|
+
|
42
|
+
if (argv.onlyJson === undefined)
|
43
|
+
outputOptions = outputOptions.concat(["--out", out]);
|
44
|
+
|
45
|
+
const readmeOption = (argv.readme === undefined) ? "none" : argv.readme;
|
46
|
+
|
47
|
+
const options = [
|
48
|
+
"--excludePrivate",
|
49
|
+
"--experimentalDecorators",
|
50
|
+
"--excludeExternals",
|
51
|
+
"--excludeNotExported",
|
52
|
+
"--ignoreCompilerErrors",
|
53
|
+
"--hideGenerator",
|
54
|
+
];
|
55
|
+
|
56
|
+
if (argv.name) options.push("--name", argv.name);
|
57
|
+
|
58
|
+
if (argv.theme) options.push("--theme", argv.theme);
|
59
|
+
|
60
|
+
const args = [
|
61
|
+
path.resolve(process.cwd(), source),
|
62
|
+
...options,
|
63
|
+
"--exclude", [excludeList],
|
64
|
+
...outputOptions,
|
65
|
+
"--mode", "modules",
|
66
|
+
"--readme", readmeOption,
|
67
|
+
"--module", "commonjs",
|
68
|
+
"--plugin", "typedoc-plugin-external-module-name,typedoc-plugin-internal-external",
|
69
|
+
"--external-aliases", "alpha,internal",
|
70
|
+
"--internal-aliases", "UNUSED",
|
71
|
+
...baseUrlOptions,
|
72
|
+
...includeOptions
|
73
|
+
];
|
74
|
+
|
75
|
+
console.log("Arguments to TypeDoc: " + JSON.stringify(args, null, 2));
|
76
|
+
|
77
|
+
spawn(require.resolve(".bin/typedoc"), args).then((code) => {
|
78
|
+
// Copy index.ts file to json output folder and rename to index.ts if a file is specified. Needed to add descriptions within the barrel file.
|
79
|
+
const outputDir = path.parse(json).dir;
|
80
|
+
if (argv.tsIndexFile) {
|
81
|
+
cpx.copySync(path.join(source, argv.tsIndexFile), outputDir);
|
82
|
+
fs.renameSync(path.join(outputDir, argv.tsIndexFile), path.join(outputDir, 'index.ts'));
|
83
|
+
}
|
84
|
+
// Copy CHANGELOG.json to json output folder
|
85
|
+
if (fs.existsSync(path.join(process.cwd(), 'CHANGELOG.json'))) {
|
86
|
+
cpx.copySync(path.join(process.cwd(), 'CHANGELOG.json'), outputDir);
|
87
|
+
}
|
88
|
+
|
89
|
+
if (code === 0) {
|
90
|
+
let tagErrors = validateTags(json);
|
91
|
+
if (tagErrors.toString()) {
|
92
|
+
console.error(`JSON contains invalid tags: ${JSON.stringify(tagErrors)}`);
|
93
|
+
fs.unlink(json);
|
94
|
+
console.log(`JSON removed from ${json}`)
|
95
|
+
code = 5;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
process.exit(code)
|
99
|
+
});
|
100
|
+
handleInterrupts();
|
package/scripts/extract-api.js
CHANGED
@@ -1,134 +1,134 @@
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
2
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
3
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
4
|
-
*--------------------------------------------------------------------------------------------*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
const { spawn, handleInterrupts } = require("./utils/simpleSpawn");
|
8
|
-
const argv = require("yargs").argv;
|
9
|
-
const fs = require("fs-extra");
|
10
|
-
const path = require("path");
|
11
|
-
const paths = require("./config/paths");
|
12
|
-
|
13
|
-
if (argv.entry === undefined) {
|
14
|
-
console.log("No argument found");
|
15
|
-
return;
|
16
|
-
}
|
17
|
-
|
18
|
-
const isCI = (process.env.TF_BUILD);
|
19
|
-
const entryPointFileName = argv.entry;
|
20
|
-
const ignoreMissingTags = argv.ignoreMissingTags;
|
21
|
-
|
22
|
-
// Resolves the root of the Rush repo
|
23
|
-
const resolveRoot = relativePath => {
|
24
|
-
// recurse until you find the "rush.json"
|
25
|
-
const parts = paths.appSrc.split(path.sep).reverse();
|
26
|
-
while (parts.length > 0) {
|
27
|
-
const resolved = path.join(parts.slice().reverse().join(path.sep), "rush.json");
|
28
|
-
if (fs.existsSync(resolved))
|
29
|
-
return path.join(parts.slice().reverse().join(path.sep), relativePath);
|
30
|
-
parts.shift();
|
31
|
-
}
|
32
|
-
process.stderr.write("Root of the Rush repository not found. Missing a rush.json file?");
|
33
|
-
};
|
34
|
-
const rushCommon = resolveRoot("common");
|
35
|
-
|
36
|
-
const config = {
|
37
|
-
$schema: "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
38
|
-
projectFolder: "../../",
|
39
|
-
compiler: {
|
40
|
-
tsconfigFilePath: "<projectFolder>/tsconfig.json"
|
41
|
-
},
|
42
|
-
mainEntryPointFilePath: `${entryPointFileName}.d.ts`,
|
43
|
-
apiReport: {
|
44
|
-
enabled: true,
|
45
|
-
reportFolder: path.resolve(path.join(rushCommon, "/api")),
|
46
|
-
reportTempFolder: path.resolve(path.join(rushCommon, "/temp/api")),
|
47
|
-
},
|
48
|
-
docModel: {
|
49
|
-
enabled: false
|
50
|
-
},
|
51
|
-
dtsRollup: {
|
52
|
-
enabled: false
|
53
|
-
},
|
54
|
-
tsdocMetadata: {
|
55
|
-
enabled: false
|
56
|
-
},
|
57
|
-
messages: {
|
58
|
-
tsdocMessageReporting: {
|
59
|
-
default: {
|
60
|
-
logLevel: "none"
|
61
|
-
}
|
62
|
-
},
|
63
|
-
extractorMessageReporting: {
|
64
|
-
default: {
|
65
|
-
logLevel: "error",
|
66
|
-
addToApiReportFile: false
|
67
|
-
},
|
68
|
-
"ae-incompatible-release-tags": {
|
69
|
-
logLevel: "error",
|
70
|
-
addToApiReportFile: false
|
71
|
-
},
|
72
|
-
"ae-missing-release-tag": {
|
73
|
-
logLevel: ignoreMissingTags ? "none" : "error",
|
74
|
-
addToApiReportFile: false
|
75
|
-
},
|
76
|
-
"ae-internal-missing-underscore": {
|
77
|
-
logLevel: "none",
|
78
|
-
addToApiReportFile: false
|
79
|
-
},
|
80
|
-
"ae-forgotten-export": {
|
81
|
-
logLevel: "none",
|
82
|
-
addToApiReportFile: false
|
83
|
-
},
|
84
|
-
"ae-unresolved-inheritdoc-reference": {
|
85
|
-
logLevel: "error",
|
86
|
-
addToApiReportFile: true
|
87
|
-
},
|
88
|
-
"ae-unresolved-inheritdoc-base": {
|
89
|
-
logLevel: "error",
|
90
|
-
addToApiReportFile: true
|
91
|
-
}
|
92
|
-
}
|
93
|
-
}
|
94
|
-
};
|
95
|
-
|
96
|
-
if (!fs.existsSync("lib")) {
|
97
|
-
process.stderr.write("lib folder not found. Run `rush build` before extract-api");
|
98
|
-
process.exit(1);
|
99
|
-
}
|
100
|
-
|
101
|
-
const configFileName = `lib/cjs/${entryPointFileName}.json`;
|
102
|
-
fs.writeFileSync(configFileName, JSON.stringify(config, null, 2));
|
103
|
-
|
104
|
-
const args = [
|
105
|
-
"run",
|
106
|
-
"-c", configFileName
|
107
|
-
];
|
108
|
-
if (!isCI)
|
109
|
-
args.push("-l");
|
110
|
-
|
111
|
-
spawn(require.resolve(".bin/api-extractor"), args).then((code) => {
|
112
|
-
if (fs.existsSync(configFileName))
|
113
|
-
fs.unlinkSync(configFileName);
|
114
|
-
|
115
|
-
// Only generate the extraction of the summary locally.
|
116
|
-
if (isCI)
|
117
|
-
process.exit(code);
|
118
|
-
|
119
|
-
const extractSummaryArgs = [
|
120
|
-
path.resolve(__dirname, "extract-api-summary.js"),
|
121
|
-
"--apiSignature", path.resolve(path.join(rushCommon, `/api/${entryPointFileName}.api.md`)),
|
122
|
-
"--outDir", path.resolve(path.join(rushCommon, "/api/summary")),
|
123
|
-
];
|
124
|
-
|
125
|
-
spawn("node", extractSummaryArgs).then((code) => {
|
126
|
-
process.exit(code);
|
127
|
-
});
|
128
|
-
|
129
|
-
if (process.env.GENERATE_FULL_API_REPORT)
|
130
|
-
spawn("node", [...extractSummaryArgs, "--gatherFullReport"]).then((code) => {
|
131
|
-
process.exit(code);
|
132
|
-
});
|
133
|
-
});
|
134
|
-
handleInterrupts();
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const { spawn, handleInterrupts } = require("./utils/simpleSpawn");
|
8
|
+
const argv = require("yargs").argv;
|
9
|
+
const fs = require("fs-extra");
|
10
|
+
const path = require("path");
|
11
|
+
const paths = require("./config/paths");
|
12
|
+
|
13
|
+
if (argv.entry === undefined) {
|
14
|
+
console.log("No argument found");
|
15
|
+
return;
|
16
|
+
}
|
17
|
+
|
18
|
+
const isCI = (process.env.TF_BUILD);
|
19
|
+
const entryPointFileName = argv.entry;
|
20
|
+
const ignoreMissingTags = argv.ignoreMissingTags;
|
21
|
+
|
22
|
+
// Resolves the root of the Rush repo
|
23
|
+
const resolveRoot = relativePath => {
|
24
|
+
// recurse until you find the "rush.json"
|
25
|
+
const parts = paths.appSrc.split(path.sep).reverse();
|
26
|
+
while (parts.length > 0) {
|
27
|
+
const resolved = path.join(parts.slice().reverse().join(path.sep), "rush.json");
|
28
|
+
if (fs.existsSync(resolved))
|
29
|
+
return path.join(parts.slice().reverse().join(path.sep), relativePath);
|
30
|
+
parts.shift();
|
31
|
+
}
|
32
|
+
process.stderr.write("Root of the Rush repository not found. Missing a rush.json file?");
|
33
|
+
};
|
34
|
+
const rushCommon = resolveRoot("common");
|
35
|
+
|
36
|
+
const config = {
|
37
|
+
$schema: "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
38
|
+
projectFolder: "../../",
|
39
|
+
compiler: {
|
40
|
+
tsconfigFilePath: "<projectFolder>/tsconfig.json"
|
41
|
+
},
|
42
|
+
mainEntryPointFilePath: `${entryPointFileName}.d.ts`,
|
43
|
+
apiReport: {
|
44
|
+
enabled: true,
|
45
|
+
reportFolder: path.resolve(path.join(rushCommon, "/api")),
|
46
|
+
reportTempFolder: path.resolve(path.join(rushCommon, "/temp/api")),
|
47
|
+
},
|
48
|
+
docModel: {
|
49
|
+
enabled: false
|
50
|
+
},
|
51
|
+
dtsRollup: {
|
52
|
+
enabled: false
|
53
|
+
},
|
54
|
+
tsdocMetadata: {
|
55
|
+
enabled: false
|
56
|
+
},
|
57
|
+
messages: {
|
58
|
+
tsdocMessageReporting: {
|
59
|
+
default: {
|
60
|
+
logLevel: "none"
|
61
|
+
}
|
62
|
+
},
|
63
|
+
extractorMessageReporting: {
|
64
|
+
default: {
|
65
|
+
logLevel: "error",
|
66
|
+
addToApiReportFile: false
|
67
|
+
},
|
68
|
+
"ae-incompatible-release-tags": {
|
69
|
+
logLevel: "error",
|
70
|
+
addToApiReportFile: false
|
71
|
+
},
|
72
|
+
"ae-missing-release-tag": {
|
73
|
+
logLevel: ignoreMissingTags ? "none" : "error",
|
74
|
+
addToApiReportFile: false
|
75
|
+
},
|
76
|
+
"ae-internal-missing-underscore": {
|
77
|
+
logLevel: "none",
|
78
|
+
addToApiReportFile: false
|
79
|
+
},
|
80
|
+
"ae-forgotten-export": {
|
81
|
+
logLevel: "none",
|
82
|
+
addToApiReportFile: false
|
83
|
+
},
|
84
|
+
"ae-unresolved-inheritdoc-reference": {
|
85
|
+
logLevel: "error",
|
86
|
+
addToApiReportFile: true
|
87
|
+
},
|
88
|
+
"ae-unresolved-inheritdoc-base": {
|
89
|
+
logLevel: "error",
|
90
|
+
addToApiReportFile: true
|
91
|
+
}
|
92
|
+
}
|
93
|
+
}
|
94
|
+
};
|
95
|
+
|
96
|
+
if (!fs.existsSync("lib")) {
|
97
|
+
process.stderr.write("lib folder not found. Run `rush build` before extract-api");
|
98
|
+
process.exit(1);
|
99
|
+
}
|
100
|
+
|
101
|
+
const configFileName = `lib/cjs/${entryPointFileName}.json`;
|
102
|
+
fs.writeFileSync(configFileName, JSON.stringify(config, null, 2));
|
103
|
+
|
104
|
+
const args = [
|
105
|
+
"run",
|
106
|
+
"-c", configFileName
|
107
|
+
];
|
108
|
+
if (!isCI)
|
109
|
+
args.push("-l");
|
110
|
+
|
111
|
+
spawn(require.resolve(".bin/api-extractor"), args).then((code) => {
|
112
|
+
if (fs.existsSync(configFileName))
|
113
|
+
fs.unlinkSync(configFileName);
|
114
|
+
|
115
|
+
// Only generate the extraction of the summary locally.
|
116
|
+
if (isCI)
|
117
|
+
process.exit(code);
|
118
|
+
|
119
|
+
const extractSummaryArgs = [
|
120
|
+
path.resolve(__dirname, "extract-api-summary.js"),
|
121
|
+
"--apiSignature", path.resolve(path.join(rushCommon, `/api/${entryPointFileName}.api.md`)),
|
122
|
+
"--outDir", path.resolve(path.join(rushCommon, "/api/summary")),
|
123
|
+
];
|
124
|
+
|
125
|
+
spawn("node", extractSummaryArgs).then((code) => {
|
126
|
+
process.exit(code);
|
127
|
+
});
|
128
|
+
|
129
|
+
if (process.env.GENERATE_FULL_API_REPORT)
|
130
|
+
spawn("node", [...extractSummaryArgs, "--gatherFullReport"]).then((code) => {
|
131
|
+
process.exit(code);
|
132
|
+
});
|
133
|
+
});
|
134
|
+
handleInterrupts();
|
package/scripts/extract.js
CHANGED
@@ -1,72 +1,72 @@
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
2
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
3
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
4
|
-
*--------------------------------------------------------------------------------------------*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
const argv = require("yargs").argv;
|
8
|
-
const path = require("path");
|
9
|
-
const paths = require("./config/paths");
|
10
|
-
const fs = require("fs-extra");
|
11
|
-
const readDirectory = require("recursive-readdir");
|
12
|
-
|
13
|
-
const __PUBLISH_EXTRACT_START__ = "__PUBLISH_EXTRACT_START__";
|
14
|
-
const __PUBLISH_EXTRACT_END__ = "__PUBLISH_EXTRACT_END__";
|
15
|
-
|
16
|
-
const extractDir = (argv.extractFrom === undefined) ? paths.appTest : argv.extractFrom;
|
17
|
-
const outDir = (argv.out === undefined) ? paths.libExtract : argv.out;
|
18
|
-
const fileExt = (argv.fileExt === undefined) ? ["test.ts"] : argv.fileExt.split(",");
|
19
|
-
const recursive = (argv.recursive === undefined) ? false : true;
|
20
|
-
|
21
|
-
const ignoreFunction = (file, stats) => {
|
22
|
-
if (stats.isDirectory())
|
23
|
-
return !recursive; // don't ignore subdirectories in recursive mode
|
24
|
-
return !fileExt.some((ext) => file.endsWith(ext)); // don't ignore files with desired extensions
|
25
|
-
};
|
26
|
-
|
27
|
-
readDirectory(extractDir, [ignoreFunction], (error, inputFileNames) => {
|
28
|
-
for (const inputFileName of inputFileNames) {
|
29
|
-
const inputFileContents = fs.readFileSync(inputFileName, "utf8");
|
30
|
-
|
31
|
-
// Skip the file if there are no occurences of the starting comment.
|
32
|
-
if (inputFileContents.indexOf(__PUBLISH_EXTRACT_START__) <= 0)
|
33
|
-
continue;
|
34
|
-
|
35
|
-
console.log("Processing: " + inputFileName);
|
36
|
-
const inputLines = inputFileContents.split("\n");
|
37
|
-
let outputFileName = undefined;
|
38
|
-
let outputLines = [];
|
39
|
-
let startIndent = 0;
|
40
|
-
|
41
|
-
for (const inputLine of inputLines) {
|
42
|
-
const startIndex = inputLine.indexOf(__PUBLISH_EXTRACT_START__);
|
43
|
-
if (startIndex > 0) {
|
44
|
-
startIndent = startIndex - 3;
|
45
|
-
if (outputFileName)
|
46
|
-
throw new Error("Nested " + __PUBLISH_EXTRACT_START__);
|
47
|
-
|
48
|
-
outputFileName = inputLine.substring(startIndex + __PUBLISH_EXTRACT_START__.length).trim();
|
49
|
-
if (0 === outputFileName.length)
|
50
|
-
throw new Error("Expected output file name after " + __PUBLISH_EXTRACT_START__);
|
51
|
-
} else if (inputLine.indexOf(__PUBLISH_EXTRACT_END__) > 0) {
|
52
|
-
if (!outputFileName)
|
53
|
-
throw new Error("Missing " + __PUBLISH_EXTRACT_START__);
|
54
|
-
|
55
|
-
if (!fs.existsSync(outDir))
|
56
|
-
fs.ensureDirSync(outDir);
|
57
|
-
|
58
|
-
const outputFilePath = path.join(outDir, outputFileName);
|
59
|
-
console.log("> Extracting into: " + outputFilePath);
|
60
|
-
fs.writeFileSync(outputFilePath, outputLines.join("\n"));
|
61
|
-
|
62
|
-
outputFileName = undefined;
|
63
|
-
outputLines = [];
|
64
|
-
} else if (outputFileName) {
|
65
|
-
outputLines.push(inputLine.substring(startIndent).replace(/\s+$/gm, ""));
|
66
|
-
}
|
67
|
-
}
|
68
|
-
|
69
|
-
if (outputFileName)
|
70
|
-
throw new Error("Missing " + __PUBLISH_EXTRACT_END__);
|
71
|
-
}
|
72
|
-
});
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const argv = require("yargs").argv;
|
8
|
+
const path = require("path");
|
9
|
+
const paths = require("./config/paths");
|
10
|
+
const fs = require("fs-extra");
|
11
|
+
const readDirectory = require("recursive-readdir");
|
12
|
+
|
13
|
+
const __PUBLISH_EXTRACT_START__ = "__PUBLISH_EXTRACT_START__";
|
14
|
+
const __PUBLISH_EXTRACT_END__ = "__PUBLISH_EXTRACT_END__";
|
15
|
+
|
16
|
+
const extractDir = (argv.extractFrom === undefined) ? paths.appTest : argv.extractFrom;
|
17
|
+
const outDir = (argv.out === undefined) ? paths.libExtract : argv.out;
|
18
|
+
const fileExt = (argv.fileExt === undefined) ? ["test.ts"] : argv.fileExt.split(",");
|
19
|
+
const recursive = (argv.recursive === undefined) ? false : true;
|
20
|
+
|
21
|
+
const ignoreFunction = (file, stats) => {
|
22
|
+
if (stats.isDirectory())
|
23
|
+
return !recursive; // don't ignore subdirectories in recursive mode
|
24
|
+
return !fileExt.some((ext) => file.endsWith(ext)); // don't ignore files with desired extensions
|
25
|
+
};
|
26
|
+
|
27
|
+
readDirectory(extractDir, [ignoreFunction], (error, inputFileNames) => {
|
28
|
+
for (const inputFileName of inputFileNames) {
|
29
|
+
const inputFileContents = fs.readFileSync(inputFileName, "utf8");
|
30
|
+
|
31
|
+
// Skip the file if there are no occurences of the starting comment.
|
32
|
+
if (inputFileContents.indexOf(__PUBLISH_EXTRACT_START__) <= 0)
|
33
|
+
continue;
|
34
|
+
|
35
|
+
console.log("Processing: " + inputFileName);
|
36
|
+
const inputLines = inputFileContents.split("\n");
|
37
|
+
let outputFileName = undefined;
|
38
|
+
let outputLines = [];
|
39
|
+
let startIndent = 0;
|
40
|
+
|
41
|
+
for (const inputLine of inputLines) {
|
42
|
+
const startIndex = inputLine.indexOf(__PUBLISH_EXTRACT_START__);
|
43
|
+
if (startIndex > 0) {
|
44
|
+
startIndent = startIndex - 3;
|
45
|
+
if (outputFileName)
|
46
|
+
throw new Error("Nested " + __PUBLISH_EXTRACT_START__);
|
47
|
+
|
48
|
+
outputFileName = inputLine.substring(startIndex + __PUBLISH_EXTRACT_START__.length).trim();
|
49
|
+
if (0 === outputFileName.length)
|
50
|
+
throw new Error("Expected output file name after " + __PUBLISH_EXTRACT_START__);
|
51
|
+
} else if (inputLine.indexOf(__PUBLISH_EXTRACT_END__) > 0) {
|
52
|
+
if (!outputFileName)
|
53
|
+
throw new Error("Missing " + __PUBLISH_EXTRACT_START__);
|
54
|
+
|
55
|
+
if (!fs.existsSync(outDir))
|
56
|
+
fs.ensureDirSync(outDir);
|
57
|
+
|
58
|
+
const outputFilePath = path.join(outDir, outputFileName);
|
59
|
+
console.log("> Extracting into: " + outputFilePath);
|
60
|
+
fs.writeFileSync(outputFilePath, outputLines.join("\n"));
|
61
|
+
|
62
|
+
outputFileName = undefined;
|
63
|
+
outputLines = [];
|
64
|
+
} else if (outputFileName) {
|
65
|
+
outputLines.push(inputLine.substring(startIndent).replace(/\s+$/gm, ""));
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
if (outputFileName)
|
70
|
+
throw new Error("Missing " + __PUBLISH_EXTRACT_END__);
|
71
|
+
}
|
72
|
+
});
|