@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.
@@ -1,106 +1,106 @@
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
- /** Generates pseudo localization files from the en localization JSON files.
8
- */
9
- function pseudoLocalizeObject(objIn) {
10
- let objOut = {};
11
- for (let prop in objIn) {
12
- if (objIn.hasOwnProperty(prop)) {
13
- if (typeof objIn[prop] === "string") {
14
- objOut[prop] = pseudoLocalize(objIn[prop])
15
- } else if (typeof objIn[prop] === "object") {
16
- objOut[prop] = pseudoLocalizeObject(objIn[prop])
17
- }
18
- }
19
- }
20
- return objOut;
21
- }
22
-
23
- const replacements = {
24
- A: "\u00C0\u00C1,\u00C2\u00C3,\u00C4\u00C5",
25
- a: "\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5",
26
- B: "\u00DF",
27
- c: "\u00A2\u00E7",
28
- C: "\u00C7\u0028",
29
- D: "\u00D0",
30
- E: "\u00C8\u00C9\u00CA\u00CB",
31
- e: "\u00E8\u00E9\u00EA\u00EB",
32
- I: "\u00CC\u00CD\u00CE\u00CF",
33
- i: "\u00EC\u00ED\u00EE\u00EF",
34
- L: "\u00A3",
35
- N: "\u00D1",
36
- n: "\u00F1",
37
- O: "\u00D2\u00D3\u00D4\u00D5\u00D6",
38
- o: "\u00F2\u00F3\u00F4\u00F5\u00F6\u00F8",
39
- S: "\u0024\u00A7",
40
- U: "\u00D9\u00DA\u00DB\u00DC",
41
- u: "\u00B5\u00F9\u00FA\u00FB\u00FC",
42
- x: "\u00D7",
43
- Y: "\u00DD\u00A5",
44
- y: "\u00FD\u00FF",
45
- };
46
-
47
- /** PseudoLocalizes a single string */
48
- function pseudoLocalize(inputString) {
49
- let inReplace = 0;
50
- let outString = "";
51
- let replaceIndex = 0; // Note: the pseudoLocalize algorithm would normally use random, but here we cycle through because Javascript doesn't allow setting of the seed for Math.random.
52
- for (let iChar = 0; iChar < inputString.length; iChar++) {
53
- let thisChar = inputString.charAt(iChar);
54
- let nextChar = ((iChar + 1) < inputString.length) ? inputString.charAt(iChar + 1) : 0;
55
-
56
- // handle the {{ and }} delimiters for placeholders - don't want to do anything to characters in between.
57
- if (('{' === thisChar) && ('{' === nextChar)) {
58
- inReplace++;
59
- iChar++;
60
- outString = outString.concat("{{");
61
- } else if (('}' === thisChar) && ('}' === nextChar) && (inReplace > 0)) {
62
- inReplace--;
63
- iChar++;
64
- outString = outString.concat("}}");
65
- } else {
66
- let replacementChar = thisChar;
67
- if (0 === inReplace) {
68
- let replacementsForChar = replacements[thisChar];
69
- if (undefined !== replacementsForChar) {
70
- replacementChar = replacementsForChar.charAt(replaceIndex++ % replacementsForChar.length);
71
- }
72
- }
73
- outString = outString.concat(replacementChar);
74
- }
75
- }
76
- return outString;
77
- }
78
-
79
- function isJsonFile(fileName) {
80
- return fileName.endsWith(".json");
81
- }
82
-
83
- const argv = require("yargs").argv;
84
- const paths = require("./config/paths");
85
- const fs = require("fs-extra");
86
- const path = require("path");
87
-
88
- const englishDir = (argv.englishDir === undefined) ? paths.appLocalesEnglish : argv.englishDir;
89
- const inputFileNames = fs.readdirSync(englishDir).filter(isJsonFile);
90
- const outDir = (argv.out === undefined) ? paths.appLocalesPseudolocalize : argv.out;
91
- try {
92
- fs.mkdirpSync(outDir);
93
- } catch (e) {
94
- console.log(e);// do nothing
95
- }
96
-
97
- for (const inputFileName of inputFileNames) {
98
- const inputFilePath = path.join(englishDir, inputFileName);
99
- const outputFileName = path.join(outDir, inputFileName);
100
-
101
- let jsonIn = fs.readFileSync(inputFilePath, { encoding: "utf8" });
102
- let objIn = JSON.parse(jsonIn);
103
-
104
- let objOut = pseudoLocalizeObject(objIn);
105
- fs.writeFileSync(outputFileName, JSON.stringify(objOut, null, 2));
106
- }
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
+ /** Generates pseudo localization files from the en localization JSON files.
8
+ */
9
+ function pseudoLocalizeObject(objIn) {
10
+ let objOut = {};
11
+ for (let prop in objIn) {
12
+ if (objIn.hasOwnProperty(prop)) {
13
+ if (typeof objIn[prop] === "string") {
14
+ objOut[prop] = pseudoLocalize(objIn[prop])
15
+ } else if (typeof objIn[prop] === "object") {
16
+ objOut[prop] = pseudoLocalizeObject(objIn[prop])
17
+ }
18
+ }
19
+ }
20
+ return objOut;
21
+ }
22
+
23
+ const replacements = {
24
+ A: "\u00C0\u00C1,\u00C2\u00C3,\u00C4\u00C5",
25
+ a: "\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5",
26
+ B: "\u00DF",
27
+ c: "\u00A2\u00E7",
28
+ C: "\u00C7\u0028",
29
+ D: "\u00D0",
30
+ E: "\u00C8\u00C9\u00CA\u00CB",
31
+ e: "\u00E8\u00E9\u00EA\u00EB",
32
+ I: "\u00CC\u00CD\u00CE\u00CF",
33
+ i: "\u00EC\u00ED\u00EE\u00EF",
34
+ L: "\u00A3",
35
+ N: "\u00D1",
36
+ n: "\u00F1",
37
+ O: "\u00D2\u00D3\u00D4\u00D5\u00D6",
38
+ o: "\u00F2\u00F3\u00F4\u00F5\u00F6\u00F8",
39
+ S: "\u0024\u00A7",
40
+ U: "\u00D9\u00DA\u00DB\u00DC",
41
+ u: "\u00B5\u00F9\u00FA\u00FB\u00FC",
42
+ x: "\u00D7",
43
+ Y: "\u00DD\u00A5",
44
+ y: "\u00FD\u00FF",
45
+ };
46
+
47
+ /** PseudoLocalizes a single string */
48
+ function pseudoLocalize(inputString) {
49
+ let inReplace = 0;
50
+ let outString = "";
51
+ let replaceIndex = 0; // Note: the pseudoLocalize algorithm would normally use random, but here we cycle through because Javascript doesn't allow setting of the seed for Math.random.
52
+ for (let iChar = 0; iChar < inputString.length; iChar++) {
53
+ let thisChar = inputString.charAt(iChar);
54
+ let nextChar = ((iChar + 1) < inputString.length) ? inputString.charAt(iChar + 1) : 0;
55
+
56
+ // handle the {{ and }} delimiters for placeholders - don't want to do anything to characters in between.
57
+ if (('{' === thisChar) && ('{' === nextChar)) {
58
+ inReplace++;
59
+ iChar++;
60
+ outString = outString.concat("{{");
61
+ } else if (('}' === thisChar) && ('}' === nextChar) && (inReplace > 0)) {
62
+ inReplace--;
63
+ iChar++;
64
+ outString = outString.concat("}}");
65
+ } else {
66
+ let replacementChar = thisChar;
67
+ if (0 === inReplace) {
68
+ let replacementsForChar = replacements[thisChar];
69
+ if (undefined !== replacementsForChar) {
70
+ replacementChar = replacementsForChar.charAt(replaceIndex++ % replacementsForChar.length);
71
+ }
72
+ }
73
+ outString = outString.concat(replacementChar);
74
+ }
75
+ }
76
+ return outString;
77
+ }
78
+
79
+ function isJsonFile(fileName) {
80
+ return fileName.endsWith(".json");
81
+ }
82
+
83
+ const argv = require("yargs").argv;
84
+ const paths = require("./config/paths");
85
+ const fs = require("fs-extra");
86
+ const path = require("path");
87
+
88
+ const englishDir = (argv.englishDir === undefined) ? paths.appLocalesEnglish : argv.englishDir;
89
+ const inputFileNames = fs.readdirSync(englishDir).filter(isJsonFile);
90
+ const outDir = (argv.out === undefined) ? paths.appLocalesPseudolocalize : argv.out;
91
+ try {
92
+ fs.mkdirpSync(outDir);
93
+ } catch (e) {
94
+ console.log(e);// do nothing
95
+ }
96
+
97
+ for (const inputFileName of inputFileNames) {
98
+ const inputFilePath = path.join(englishDir, inputFileName);
99
+ const outputFileName = path.join(outDir, inputFileName);
100
+
101
+ let jsonIn = fs.readFileSync(inputFilePath, { encoding: "utf8" });
102
+ let objIn = JSON.parse(jsonIn);
103
+
104
+ let objOut = pseudoLocalizeObject(objIn);
105
+ fs.writeFileSync(outputFileName, JSON.stringify(objOut, null, 2));
106
+ }
@@ -1,39 +1,39 @@
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
- function logBuildWarning(msg) {
6
- if (process.env.TF_BUILD)
7
- console.error("##vso[task.logissue type=warning;]%s", msg);
8
- else
9
- console.error("WARNING: %s", msg);
10
- }
11
-
12
- function logBuildError(msg) {
13
- if (process.env.TF_BUILD)
14
- console.error("##vso[task.logissue type=error;]%s", msg);
15
- else
16
- console.error("ERROR: %s", msg);
17
- }
18
-
19
- function failBuild() {
20
- if (process.env.TF_BUILD) {
21
- console.error("##vso[task.complete result=Failed;]DONE")
22
- process.exit(0);
23
- } else {
24
- process.exit(1);
25
- }
26
- }
27
-
28
- function throwAfterTimeout(timeout, message) {
29
- return new Promise((_resolve, reject) => {
30
- setTimeout(() => reject(message), timeout);
31
- });
32
- }
33
-
34
- module.exports = {
35
- logBuildWarning,
36
- logBuildError,
37
- failBuild,
38
- throwAfterTimeout
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
+ function logBuildWarning(msg) {
6
+ if (process.env.TF_BUILD)
7
+ console.error("##vso[task.logissue type=warning;]%s", msg);
8
+ else
9
+ console.error("WARNING: %s", msg);
10
+ }
11
+
12
+ function logBuildError(msg) {
13
+ if (process.env.TF_BUILD)
14
+ console.error("##vso[task.logissue type=error;]%s", msg);
15
+ else
16
+ console.error("ERROR: %s", msg);
17
+ }
18
+
19
+ function failBuild() {
20
+ if (process.env.TF_BUILD) {
21
+ console.error("##vso[task.complete result=Failed;]DONE")
22
+ process.exit(0);
23
+ } else {
24
+ process.exit(1);
25
+ }
26
+ }
27
+
28
+ function throwAfterTimeout(timeout, message) {
29
+ return new Promise((_resolve, reject) => {
30
+ setTimeout(() => reject(message), timeout);
31
+ });
32
+ }
33
+
34
+ module.exports = {
35
+ logBuildWarning,
36
+ logBuildError,
37
+ failBuild,
38
+ throwAfterTimeout
39
39
  }
@@ -1,86 +1,86 @@
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 spawn = require("cross-spawn");
7
- const chalk = require("chalk");
8
- const kill = require("tree-kill");
9
-
10
- function simpleSpawn(cmd, args, cwd, env = {}) {
11
- if (!cwd)
12
- cwd = process.cwd();
13
-
14
- return new Promise((resolve) => {
15
- const child = spawn(cmd, args, {
16
- cwd: cwd,
17
- env: { FORCE_COLOR: "1", ...env, ...process.env },
18
- stdio: "pipe"
19
- });
20
-
21
- child.stdout.on("data", (data) => {
22
- process.stdout.write(data);
23
- })
24
- child.stderr.on("data", (data) => {
25
- process.stderr.write(data);
26
- })
27
- child.on("error", function (data) { console.log(chalk.red(data)); });
28
- child.on("close", (code) => resolve(code));
29
- simpleSpawn.children.push(child);
30
- });
31
- }
32
-
33
- function simpleSpawnSync(cmd, args, cwd, env = {}) {
34
- if (!cwd)
35
- cwd = process.cwd();
36
-
37
- const child = spawn.sync(cmd, args, {
38
- cwd: cwd,
39
- env: { FORCE_COLOR: "1", ...env, ...process.env },
40
- stdio: "inherit"
41
- });
42
-
43
- if (child.status !== 0) {
44
- process.exit(child.status);
45
- }
46
- }
47
-
48
- simpleSpawn.children = [];
49
- simpleSpawn.killAll = async function () {
50
- const promises = [];
51
- simpleSpawn.children.forEach((proc) => {
52
- promises.push(new Promise((resolve) => {
53
- kill(proc.pid, undefined, resolve);
54
- }));
55
- });
56
- await Promise.all(promises);
57
- }
58
-
59
- function handleInterrupts(callback) {
60
- if (!callback) {
61
- callback = async () => {
62
- await simpleSpawn.killAll();
63
- process.exit();
64
- };
65
- }
66
-
67
- if (process.platform === "win32") {
68
- require("readline")
69
- .createInterface({
70
- input: process.stdin,
71
- output: process.stdout
72
- });
73
- }
74
-
75
- ["SIGINT", "SIGTERM"].forEach(function (sig) {
76
- process.on(sig, function () {
77
- callback();
78
- });
79
- });
80
- }
81
-
82
- module.exports = {
83
- spawn: simpleSpawn,
84
- spawnSync: simpleSpawnSync,
85
- 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
+
6
+ const spawn = require("cross-spawn");
7
+ const chalk = require("chalk");
8
+ const kill = require("tree-kill");
9
+
10
+ function simpleSpawn(cmd, args, cwd, env = {}) {
11
+ if (!cwd)
12
+ cwd = process.cwd();
13
+
14
+ return new Promise((resolve) => {
15
+ const child = spawn(cmd, args, {
16
+ cwd: cwd,
17
+ env: { FORCE_COLOR: "1", ...env, ...process.env },
18
+ stdio: "pipe"
19
+ });
20
+
21
+ child.stdout.on("data", (data) => {
22
+ process.stdout.write(data);
23
+ })
24
+ child.stderr.on("data", (data) => {
25
+ process.stderr.write(data);
26
+ })
27
+ child.on("error", function (data) { console.log(chalk.red(data)); });
28
+ child.on("close", (code) => resolve(code));
29
+ simpleSpawn.children.push(child);
30
+ });
31
+ }
32
+
33
+ function simpleSpawnSync(cmd, args, cwd, env = {}) {
34
+ if (!cwd)
35
+ cwd = process.cwd();
36
+
37
+ const child = spawn.sync(cmd, args, {
38
+ cwd: cwd,
39
+ env: { FORCE_COLOR: "1", ...env, ...process.env },
40
+ stdio: "inherit"
41
+ });
42
+
43
+ if (child.status !== 0) {
44
+ process.exit(child.status);
45
+ }
46
+ }
47
+
48
+ simpleSpawn.children = [];
49
+ simpleSpawn.killAll = async function () {
50
+ const promises = [];
51
+ simpleSpawn.children.forEach((proc) => {
52
+ promises.push(new Promise((resolve) => {
53
+ kill(proc.pid, undefined, resolve);
54
+ }));
55
+ });
56
+ await Promise.all(promises);
57
+ }
58
+
59
+ function handleInterrupts(callback) {
60
+ if (!callback) {
61
+ callback = async () => {
62
+ await simpleSpawn.killAll();
63
+ process.exit();
64
+ };
65
+ }
66
+
67
+ if (process.platform === "win32") {
68
+ require("readline")
69
+ .createInterface({
70
+ input: process.stdin,
71
+ output: process.stdout
72
+ });
73
+ }
74
+
75
+ ["SIGINT", "SIGTERM"].forEach(function (sig) {
76
+ process.on(sig, function () {
77
+ callback();
78
+ });
79
+ });
80
+ }
81
+
82
+ module.exports = {
83
+ spawn: simpleSpawn,
84
+ spawnSync: simpleSpawnSync,
85
+ handleInterrupts
86
86
  };