pdm-ts 0.0.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/README.md +31 -0
- package/dist/index.js +2 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# pm-ts
|
|
2
|
+
|
|
3
|
+
Convert PDM files to TypeScript types via CLI
|
|
4
|
+
|
|
5
|
+
# install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install pdm-ts
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
# config
|
|
12
|
+
|
|
13
|
+
`pdm2type.json`
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"pdmPath": "./demo.pdm",
|
|
18
|
+
"output": "./",
|
|
19
|
+
"date2string": true,
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
- `pdmPath`: For the `.pdm` file path, absoute path are recommended.
|
|
24
|
+
- `output` : Output directory for generated the `.ts` file.
|
|
25
|
+
- `date2string`: If set to true, data of types such as time and Date from the database will be converted to string; otherwise, they will remain Date objects (default false),
|
|
26
|
+
|
|
27
|
+
# use
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
npm run pdm-ts
|
|
31
|
+
```
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const{XMLParser:e}=require("fast-xml-parser"),t=require("path"),r=require("fs");let n=!1;const a=(e=[])=>{let t="";return e.forEach(e=>{const r=e["a:Code"],a=e["a:Name"],s=e["c:Columns"]["o:Column"];r&&a&&s&&(t+=function(e,t,r){const a=Array.isArray(r)?r:r?[r]:[];if(0===a.length)return"";const s=a.map(e=>{const t=e["a:Code"],r=e["a:Name"],a=e["a:DataType"],s=a?function(e){const t=e.toLowerCase();return/varchar|char|text|nchar|nvarchar|ntext/.test(t)?"string":/int|bigint|smallint|tinyint|numeric|decimal|float|real/.test(t)?"number":/bit|boolean/.test(t)?"boolean":/datetime|date|time|timestamp/.test(t)?n?"string":"Date":"any"}(a):"any";return` //${o=r,o?o.replace(/\s*\n\s*/g," ").trim():""}\n ${t}: ${s};`;var o});return` /** ${e} */\n export interface ${t} {\n${s.join("\n")}\n}\n`}(a,r,s))}),t};const s=(e,n,a)=>{if(a){const s=+Date.now()+"",o=t.resolve(e,`${n}-${s.slice(-8)}.type.ts`);r.writeFileSync(o,a,"utf-8")}};(()=>{try{const o=process.cwd(),i=t.resolve(o,"./pdm2ts.json"),c=r.readFileSync(i,"utf-8"),l=JSON.parse(c),u=t.resolve(o,l.pdmPath),m=t.resolve(o,l.output);n=!!l.dateIsAny;const d=r.readFileSync(u,"utf8"),p=new e({ignoreAttributes:!1,attributeNamePrefix:"@_",parseAttributeValue:!0,trimValues:!0}).parse(d),f=p.Model["o:RootObject"],y=f["c:Children"]["o:Model"],b=y["a:Code"],h=y["c:Tables"]["o:Table"],v=a(h);s(m,b,v)}catch(e){}})();
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pdm-ts",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Convert PDM files to TypeScript types via CLI",
|
|
5
|
+
"main": "./dist/index",
|
|
6
|
+
"bin": {
|
|
7
|
+
"pdm-ts": "dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "rollup -c",
|
|
11
|
+
"prepublishOnly": "npm run build"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"keywords": [
|
|
17
|
+
"pdm",
|
|
18
|
+
"typescript",
|
|
19
|
+
"type-generator",
|
|
20
|
+
"cli"
|
|
21
|
+
],
|
|
22
|
+
"author": "",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"fast-xml-parser": "^5.9.3"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@rollup/plugin-commonjs": "^29.0.3",
|
|
29
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
30
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
31
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
32
|
+
"@types/node": "^26.0.1",
|
|
33
|
+
"tslib": "^2.8.1",
|
|
34
|
+
"typescript": "^6.0.3"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/jyp114110/pdm-ts.git"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/jyp114110/pdm-ts#readme",
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/jyp114110/pdm-ts/issues"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"registry": "https://registry.npmjs.org/"
|
|
46
|
+
}
|
|
47
|
+
}
|