@uxf/data-grid 11.0.0-beta.18 → 11.0.0-beta.19
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/_generator/cli.js +4 -3
- package/_generator/index.js +29 -13
- package/package.json +1 -1
package/_generator/cli.js
CHANGED
|
@@ -8,19 +8,20 @@ Usage:
|
|
|
8
8
|
uxf-data-grid-generator [options]
|
|
9
9
|
`);
|
|
10
10
|
})
|
|
11
|
-
.option("s", { alias: "
|
|
11
|
+
.option("s", { alias: "schemaDirectory" })
|
|
12
|
+
.option("o", { alias: "outputDirectory" })
|
|
12
13
|
.option("h", { alias: "help", group: "Options" })
|
|
13
14
|
.strict(false)
|
|
14
15
|
.exitProcess(false);
|
|
15
16
|
|
|
16
17
|
try {
|
|
17
|
-
const { help,
|
|
18
|
+
const { help, schemaDirectory, outputDirectory } = cli.parse(argv.slice(2));
|
|
18
19
|
|
|
19
20
|
if (Boolean(help)) {
|
|
20
21
|
return 0;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
await require("./index")(
|
|
24
|
+
await require("./index")(schemaDirectory, outputDirectory);
|
|
24
25
|
} catch (e) {
|
|
25
26
|
console.error(e);
|
|
26
27
|
return 1;
|
package/_generator/index.js
CHANGED
|
@@ -1,24 +1,40 @@
|
|
|
1
1
|
const { globSync } = require("fast-glob");
|
|
2
|
-
const { readFileSync, writeFileSync } = require("fs");
|
|
3
|
-
const { dirname } = require("path");
|
|
2
|
+
const { readFileSync, writeFileSync, mkdirSync } = require("fs");
|
|
3
|
+
const { dirname, relative, parse, join } = require("path");
|
|
4
4
|
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
function camelize(value) {
|
|
6
|
+
return value
|
|
7
|
+
.split("-")
|
|
8
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
9
|
+
.join("");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function writeFile(filename, value) {
|
|
13
|
+
mkdirSync(dirname(filename), { recursive: true });
|
|
14
|
+
writeFileSync(filename, value);
|
|
15
|
+
}
|
|
8
16
|
|
|
9
|
-
|
|
17
|
+
function generateSchemaFile(gridName, schemaRelativeImport) {
|
|
18
|
+
return `import { Schema } from "@uxf/data-grid";
|
|
19
|
+
import json from "${schemaRelativeImport}";
|
|
10
20
|
|
|
11
|
-
|
|
21
|
+
export const dataGridSchema_${camelize(gridName)}: Schema<any> = json as any;`;
|
|
12
22
|
}
|
|
13
23
|
|
|
14
|
-
function generate(jsonSchema, filename) {
|
|
15
|
-
const
|
|
24
|
+
function generate(jsonSchema, filename, outputDirectory) {
|
|
25
|
+
const gridName = parse(filename).name;
|
|
26
|
+
const generatedPath = join(process.cwd(), outputDirectory, gridName);
|
|
27
|
+
|
|
28
|
+
const generatedSchemaFilename = `${generatedPath}/schema.ts`;
|
|
16
29
|
|
|
17
|
-
|
|
30
|
+
writeFile(
|
|
31
|
+
generatedSchemaFilename,
|
|
32
|
+
generateSchemaFile(gridName, relative(dirname(generatedSchemaFilename), filename)),
|
|
33
|
+
);
|
|
18
34
|
}
|
|
19
35
|
|
|
20
|
-
module.exports = (
|
|
21
|
-
globSync(
|
|
36
|
+
module.exports = (schemaDirectory, outputDirectory) => {
|
|
37
|
+
globSync(schemaDirectory + "/*.json")
|
|
22
38
|
.map((path) => process.cwd() + "/" + path)
|
|
23
|
-
.forEach((filename) => generate(readFileSync(filename), filename));
|
|
39
|
+
.forEach((filename) => generate(readFileSync(filename), filename, outputDirectory));
|
|
24
40
|
};
|