cddl2ts 0.3.1 → 0.4.1
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/.release-it.ts +14 -0
- package/LICENSE +1 -1
- package/README.md +5 -9
- package/changelogithub.config.ts +6 -0
- package/cli-examples/local.ts +1013 -0
- package/cli-examples/remote.ts +1520 -0
- package/cli-examples/tsconfig.json +12 -0
- package/package.json +18 -34
- package/src/cli.ts +42 -0
- package/src/constants.ts +6 -0
- package/src/index.ts +652 -0
- package/src/utils.ts +61 -0
- package/tests/__snapshots__/group_choice.test.ts.snap +72 -0
- package/tests/__snapshots__/literals.test.ts.snap +8 -0
- package/tests/__snapshots__/mixin_union.test.ts.snap +19 -0
- package/tests/__snapshots__/mod.test.ts.snap +102 -0
- package/tests/__snapshots__/repro_proxy.test.ts.snap +14 -0
- package/tests/__snapshots__/union_extension.test.ts.snap +18 -0
- package/tests/__snapshots__/webdriver_local.test.ts.snap +1017 -0
- package/tests/__snapshots__/webdriver_remote.test.ts.snap +1524 -0
- package/tests/complex_types.test.ts +54 -0
- package/tests/group_choice.test.ts +53 -0
- package/tests/literals.test.ts +45 -0
- package/tests/mixin_union.test.ts +56 -0
- package/tests/mod.test.ts +74 -0
- package/tests/named_group_choice.test.ts +47 -0
- package/tests/transform.test.ts +21 -0
- package/tests/unknown.test.ts +51 -0
- package/tests/webdriver_local.test.ts +43 -0
- package/tests/webdriver_remote.test.ts +43 -0
- package/tsconfig.json +11 -0
package/package.json
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cddl2ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "A Node.js package that can generate a TypeScript definition based on a CDDL file",
|
|
5
5
|
"author": "Christian Bromann <mail@bromann.dev>",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"homepage": "https://github.com/
|
|
7
|
+
"homepage": "https://github.com/webdriverio/cddl/blob/main/packages/cddl2ts/README.md",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git+ssh://git@github.com/
|
|
10
|
+
"url": "git+ssh://git@github.com/webdriverio/cddl.git"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|
|
13
|
-
"cddl"
|
|
13
|
+
"cddl",
|
|
14
|
+
"typescript",
|
|
15
|
+
"javascript"
|
|
14
16
|
],
|
|
15
|
-
"engines": {
|
|
16
|
-
"node": ">=20.0.0",
|
|
17
|
-
"npm": ">=9.0.0"
|
|
18
|
-
},
|
|
19
17
|
"bugs": {
|
|
20
|
-
"url": "https://github.com/
|
|
18
|
+
"url": "https://github.com/webdriverio/cddl/issues"
|
|
21
19
|
},
|
|
22
20
|
"type": "module",
|
|
23
21
|
"exports": "./build/index.js",
|
|
@@ -25,36 +23,22 @@
|
|
|
25
23
|
"bin": {
|
|
26
24
|
"cddl2ts": "./bin/cddl2ts.js"
|
|
27
25
|
},
|
|
28
|
-
"scripts": {
|
|
29
|
-
"build": "run-s clean compile",
|
|
30
|
-
"clean": "rm -rf ./build ./coverage",
|
|
31
|
-
"compile": "tsc -p ./tsconfig.json",
|
|
32
|
-
"release": "release-it --github.release",
|
|
33
|
-
"release:ci": "npm run release -- --ci --npm.skipChecks --no-git.requireCleanWorkingDir",
|
|
34
|
-
"release:patch": "npm run release -- patch",
|
|
35
|
-
"release:minor": "npm run release -- minor",
|
|
36
|
-
"release:major": "npm run release -- major",
|
|
37
|
-
"generate:local": "npm run compile && node ./bin/cddl2ts.js ./examples/webdriver/local.cddl --unknown-as-any > ./examples/webdriver/local.ts && tsc -p ./examples/webdriver/tsconfig.json",
|
|
38
|
-
"generate:remote": "npm run compile && node ./bin/cddl2ts.js ./examples/webdriver/remote.cddl --unknown-as-any > ./examples/webdriver/remote.ts && tsc -p ./examples/webdriver/tsconfig.json",
|
|
39
|
-
"generate:examples": "npm run generate:local && npm run generate:remote",
|
|
40
|
-
"test": "vitest run",
|
|
41
|
-
"watch": "tsc --watch",
|
|
42
|
-
"checks:all": "npm run compile && npm run test && npm run generate:examples"
|
|
43
|
-
},
|
|
44
26
|
"devDependencies": {
|
|
45
27
|
"@types/yargs": "^17.0.35",
|
|
46
|
-
"@types/node": "^
|
|
47
|
-
"@vitest/coverage-v8": "^4.1.0",
|
|
48
|
-
"npm-run-all": "^4.1.5",
|
|
49
|
-
"release-it": "^19.2.4",
|
|
50
|
-
"typescript": "^5.9.3",
|
|
51
|
-
"vitest": "^4.1.0"
|
|
28
|
+
"@types/node": "^25.5.0"
|
|
52
29
|
},
|
|
53
30
|
"dependencies": {
|
|
54
31
|
"@babel/parser": "^7.29.0",
|
|
55
32
|
"camelcase": "^9.0.0",
|
|
56
|
-
"cddl": "^0.13.1",
|
|
57
33
|
"recast": "^0.23.11",
|
|
58
|
-
"yargs": "^18.0.0"
|
|
34
|
+
"yargs": "^18.0.0",
|
|
35
|
+
"cddl": "0.14.5"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"release": "release-it --config .release-it.ts",
|
|
39
|
+
"release:ci": "pnpm release --ci --npm.skipChecks",
|
|
40
|
+
"cli-examples": "run-p cli-examples:*",
|
|
41
|
+
"cli-examples:local": "pnpm run compile && node ./bin/cddl2ts.js ../../examples/webdriver/local.cddl --unknown-as-any > ./cli-examples/local.ts && tsc -p ./cli-examples/tsconfig.json",
|
|
42
|
+
"cli-examples:remote": "pnpm run compile && node ./bin/cddl2ts.js ../../examples/webdriver/remote.cddl --unknown-as-any > ./cli-examples/remote.ts && tsc -p ./cli-examples/tsconfig.json"
|
|
59
43
|
}
|
|
60
|
-
}
|
|
44
|
+
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import fs from 'node:fs/promises'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import yargs from 'yargs'
|
|
4
|
+
|
|
5
|
+
import { parse } from 'cddl'
|
|
6
|
+
|
|
7
|
+
import { transform } from './index.js'
|
|
8
|
+
import { pkg } from './constants.js'
|
|
9
|
+
|
|
10
|
+
export default async function cli (argv = process.argv.slice(2)) {
|
|
11
|
+
const parser = yargs(argv)
|
|
12
|
+
.usage(`${pkg.name}\n${pkg.description}\n\nUsage:\nrunme2ts ./path/to/spec.cddl &> ./path/to/interface.ts`)
|
|
13
|
+
.epilog(`v${pkg.version}\nCopyright ${(new Date()).getFullYear()} ${pkg.author}`)
|
|
14
|
+
.version(pkg.version)
|
|
15
|
+
.option('u', {
|
|
16
|
+
alias: 'unknown-as-any',
|
|
17
|
+
type: 'boolean',
|
|
18
|
+
description: 'Use unknown instead of any',
|
|
19
|
+
default: false
|
|
20
|
+
})
|
|
21
|
+
.help('help')
|
|
22
|
+
.alias('h', 'help')
|
|
23
|
+
.alias('v', 'version')
|
|
24
|
+
|
|
25
|
+
const args = await parser.argv
|
|
26
|
+
|
|
27
|
+
if (args._.length === 0) {
|
|
28
|
+
parser.showHelp()
|
|
29
|
+
return process.exit(0)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const absoluteFilePath = path.resolve(process.cwd(), args._[0] as string)
|
|
33
|
+
const hasAccess = await fs.access(absoluteFilePath).then(() => true, () => false)
|
|
34
|
+
|
|
35
|
+
if (!hasAccess) {
|
|
36
|
+
console.error(`Couldn't find or access source CDDL file at "${absoluteFilePath}"`)
|
|
37
|
+
return process.exit(1)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const ast = parse(absoluteFilePath)
|
|
41
|
+
console.log(transform(ast, { useUnknown: args.u as boolean }))
|
|
42
|
+
}
|
package/src/constants.ts
ADDED