@itwin/build-tools 4.0.0-dev.10 → 4.0.0-dev.100
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/CHANGELOG.md +55 -1
- package/bin/betools.js +14 -2
- package/mocha-reporter/index.js +96 -97
- package/package.json +11 -12
- package/scripts/docs.js +4 -3
- package/scripts/extract-api.js +15 -6
- package/scripts/utils/addPackageMetadata.js +50 -0
- package/tsconfig-base.json +2 -2
- package/scripts/utils/addSourceDir.js +0 -39
package/CHANGELOG.md
CHANGED
@@ -1,6 +1,60 @@
|
|
1
1
|
# Change Log - @itwin/build-tools
|
2
2
|
|
3
|
-
This log was last generated on
|
3
|
+
This log was last generated on Tue, 25 Apr 2023 17:50:35 GMT and should not be manually modified.
|
4
|
+
|
5
|
+
## 3.7.4
|
6
|
+
Tue, 25 Apr 2023 17:50:35 GMT
|
7
|
+
|
8
|
+
_Version update only_
|
9
|
+
|
10
|
+
## 3.7.3
|
11
|
+
Thu, 20 Apr 2023 13:19:28 GMT
|
12
|
+
|
13
|
+
_Version update only_
|
14
|
+
|
15
|
+
## 3.7.2
|
16
|
+
Wed, 12 Apr 2023 13:12:42 GMT
|
17
|
+
|
18
|
+
_Version update only_
|
19
|
+
|
20
|
+
## 3.7.1
|
21
|
+
Mon, 03 Apr 2023 15:15:36 GMT
|
22
|
+
|
23
|
+
_Version update only_
|
24
|
+
|
25
|
+
## 3.7.0
|
26
|
+
Wed, 29 Mar 2023 15:02:27 GMT
|
27
|
+
|
28
|
+
_Version update only_
|
29
|
+
|
30
|
+
## 3.6.3
|
31
|
+
Mon, 27 Mar 2023 16:26:47 GMT
|
32
|
+
|
33
|
+
_Version update only_
|
34
|
+
|
35
|
+
## 3.6.2
|
36
|
+
Fri, 17 Mar 2023 17:52:32 GMT
|
37
|
+
|
38
|
+
_Version update only_
|
39
|
+
|
40
|
+
## 3.6.1
|
41
|
+
Fri, 24 Feb 2023 22:00:48 GMT
|
42
|
+
|
43
|
+
_Version update only_
|
44
|
+
|
45
|
+
## 3.6.0
|
46
|
+
Wed, 08 Feb 2023 14:58:39 GMT
|
47
|
+
|
48
|
+
### Updates
|
49
|
+
|
50
|
+
- Fix script paths for situation when repository path has spaces
|
51
|
+
- add copy-assets script to betools command
|
52
|
+
- Added ability to override default exclude pattern for tests when generating docs
|
53
|
+
|
54
|
+
## 3.5.6
|
55
|
+
Fri, 24 Feb 2023 16:02:47 GMT
|
56
|
+
|
57
|
+
_Version update only_
|
4
58
|
|
5
59
|
## 3.5.5
|
6
60
|
Thu, 26 Jan 2023 22:53:27 GMT
|
package/bin/betools.js
CHANGED
@@ -71,7 +71,7 @@ yargs.strict(true)
|
|
71
71
|
})
|
72
72
|
},
|
73
73
|
(argv) => { extractCommand(argv) })
|
74
|
-
.command("extract-api", "Extracts the API of the Typescript library starting from an entry file with a default presets.
|
74
|
+
.command("extract-api", "Extracts the API of the Typescript library starting from an entry file with a default presets. Powered by @microsoft/api-extractor (https://api-extractor.com)",
|
75
75
|
function (yargs) {
|
76
76
|
return yargs.options({
|
77
77
|
"entry": {
|
@@ -79,6 +79,15 @@ yargs.strict(true)
|
|
79
79
|
},
|
80
80
|
"ignoreMissingTags": {
|
81
81
|
describe: "Turns off the 'ae-missing-release-tag' option which returns an error when a missing release tag is detected"
|
82
|
+
},
|
83
|
+
"apiReportFolder": {
|
84
|
+
describe: "Directory for the API report. Defaults to `<Rush repository root>/common/api`."
|
85
|
+
},
|
86
|
+
"apiReportTempFolder": {
|
87
|
+
describe: "Directory for the API report. Defaults to `<Rush repository root>/temp/api`."
|
88
|
+
},
|
89
|
+
"apiSummaryFolder": {
|
90
|
+
describe: "Directory for the API summary. Defaults to `<Rush repository root>/common/api/summary`."
|
82
91
|
}
|
83
92
|
})
|
84
93
|
},
|
@@ -149,7 +158,10 @@ function extractCommand(options) {
|
|
149
158
|
function extractApiCommand(options) {
|
150
159
|
const entryOpt = options.entry ? ["--entry", options.entry] : [];
|
151
160
|
const ignoreTagsOpt = options.ignoreMissingTags ? ["--ignoreMissingTags"] : [];
|
152
|
-
|
161
|
+
const apiReportFolderOpt = options.apiReportFolder ? ["--apiReportFolder", options.apiReportFolder] : [];
|
162
|
+
const apiReportTempFolderOpt = options.apiReportTempFolder ? ["--apiReportTempFolder", options.apiReportTempFolder] : [];
|
163
|
+
const apiSummaryFolderOpt = options.apiSummaryFolder ? ["--apiSummaryFolder", options.apiSummaryFolder] : [];
|
164
|
+
exec(["node", getScriptPath("extract-api.js"), ...entryOpt, ...ignoreTagsOpt, ...apiReportFolderOpt, ...apiReportTempFolderOpt, ...apiSummaryFolderOpt]);
|
153
165
|
}
|
154
166
|
|
155
167
|
function pseudolocalizeCommand(options) {
|
package/mocha-reporter/index.js
CHANGED
@@ -1,97 +1,96 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
*
|
6
|
-
|
7
|
-
|
8
|
-
/* eslint-disable @typescript-eslint/
|
9
|
-
/* eslint-disable
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
const
|
15
|
-
const
|
16
|
-
const
|
17
|
-
const
|
18
|
-
const
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
//
|
28
|
-
|
29
|
-
if (
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
//
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
+ "\
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
//
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
wtf.
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
module.exports = BentleyMochaReporter;
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
/*---------------------------------------------------------------------------------------------
|
4
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
5
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
6
|
+
*--------------------------------------------------------------------------------------------*/
|
7
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
8
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
9
|
+
/* eslint-disable no-console */
|
10
|
+
const debugLeaks = process.env.DEBUG_LEAKS;
|
11
|
+
if (debugLeaks)
|
12
|
+
require("wtfnode");
|
13
|
+
const path = require("path");
|
14
|
+
const fs = require("fs-extra");
|
15
|
+
const { logBuildWarning, logBuildError, failBuild } = require("../scripts/utils/utils");
|
16
|
+
const Base = require("mocha/lib/reporters/base");
|
17
|
+
const Spec = require("mocha/lib/reporters/spec");
|
18
|
+
const MochaJUnitReporter = require("mocha-junit-reporter");
|
19
|
+
function withStdErr(callback) {
|
20
|
+
const originalConsoleLog = Base.consoleLog;
|
21
|
+
Base.consoleLog = console.error;
|
22
|
+
callback();
|
23
|
+
Base.consoleLog = originalConsoleLog;
|
24
|
+
}
|
25
|
+
const isCI = process.env.CI || process.env.TF_BUILD;
|
26
|
+
// Force rush test to fail CI builds if describe.only or it.only is used.
|
27
|
+
// These should only be used for debugging and must not be committed, otherwise we may be accidentally skipping lots of tests.
|
28
|
+
if (isCI) {
|
29
|
+
if (typeof (mocha) !== "undefined")
|
30
|
+
mocha.forbidOnly();
|
31
|
+
else
|
32
|
+
require.cache[require.resolve("mocha/lib/mocharc.json", { paths: require.main?.paths ?? module.paths })].exports.forbidOnly = true;
|
33
|
+
}
|
34
|
+
// This is necessary to enable colored output when running in rush test:
|
35
|
+
Object.defineProperty(Base, "color", {
|
36
|
+
get: () => process.env.FORCE_COLOR !== "false" && process.env.FORCE_COLOR !== "0",
|
37
|
+
set: () => { },
|
38
|
+
});
|
39
|
+
class BentleyMochaReporter extends Spec {
|
40
|
+
constructor(_runner, _options) {
|
41
|
+
super(...arguments);
|
42
|
+
this._junitReporter = new MochaJUnitReporter(...arguments);
|
43
|
+
}
|
44
|
+
epilogue(...args) {
|
45
|
+
// Force test errors to be printed to stderr instead of stdout.
|
46
|
+
// This will allow rush to correctly summarize test failure when running rush test.
|
47
|
+
if (this.stats.failures) {
|
48
|
+
withStdErr(() => super.epilogue(...args));
|
49
|
+
}
|
50
|
+
else {
|
51
|
+
super.epilogue(...args);
|
52
|
+
if (0 === this.stats.passes) {
|
53
|
+
logBuildError("There were 0 passing tests. That doesn't seem right."
|
54
|
+
+ "\nIf there are really no passing tests and no failures, then what was even the point?"
|
55
|
+
+ "\nIt seems likely that tests were skipped by it.only, it.skip, or grep filters, so I'm going to fail now.");
|
56
|
+
failBuild();
|
57
|
+
}
|
58
|
+
}
|
59
|
+
// Detect hangs caused by tests that leave timers/other handles open - not possible in electron frontends.
|
60
|
+
if (!("electron" in process.versions)) {
|
61
|
+
// NB: By calling unref() on this timer, we stop it from keeping the process alive, so it will only fire if _something else_ is still keeping
|
62
|
+
// the process alive after 5 seconds. This also has the benefit of preventing the timer from showing up in wtfnode's dump of open handles.
|
63
|
+
setTimeout(() => {
|
64
|
+
logBuildError(`Handle leak detected. Node was still running 5 seconds after tests completed.`);
|
65
|
+
if (debugLeaks) {
|
66
|
+
const wtf = require("wtfnode");
|
67
|
+
wtf.setLogger("info", console.error);
|
68
|
+
wtf.dump();
|
69
|
+
}
|
70
|
+
else {
|
71
|
+
console.error("Try running with the DEBUG_LEAKS env var set to see open handles.");
|
72
|
+
}
|
73
|
+
// Not sure why, but process.exit(1) wasn't working here...
|
74
|
+
process.kill(process.pid);
|
75
|
+
}, 5000).unref();
|
76
|
+
}
|
77
|
+
if (!this.stats.pending)
|
78
|
+
return;
|
79
|
+
// Also log warnings in CI builds when tests have been skipped.
|
80
|
+
const currentPkgJson = path.join(process.cwd(), "package.json");
|
81
|
+
if (fs.existsSync(currentPkgJson)) {
|
82
|
+
const currentPackage = require(currentPkgJson).name;
|
83
|
+
if (this.stats.pending === 1)
|
84
|
+
logBuildWarning(`1 test skipped in ${currentPackage}`);
|
85
|
+
else
|
86
|
+
logBuildWarning(`${this.stats.pending} tests skipped in ${currentPackage}`);
|
87
|
+
}
|
88
|
+
else {
|
89
|
+
if (this.stats.pending === 1)
|
90
|
+
logBuildWarning(`1 test skipped`);
|
91
|
+
else
|
92
|
+
logBuildWarning(`${this.stats.pending} tests skipped`);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
module.exports = BentleyMochaReporter;
|
package/package.json
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@itwin/build-tools",
|
3
|
-
"version": "4.0.0-dev.
|
3
|
+
"version": "4.0.0-dev.100",
|
4
4
|
"description": "Bentley build tools",
|
5
5
|
"license": "MIT",
|
6
6
|
"repository": {
|
7
7
|
"type": "git",
|
8
|
-
"url": "https://github.com/iTwin/itwinjs-core
|
8
|
+
"url": "https://github.com/iTwin/itwinjs-core.git",
|
9
|
+
"directory": "tools/build"
|
9
10
|
},
|
10
11
|
"bin": {
|
11
12
|
"betools": "bin/betools.js"
|
@@ -20,7 +21,7 @@
|
|
20
21
|
"url": "http://www.bentley.com"
|
21
22
|
},
|
22
23
|
"dependencies": {
|
23
|
-
"@microsoft/api-extractor": "7.
|
24
|
+
"@microsoft/api-extractor": "7.34.4",
|
24
25
|
"chalk": "^3.0.0",
|
25
26
|
"cpx2": "^3.0.0",
|
26
27
|
"cross-spawn": "^7.0.1",
|
@@ -30,16 +31,16 @@
|
|
30
31
|
"mocha-junit-reporter": "^2.0.2",
|
31
32
|
"rimraf": "^3.0.2",
|
32
33
|
"tree-kill": "^1.2.0",
|
33
|
-
"typedoc": "^0.
|
34
|
-
"typedoc-plugin-merge-modules": "^
|
35
|
-
"typescript": "~
|
34
|
+
"typedoc": "^0.23.28",
|
35
|
+
"typedoc-plugin-merge-modules": "^4.0.1",
|
36
|
+
"typescript": "~5.0.2",
|
36
37
|
"wtfnode": "^0.9.1",
|
37
38
|
"yargs": "^17.4.0"
|
38
39
|
},
|
39
40
|
"devDependencies": {
|
40
|
-
"@itwin/eslint-plugin": "4.0.0-dev.
|
41
|
-
"@types/node": "18.11.5",
|
42
|
-
"eslint": "^
|
41
|
+
"@itwin/eslint-plugin": "^4.0.0-dev.33",
|
42
|
+
"@types/node": "^18.11.5",
|
43
|
+
"eslint": "^8.36.0"
|
43
44
|
},
|
44
45
|
"eslintConfig": {
|
45
46
|
"plugins": [
|
@@ -52,12 +53,10 @@
|
|
52
53
|
},
|
53
54
|
"scripts": {
|
54
55
|
"build": "tsc 1>&2",
|
55
|
-
"build:ci": "npm run -s build",
|
56
56
|
"clean": "rimraf ../../modules .rush/temp/package-deps*.json",
|
57
57
|
"docs": "",
|
58
58
|
"lint": "eslint -f visualstudio --config package.json --no-eslintrc \"./src/**/*.ts\" 1>&2",
|
59
59
|
"test": "",
|
60
60
|
"cover": ""
|
61
|
-
}
|
62
|
-
"readme": "# @itwin/build-tools\r\n\r\nCopyright © Bentley Systems, Incorporated. All rights reserved. See LICENSE.md for license terms and full copyright notice.\r\n\r\n## Description\r\n\r\nThe **@itwin/build-tools** is a package for developers to consolidate the steps for building TypeScript-based packages. The tools contained in this package are written in either Typescript or Javascript within the src/ directory, and compiled for use into the lib/ directory. As a developer package, this package has only dependencies, no devDependencies.\r\n\r\n### tsconfig-base\r\n\r\nLocation: tsconfig-base.json\\\r\nRequires build: no\r\n\r\nThis file contains common tsconfig settings across all iTwin.js packages. Packages should extend this file in their own tsconfig.json file, and then overwrite and set new properties as needed. Note that this file is different from the tsconfig.json file for this package, as that contains different settings for bentleyjs-tools only.\r\n\r\n### NPM Scripts\r\n\r\nLocation: scripts/\\\r\nRequires build: no\r\n\r\nThe following node scripts are delivered in this package's scripts folder in order to ease development of iTwin.js packages with npm scripts. These scripts may require that additional packages be installed as dependencies of your package.\r\n\r\nThe default behaviors of the scripts (without parameters) assume that the directory structure of your package mirrors the following:\r\n\r\n- root\r\n - source\r\n - test\r\n - assets\r\n - lib\r\n - package.json\r\n - tsconfig.json\r\n\r\nThe following is a list of some of the most commonly used scripts within this package:\r\n\r\n#### docs.js\r\n\r\nThis script runs a TypeDoc command, with specific parameters, to generate html TypeScript documentation as well as a json representation of the documentation to be consumed for other purposes. It includes the following parameters:\r\n\r\n- source - specify the TypeScript source directory\r\n- out - specify the directory of the html output\r\n- json - specify the directory and filename of the json output\r\n- baseUrl - specify a baseUrl to resolve modules\r\n- onlyJson - including this option will skip the html output and only output the json file\r\n- includes - directory of files to include in documentation (ex: for sample code)\r\n- excludes - name of directory, files, or file extensions to exclude.\r\n - A list can be provided using a `,` as a separator\r\n - Each of the provided to exclude is added to a glob pattern which checks all directories within the source.\r\n - i.e `--excludes=test,docs/*.md` will translate to `**/{test,docs/*.md}/**/*`\r\n\r\n#### extract.js\r\n\r\nThis is a script designed to extract sample code from test.ts files in a specific directory. The sample code should be surrounded by comments containing \"\\_\\_PUBLISH_EXTRACT_START\\_\\_\" and \"\\_\\_PUBLISH_EXTRACT_END\\_\\_\" directives.\r\n\r\n- extractDir - the path at which the sample code files are located\r\n- outDir - the path at which to output the selected code\r\n\r\n#### pseudolocalize.js\r\n\r\nThis script handles translating an English localization JSON file into a pseudoLocalization file.\r\n"
|
61
|
+
}
|
63
62
|
}
|
package/scripts/docs.js
CHANGED
@@ -12,7 +12,7 @@ const cpx = require("cpx2");
|
|
12
12
|
const fs = require("fs");
|
13
13
|
const { spawn, handleInterrupts } = require("./utils/simpleSpawn");
|
14
14
|
const { validateTags } = require("./utils/validateTags");
|
15
|
-
const {
|
15
|
+
const { addPackageMetadata } = require("./utils/addPackageMetadata");
|
16
16
|
const argv = require("yargs").argv;
|
17
17
|
|
18
18
|
// Makes the script crash on unhandled rejections instead of silently
|
@@ -85,13 +85,14 @@ spawn(require.resolve(".bin/typedoc"), args).then((code) => {
|
|
85
85
|
cpx.copySync(path.join(source, argv.tsIndexFile), outputDir);
|
86
86
|
fs.renameSync(path.join(outputDir, argv.tsIndexFile), path.join(outputDir, 'index.ts'));
|
87
87
|
}
|
88
|
+
|
88
89
|
// Copy CHANGELOG.json to json output folder
|
89
90
|
if (fs.existsSync(path.join(process.cwd(), 'CHANGELOG.json'))) {
|
90
91
|
cpx.copySync(path.join(process.cwd(), 'CHANGELOG.json'), outputDir);
|
91
92
|
}
|
92
93
|
|
93
|
-
// Append the directory of the package to the output
|
94
|
-
|
94
|
+
// Append the directory of the package, version and repository URL to the output
|
95
|
+
addPackageMetadata(json, process.cwd());
|
95
96
|
|
96
97
|
if (code === 0) {
|
97
98
|
let tagErrors = validateTags(json);
|
package/scripts/extract-api.js
CHANGED
@@ -31,7 +31,16 @@ const resolveRoot = relativePath => {
|
|
31
31
|
}
|
32
32
|
process.stderr.write("Root of the Rush repository not found. Missing a rush.json file?");
|
33
33
|
};
|
34
|
-
const rushCommon =
|
34
|
+
const rushCommon = () => {
|
35
|
+
let resolved;
|
36
|
+
if (!resolved)
|
37
|
+
resolved = resolveRoot("common");
|
38
|
+
return resolved;
|
39
|
+
};
|
40
|
+
|
41
|
+
const apiReportFolder = argv.apiReportFolder ?? path.join(rushCommon(), "/api");
|
42
|
+
const apiReportTempFolder = argv.apiReportTempFolder ?? path.join(rushCommon(), "/temp/api");
|
43
|
+
const apiSummaryFolder = argv.apiSummaryFolder ?? path.join(rushCommon(), "/api/summary");
|
35
44
|
|
36
45
|
const config = {
|
37
46
|
$schema: "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
@@ -42,8 +51,8 @@ const config = {
|
|
42
51
|
mainEntryPointFilePath: `${entryPointFileName}.d.ts`,
|
43
52
|
apiReport: {
|
44
53
|
enabled: true,
|
45
|
-
reportFolder: path.resolve(
|
46
|
-
reportTempFolder: path.resolve(
|
54
|
+
reportFolder: path.resolve(apiReportFolder),
|
55
|
+
reportTempFolder: path.resolve(apiReportTempFolder),
|
47
56
|
},
|
48
57
|
docModel: {
|
49
58
|
enabled: false
|
@@ -94,7 +103,7 @@ const config = {
|
|
94
103
|
};
|
95
104
|
|
96
105
|
if (!fs.existsSync("lib")) {
|
97
|
-
process.stderr.write("lib folder not found.
|
106
|
+
process.stderr.write("`lib` folder not found. Build the package(s) before running `extract-api`");
|
98
107
|
process.exit(1);
|
99
108
|
}
|
100
109
|
|
@@ -118,8 +127,8 @@ spawn(require.resolve(".bin/api-extractor"), args).then((code) => {
|
|
118
127
|
|
119
128
|
const extractSummaryArgs = [
|
120
129
|
path.resolve(__dirname, "extract-api-summary.js"),
|
121
|
-
"--apiSignature", path.resolve(path.join(
|
122
|
-
"--outDir", path.resolve(
|
130
|
+
"--apiSignature", path.resolve(path.join(apiReportFolder, `${entryPointFileName}.api.md`)),
|
131
|
+
"--outDir", path.resolve(apiSummaryFolder),
|
123
132
|
];
|
124
133
|
|
125
134
|
spawn("node", extractSummaryArgs).then((code) => {
|
@@ -0,0 +1,50 @@
|
|
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
|
+
|
6
|
+
const FS = require("fs-extra");
|
7
|
+
const path = require("path");
|
8
|
+
|
9
|
+
// We cannot guarantee the folder structure of a project
|
10
|
+
// so find the project root using rush env variable if available.
|
11
|
+
const rootPackageJson = process.env.RUSHSTACK_FILE_ERROR_BASE_FOLDER
|
12
|
+
? path.join(process.env.RUSHSTACK_FILE_ERROR_BASE_FOLDER, "package.json")
|
13
|
+
: "../../../../package.json";
|
14
|
+
|
15
|
+
// Check if path to root package.json is valid.
|
16
|
+
const rootPackageJsonPath = require.resolve(rootPackageJson);
|
17
|
+
|
18
|
+
//Find the package.json of the project and retrieve the version and repository URL
|
19
|
+
const packageJsonPath = path.join(process.cwd(), "package.json");
|
20
|
+
const packageJson = JSON.parse(FS.readFileSync(packageJsonPath));
|
21
|
+
const version = packageJson.version;
|
22
|
+
const repositoryUrl = packageJson.repository?.url;
|
23
|
+
const repositoryDirectory = packageJson.repository?.directory;
|
24
|
+
|
25
|
+
if (!version || !repositoryUrl || !repositoryDirectory) {
|
26
|
+
throw new Error("version or repository info not found in package.json");
|
27
|
+
}
|
28
|
+
|
29
|
+
// Appends the directory of the package root to the Typedoc JSON output
|
30
|
+
function addPackageMetadata(file, directory) {
|
31
|
+
if (FS.existsSync(file) && FS.statSync(file).isFile()) {
|
32
|
+
const contents = FS.readFileSync(file, "utf-8");
|
33
|
+
const pathToRootFolder = path.dirname(rootPackageJsonPath);
|
34
|
+
const packageRoot = directory.substring(pathToRootFolder.length + 1);
|
35
|
+
const jsonContents = JSON.parse(contents);
|
36
|
+
|
37
|
+
jsonContents["packageRoot"] = packageRoot.endsWith("src")
|
38
|
+
? packageRoot
|
39
|
+
: `${packageRoot}\\${"src"}`;
|
40
|
+
jsonContents["version"] = version;
|
41
|
+
jsonContents["repositoryUrl"] = repositoryUrl;
|
42
|
+
jsonContents["repositoryDirectory"] = repositoryDirectory;
|
43
|
+
|
44
|
+
FS.writeFileSync(file, Buffer.from(JSON.stringify(jsonContents, null, 2)));
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
module.exports = {
|
49
|
+
addPackageMetadata,
|
50
|
+
};
|
package/tsconfig-base.json
CHANGED
@@ -1,39 +0,0 @@
|
|
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
|
-
|
6
|
-
const FS = require("fs-extra");
|
7
|
-
const path = require("path");
|
8
|
-
|
9
|
-
// We cannot guarantee the folder structure of a project
|
10
|
-
// so find the project root using rush env variable if available.
|
11
|
-
if (process.env.RUSHSTACK_FILE_ERROR_BASE_FOLDER) {
|
12
|
-
rootPackageJsonPath = path.resolve(
|
13
|
-
process.env.RUSHSTACK_FILE_ERROR_BASE_FOLDER,
|
14
|
-
"package.json"
|
15
|
-
);
|
16
|
-
} else {
|
17
|
-
rootPackageJsonPath = path.resolve("../../../../package.json");
|
18
|
-
}
|
19
|
-
|
20
|
-
const rootPackageJson = require(rootPackageJsonPath);
|
21
|
-
|
22
|
-
// Appends the directory of the package root to the Typedoc JSON output
|
23
|
-
function addSourceDir(file, directory) {
|
24
|
-
if (FS.existsSync(file) && FS.statSync(file).isFile()) {
|
25
|
-
const contents = FS.readFileSync(file, "utf-8");
|
26
|
-
const packageRoot = directory.substring(
|
27
|
-
directory.indexOf(rootPackageJson.name) + rootPackageJson.name.length + 1
|
28
|
-
);
|
29
|
-
const jsonContents = JSON.parse(contents);
|
30
|
-
jsonContents["packageRoot"] = packageRoot.endsWith("src")
|
31
|
-
? packageRoot
|
32
|
-
: `${packageRoot}\\${"src"}`;
|
33
|
-
FS.writeFileSync(file, Buffer.from(JSON.stringify(jsonContents, null, 2)));
|
34
|
-
}
|
35
|
-
}
|
36
|
-
|
37
|
-
module.exports = {
|
38
|
-
addSourceDir,
|
39
|
-
};
|