@cosmwasm/ts-codegen 1.12.1 → 1.13.0
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 +108 -117
- package/builder/builder.js +26 -24
- package/bundler/bundler.js +27 -17
- package/cli.js +2 -2
- package/commands/create-boilerplate.js +29 -18
- package/commands/generate.js +26 -35
- package/commands/install.js +22 -18
- package/esm/builder/builder.js +10 -18
- package/esm/bundler/bundler.js +10 -10
- package/esm/cli.js +2 -2
- package/esm/commands/create-boilerplate.js +11 -10
- package/esm/commands/generate.js +26 -35
- package/esm/commands/install.js +23 -19
- package/esm/file.js +4 -3
- package/esm/plugins/client.js +1 -1
- package/esm/plugins/message-builder.js +4 -4
- package/esm/plugins/message-composer.js +1 -1
- package/esm/plugins/plugin-base.js +3 -2
- package/esm/plugins/provider-bundle.js +1 -1
- package/esm/plugins/provider.js +1 -1
- package/esm/plugins/react-query.js +8 -7
- package/esm/plugins/recoil.js +4 -4
- package/esm/plugins/types.js +3 -3
- package/esm/ts-codegen.js +2 -1
- package/esm/utils/clean.js +1 -1
- package/esm/utils/cleanse.js +9 -5
- package/esm/utils/package.js +1 -1
- package/esm/utils/parse.js +5 -7
- package/esm/utils/prompt.js +2 -2
- package/esm/utils/schemas.js +32 -19
- package/esm/utils/unused.js +3 -4
- package/file.js +7 -3
- package/package.json +13 -13
- package/plugins/client.js +18 -8
- package/plugins/message-builder.js +20 -10
- package/plugins/message-composer.js +18 -8
- package/plugins/plugin-base.js +19 -8
- package/plugins/provider-bundle.js +17 -7
- package/plugins/provider.js +17 -7
- package/plugins/react-query.js +24 -13
- package/plugins/recoil.js +20 -10
- package/plugins/types.js +19 -9
- package/ts-codegen.js +5 -1
- package/utils/clean.js +1 -1
- package/utils/cleanse.d.ts +1 -0
- package/utils/cleanse.js +12 -7
- package/utils/files.js +17 -7
- package/utils/package.js +2 -3
- package/utils/parse.js +5 -7
- package/utils/prompt.js +2 -2
- package/utils/schemas.d.ts +5 -1
- package/utils/schemas.js +34 -20
- package/utils/unused.js +20 -11
package/esm/commands/generate.js
CHANGED
@@ -7,38 +7,33 @@ export default async (argv) => {
|
|
7
7
|
type: 'path',
|
8
8
|
name: 'schema',
|
9
9
|
message: 'which directory contains the the Rust contracts?',
|
10
|
-
default: './schema'
|
10
|
+
default: './schema',
|
11
11
|
},
|
12
12
|
{
|
13
13
|
_: true,
|
14
14
|
type: 'path',
|
15
15
|
name: 'out',
|
16
16
|
message: 'where is the output directory?',
|
17
|
-
default: './ts'
|
17
|
+
default: './ts',
|
18
18
|
},
|
19
19
|
{
|
20
20
|
_: true,
|
21
21
|
type: 'string',
|
22
22
|
name: 'name',
|
23
|
-
message: 'contract name?'
|
23
|
+
message: 'contract name?',
|
24
24
|
},
|
25
25
|
{
|
26
26
|
type: 'checkbox',
|
27
27
|
name: 'plugin',
|
28
28
|
message: 'which plugins?',
|
29
|
-
choices: [
|
30
|
-
'client',
|
31
|
-
'recoil',
|
32
|
-
'react-query',
|
33
|
-
'message-composer'
|
34
|
-
]
|
29
|
+
choices: ['client', 'recoil', 'react-query', 'message-composer'],
|
35
30
|
},
|
36
31
|
{
|
37
32
|
type: 'confirm',
|
38
33
|
name: 'bundle',
|
39
34
|
message: 'enable bundle?',
|
40
|
-
default: true
|
41
|
-
}
|
35
|
+
default: true,
|
36
|
+
},
|
42
37
|
];
|
43
38
|
if (argv.typesOnly) {
|
44
39
|
argv.plugin = 'types';
|
@@ -55,24 +50,23 @@ export default async (argv) => {
|
|
55
50
|
type: 'confirm',
|
56
51
|
name: 'optionalClient',
|
57
52
|
message: 'optionalClient?',
|
58
|
-
default: false
|
53
|
+
default: false,
|
59
54
|
},
|
60
55
|
{
|
61
56
|
type: 'list',
|
62
57
|
name: 'version',
|
63
58
|
message: 'which react-query version?',
|
64
59
|
default: 'v4',
|
65
|
-
choices: ['v3', 'v4']
|
60
|
+
choices: ['v3', 'v4'],
|
66
61
|
},
|
67
62
|
{
|
68
63
|
type: 'confirm',
|
69
64
|
name: 'queryKeys',
|
70
65
|
message: 'queryKeys?',
|
71
|
-
default: false
|
66
|
+
default: false,
|
72
67
|
},
|
73
68
|
]);
|
74
69
|
}
|
75
|
-
;
|
76
70
|
const { optionalClient, version, queryKeys } = await prompt(questions2, argv);
|
77
71
|
const questions3 = [];
|
78
72
|
if (version === 'v4') {
|
@@ -82,11 +76,10 @@ export default async (argv) => {
|
|
82
76
|
type: 'confirm',
|
83
77
|
name: 'mutations',
|
84
78
|
message: 'Generate useMutation hooks?',
|
85
|
-
default: false
|
86
|
-
}
|
79
|
+
default: false,
|
80
|
+
},
|
87
81
|
]);
|
88
82
|
}
|
89
|
-
;
|
90
83
|
const { mutations } = await prompt(questions3, argv);
|
91
84
|
const queryFactoryQuestions = [];
|
92
85
|
if (queryKeys) {
|
@@ -96,11 +89,10 @@ export default async (argv) => {
|
|
96
89
|
type: 'confirm',
|
97
90
|
name: 'queryFactory',
|
98
91
|
message: 'queryFactory? ',
|
99
|
-
default: false
|
100
|
-
}
|
92
|
+
default: false,
|
93
|
+
},
|
101
94
|
]);
|
102
95
|
}
|
103
|
-
;
|
104
96
|
const { queryFactory } = await prompt(queryFactoryQuestions, argv);
|
105
97
|
///////// END REACT QUERY
|
106
98
|
///////// BUNDLE
|
@@ -111,27 +103,26 @@ export default async (argv) => {
|
|
111
103
|
type: 'string',
|
112
104
|
name: 'bundleFile',
|
113
105
|
message: 'bundleFile?',
|
114
|
-
default: 'index.ts'
|
106
|
+
default: 'index.ts',
|
115
107
|
},
|
116
108
|
{
|
117
109
|
type: 'string',
|
118
110
|
name: 'bundleScope',
|
119
111
|
message: 'bundleScope?',
|
120
|
-
default: 'contracts'
|
121
|
-
}
|
112
|
+
default: 'contracts',
|
113
|
+
},
|
122
114
|
]);
|
123
115
|
}
|
124
|
-
;
|
125
116
|
const { bundleFile, bundleScope } = await prompt(questions4, argv);
|
126
117
|
///////// END BUNDLE
|
127
118
|
const options = {
|
128
119
|
types: {
|
129
|
-
enabled: true
|
120
|
+
enabled: true,
|
130
121
|
},
|
131
122
|
client: {
|
132
123
|
enabled: plugin.includes('client') ||
|
133
124
|
plugin.includes('recoil') ||
|
134
|
-
plugin.includes('react-query')
|
125
|
+
plugin.includes('react-query'),
|
135
126
|
},
|
136
127
|
reactQuery: {
|
137
128
|
enabled: plugin.includes('react-query'),
|
@@ -139,31 +130,31 @@ export default async (argv) => {
|
|
139
130
|
queryKeys,
|
140
131
|
version,
|
141
132
|
mutations,
|
142
|
-
queryFactory
|
133
|
+
queryFactory,
|
143
134
|
},
|
144
135
|
recoil: {
|
145
136
|
enabled: plugin.includes('recoil'),
|
146
137
|
},
|
147
138
|
messageComposer: {
|
148
|
-
enabled: plugin.includes('message-composer')
|
139
|
+
enabled: plugin.includes('message-composer'),
|
149
140
|
},
|
150
141
|
messageBuilder: {
|
151
|
-
enabled: plugin.includes('message-builder')
|
142
|
+
enabled: plugin.includes('message-builder'),
|
152
143
|
},
|
153
144
|
bundle: {
|
154
145
|
enabled: bundle,
|
155
146
|
scope: bundleScope,
|
156
|
-
bundleFile
|
157
|
-
}
|
147
|
+
bundleFile,
|
148
|
+
},
|
158
149
|
};
|
159
150
|
await codegen({
|
160
151
|
contracts: [
|
161
152
|
{
|
162
153
|
name,
|
163
|
-
dir: schema
|
164
|
-
}
|
154
|
+
dir: schema,
|
155
|
+
},
|
165
156
|
],
|
166
157
|
outPath: out,
|
167
|
-
options
|
158
|
+
options,
|
168
159
|
});
|
169
160
|
};
|
package/esm/commands/install.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { readFileSync, writeFileSync } from 'fs';
|
2
|
-
import {
|
2
|
+
import { globSync as glob } from 'glob';
|
3
3
|
import { sync as mkdirp } from 'mkdirp';
|
4
4
|
import { tmpdir } from 'os';
|
5
5
|
import { parse } from 'parse-package-name';
|
@@ -11,10 +11,12 @@ const TMPDIR = tmpdir();
|
|
11
11
|
const rnd = () => Math.random().toString(36).substring(2, 15) +
|
12
12
|
Math.random().toString(36).substring(2, 15);
|
13
13
|
const getPackages = (names) => {
|
14
|
-
return names
|
14
|
+
return names
|
15
|
+
.map((pkg) => {
|
15
16
|
const { name, version } = parse(pkg);
|
16
17
|
return `${name}@${version}`;
|
17
|
-
})
|
18
|
+
})
|
19
|
+
.join(' ');
|
18
20
|
};
|
19
21
|
export default async (argv) => {
|
20
22
|
// don't prompt if we got this...
|
@@ -27,7 +29,7 @@ export default async (argv) => {
|
|
27
29
|
try {
|
28
30
|
thisPackage = JSON.parse(readFileSync(join(cur, 'package.json'), 'utf-8'));
|
29
31
|
}
|
30
|
-
catch
|
32
|
+
catch {
|
31
33
|
throw new Error('make sure you are inside of a telescope package!');
|
32
34
|
}
|
33
35
|
// what are we installing?
|
@@ -46,14 +48,14 @@ export default async (argv) => {
|
|
46
48
|
'stargaze-vending-factory',
|
47
49
|
'stargaze-vending-minter',
|
48
50
|
'stargaze-whitelist',
|
49
|
-
'wasmswap'
|
50
|
-
].map(name => {
|
51
|
+
'wasmswap',
|
52
|
+
].map((name) => {
|
51
53
|
return {
|
52
54
|
name,
|
53
|
-
value: `@cosmjson/${name}
|
55
|
+
value: `@cosmjson/${name}`,
|
54
56
|
};
|
55
|
-
})
|
56
|
-
}
|
57
|
+
}),
|
58
|
+
},
|
57
59
|
], argv);
|
58
60
|
// install
|
59
61
|
if (!Array.isArray(pkg))
|
@@ -63,26 +65,28 @@ export default async (argv) => {
|
|
63
65
|
process.chdir(tmp);
|
64
66
|
exec(`npm install ${getPackages(pkg)} --production --prefix ./smart-contracts`);
|
65
67
|
// protos
|
66
|
-
const pkgs = glob('./smart-contracts/**/package.json');
|
68
|
+
const pkgs = glob('./smart-contracts/**/package.json').sort();
|
67
69
|
const cmds = pkgs
|
68
|
-
.filter((f) => {
|
70
|
+
.filter((f) => {
|
71
|
+
return f !== './smart-contracts/package.json';
|
72
|
+
})
|
69
73
|
.map((f) => resolve(join(tmp, f)))
|
70
74
|
.map((conf) => {
|
71
75
|
const extDir = dirname(conf);
|
72
76
|
const dir = extDir.split('node_modules/')[1];
|
73
77
|
const dst = basename(dir);
|
74
|
-
const files = glob(`${extDir}/**/*`, { nodir: true });
|
75
|
-
files.forEach(f => {
|
76
|
-
if (extname(f) === '.json'
|
77
|
-
|
78
|
-
|
79
|
-
|
78
|
+
const files = glob(`${extDir}/**/*`, { nodir: true }).sort();
|
79
|
+
files.forEach((f) => {
|
80
|
+
if (extname(f) === '.json' ||
|
81
|
+
f === 'package.json' ||
|
82
|
+
/license/i.test(f) ||
|
83
|
+
/readme/i.test(f))
|
80
84
|
return;
|
81
85
|
rimraf(f);
|
82
86
|
});
|
83
87
|
return [extDir, resolve(join(cur, 'contracts', dst)), dir];
|
84
88
|
});
|
85
|
-
// move protos
|
89
|
+
// move protos
|
86
90
|
for (const [src, dst, pkg] of cmds) {
|
87
91
|
rimraf(dst);
|
88
92
|
console.log(`installing ${pkg}...`);
|
@@ -95,7 +99,7 @@ export default async (argv) => {
|
|
95
99
|
thisPackage.devDependencies = thisPackage.devDependencies ?? {};
|
96
100
|
thisPackage.devDependencies = {
|
97
101
|
...thisPackage.devDependencies,
|
98
|
-
...deps
|
102
|
+
...deps,
|
99
103
|
};
|
100
104
|
thisPackage.devDependencies = Object.fromEntries(Object.entries(thisPackage.devDependencies).sort());
|
101
105
|
writeFileSync(join(cur, 'package.json'), JSON.stringify(thisPackage, null, 2));
|
package/esm/file.js
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
import { readFileSync } from 'fs';
|
3
|
+
import minimist from 'minimist';
|
3
4
|
import { cli } from './cli';
|
4
5
|
import { prompt } from './utils/prompt';
|
5
|
-
const argv =
|
6
|
+
const argv = minimist(process.argv.slice(2));
|
6
7
|
const question = [
|
7
8
|
{
|
8
9
|
_: true,
|
9
10
|
type: 'string',
|
10
11
|
name: 'file',
|
11
|
-
message: 'file'
|
12
|
-
}
|
12
|
+
message: 'file',
|
13
|
+
},
|
13
14
|
];
|
14
15
|
(async () => {
|
15
16
|
const { file } = await prompt(question, argv);
|
package/esm/plugins/client.js
CHANGED
@@ -43,7 +43,7 @@ export class ClientPlugin extends BuilderPluginBase {
|
|
43
43
|
context.addProviderInfo(name, w.PROVIDER_TYPES.SIGNING_CLIENT_TYPE, Client, localname);
|
44
44
|
}
|
45
45
|
}
|
46
|
-
if (
|
46
|
+
if (Object.prototype.hasOwnProperty.call(typeHash, 'Coin')) {
|
47
47
|
// @ts-ignore
|
48
48
|
delete context.utils.Coin;
|
49
49
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as w from '@cosmwasm/ts-codegen-ast';
|
2
|
-
import { getMessageProperties, RenderContext } from '@cosmwasm/ts-codegen-ast';
|
2
|
+
import { getMessageProperties, RenderContext, } from '@cosmwasm/ts-codegen-ast';
|
3
3
|
import { pascal } from 'case';
|
4
4
|
import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils';
|
5
5
|
import { BuilderPluginBase } from './plugin-base';
|
@@ -37,7 +37,7 @@ export class MessageBuilderPlugin extends BuilderPluginBase {
|
|
37
37
|
body.push(w.createMessageBuilderClass(context, className, QueryMsg));
|
38
38
|
}
|
39
39
|
}
|
40
|
-
if (
|
40
|
+
if (Object.prototype.hasOwnProperty.call(typeHash, 'Coin')) {
|
41
41
|
// @ts-ignore
|
42
42
|
delete context.utils.Coin;
|
43
43
|
}
|
@@ -45,8 +45,8 @@ export class MessageBuilderPlugin extends BuilderPluginBase {
|
|
45
45
|
{
|
46
46
|
type: 'message-builder',
|
47
47
|
localname,
|
48
|
-
body
|
49
|
-
}
|
48
|
+
body,
|
49
|
+
},
|
50
50
|
];
|
51
51
|
}
|
52
52
|
}
|
@@ -30,7 +30,7 @@ export class MessageComposerPlugin extends BuilderPluginBase {
|
|
30
30
|
context.addProviderInfo(name, w.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE, TheClass, localname);
|
31
31
|
}
|
32
32
|
}
|
33
|
-
if (
|
33
|
+
if (Object.prototype.hasOwnProperty.call(typeHash, 'Coin')) {
|
34
34
|
// @ts-ignore
|
35
35
|
delete context.utils.Coin;
|
36
36
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import generate from '@babel/generator';
|
2
2
|
import * as t from '@babel/types';
|
3
|
-
import { defaultOptions } from '@cosmwasm/ts-codegen-ast';
|
3
|
+
import { defaultOptions, } from '@cosmwasm/ts-codegen-ast';
|
4
4
|
import deepmerge from 'deepmerge';
|
5
5
|
import { writeFileSync } from 'fs';
|
6
6
|
import { sync as mkdirp } from 'mkdirp';
|
@@ -41,8 +41,9 @@ export class BuilderPluginBase {
|
|
41
41
|
}
|
42
42
|
return results.map((result) => {
|
43
43
|
const imports = context.getImports(this.utils, result.localname);
|
44
|
+
const nodes = [...imports, ...result.body];
|
44
45
|
// @ts-ignore
|
45
|
-
const code = header + generate(t.program(
|
46
|
+
const code = header + generate(t.program(nodes)).code;
|
46
47
|
mkdirp(outPath);
|
47
48
|
const filename = join(outPath, result.localname);
|
48
49
|
writeFileSync(filename, code);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as w from '@cosmwasm/ts-codegen-ast';
|
2
|
-
import { RenderContext } from '@cosmwasm/ts-codegen-ast';
|
2
|
+
import { RenderContext, } from '@cosmwasm/ts-codegen-ast';
|
3
3
|
import { pascal } from 'case';
|
4
4
|
import { BuilderPluginBase } from './plugin-base';
|
5
5
|
import { GetLocalBaseNameByContractName } from './provider';
|
package/esm/plugins/provider.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as w from '@cosmwasm/ts-codegen-ast';
|
2
|
-
import { RenderContext } from '@cosmwasm/ts-codegen-ast';
|
2
|
+
import { RenderContext, } from '@cosmwasm/ts-codegen-ast';
|
3
3
|
import { pascal } from 'case';
|
4
4
|
import { BuilderPluginBase } from './plugin-base';
|
5
5
|
export const GetLocalNameByContractName = (name) => `${pascal(name)}.provider.ts`;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as w from '@cosmwasm/ts-codegen-ast';
|
2
|
-
import { getMessageProperties, RenderContext } from '@cosmwasm/ts-codegen-ast';
|
2
|
+
import { getMessageProperties, RenderContext, } from '@cosmwasm/ts-codegen-ast';
|
3
3
|
import { pascal } from 'case';
|
4
4
|
import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils';
|
5
5
|
import { BuilderPluginBase } from './plugin-base';
|
@@ -24,7 +24,8 @@ export class ReactQueryPlugin extends BuilderPluginBase {
|
|
24
24
|
const QueryClient = pascal(`${name}QueryClient`);
|
25
25
|
const body = [];
|
26
26
|
const clientImports = [];
|
27
|
-
|
27
|
+
if (QueryMsg)
|
28
|
+
clientImports.push(QueryClient);
|
28
29
|
// check that there are commands within the exec msg
|
29
30
|
const shouldGenerateMutationHooks = ExecuteMsg &&
|
30
31
|
options?.version === 'v4' &&
|
@@ -43,7 +44,7 @@ export class ReactQueryPlugin extends BuilderPluginBase {
|
|
43
44
|
context,
|
44
45
|
queryMsg: QueryMsg,
|
45
46
|
contractName: name,
|
46
|
-
QueryClient
|
47
|
+
QueryClient,
|
47
48
|
}));
|
48
49
|
}
|
49
50
|
if (shouldGenerateMutationHooks) {
|
@@ -51,10 +52,10 @@ export class ReactQueryPlugin extends BuilderPluginBase {
|
|
51
52
|
context,
|
52
53
|
execMsg: ExecuteMsg,
|
53
54
|
contractName: name,
|
54
|
-
ExecuteClient
|
55
|
+
ExecuteClient,
|
55
56
|
}));
|
56
57
|
}
|
57
|
-
if (
|
58
|
+
if (Object.prototype.hasOwnProperty.call(typeHash, 'Coin')) {
|
58
59
|
// @ts-ignore
|
59
60
|
delete context.utils.Coin;
|
60
61
|
}
|
@@ -62,8 +63,8 @@ export class ReactQueryPlugin extends BuilderPluginBase {
|
|
62
63
|
{
|
63
64
|
type: 'react-query',
|
64
65
|
localname,
|
65
|
-
body
|
66
|
-
}
|
66
|
+
body,
|
67
|
+
},
|
67
68
|
];
|
68
69
|
}
|
69
70
|
}
|
package/esm/plugins/recoil.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as w from '@cosmwasm/ts-codegen-ast';
|
2
|
-
import { RenderContext } from '@cosmwasm/ts-codegen-ast';
|
2
|
+
import { RenderContext, } from '@cosmwasm/ts-codegen-ast';
|
3
3
|
import { pascal } from 'case';
|
4
4
|
import { findAndParseTypes, findQueryMsg } from '../utils';
|
5
5
|
import { BuilderPluginBase } from './plugin-base';
|
@@ -36,7 +36,7 @@ export class RecoilPlugin extends BuilderPluginBase {
|
|
36
36
|
const selectors = w.createRecoilSelectors(context, name, QueryClient, QueryMsg);
|
37
37
|
body.push(...selectors);
|
38
38
|
}
|
39
|
-
if (
|
39
|
+
if (Object.prototype.hasOwnProperty.call(typeHash, 'Coin')) {
|
40
40
|
// @ts-ignore
|
41
41
|
delete context.utils.Coin;
|
42
42
|
}
|
@@ -44,8 +44,8 @@ export class RecoilPlugin extends BuilderPluginBase {
|
|
44
44
|
{
|
45
45
|
type: 'recoil',
|
46
46
|
localname,
|
47
|
-
body
|
48
|
-
}
|
47
|
+
body,
|
48
|
+
},
|
49
49
|
];
|
50
50
|
}
|
51
51
|
}
|
package/esm/plugins/types.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
|
-
import { RenderContext } from '@cosmwasm/ts-codegen-ast';
|
2
|
+
import { RenderContext, } from '@cosmwasm/ts-codegen-ast';
|
3
3
|
import { pascal } from 'case';
|
4
4
|
import { findAndParseTypes, findExecuteMsg } from '../utils';
|
5
5
|
import { clean } from '../utils/clean';
|
@@ -31,8 +31,8 @@ export class TypesPlugin extends BuilderPluginBase {
|
|
31
31
|
{
|
32
32
|
type: 'type',
|
33
33
|
localname,
|
34
|
-
body
|
35
|
-
}
|
34
|
+
body,
|
35
|
+
},
|
36
36
|
];
|
37
37
|
}
|
38
38
|
}
|
package/esm/ts-codegen.js
CHANGED
package/esm/utils/clean.js
CHANGED
@@ -21,7 +21,7 @@ export const clean = (obj) => {
|
|
21
21
|
if (obj instanceof Object || typeof obj === 'object') {
|
22
22
|
copy = {};
|
23
23
|
for (let attr in obj) {
|
24
|
-
if (
|
24
|
+
if (Object.prototype.hasOwnProperty.call(obj, attr)) {
|
25
25
|
switch (attr) {
|
26
26
|
case 'leadingComments':
|
27
27
|
case 'trailingComments':
|
package/esm/utils/cleanse.js
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
import { pascal } from 'case';
|
2
|
-
const cleanFor = (str) => {
|
2
|
+
export const cleanFor = (str) => {
|
3
3
|
/*
|
4
4
|
1. look at first char after _for_
|
5
5
|
2. ONLY if you find capitals after, modify it
|
6
6
|
*/
|
7
|
-
while (
|
8
|
-
const
|
9
|
-
|
7
|
+
while (true) {
|
8
|
+
const match = str.match(/(_[a-z]+_)[A-Z]/);
|
9
|
+
if (!match)
|
10
|
+
break;
|
11
|
+
// this replace is unsafe as it replaces the same text but maybe
|
12
|
+
// in a different location than the match
|
13
|
+
str = str.replace(match[1], pascal(match[1]));
|
10
14
|
}
|
11
15
|
return str;
|
12
16
|
};
|
@@ -46,7 +50,7 @@ export const cleanse = (obj) => {
|
|
46
50
|
}
|
47
51
|
}
|
48
52
|
for (let attr in obj) {
|
49
|
-
if (
|
53
|
+
if (Object.prototype.hasOwnProperty.call(obj, attr)) {
|
50
54
|
if (/_for_/.test(attr)) {
|
51
55
|
// @ts-ignore
|
52
56
|
copy[cleanFor(attr)] = cleanse(obj[attr]);
|
package/esm/utils/package.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { existsSync, readFileSync } from 'fs';
|
2
2
|
import { dirname, join } from 'path';
|
3
|
-
// need to search due to the dist/ folder and src/, etc.
|
3
|
+
// need to search due to the dist/ folder and src/, etc.
|
4
4
|
function findPackageJson(currentDir) {
|
5
5
|
const filePath = join(currentDir, 'package.json');
|
6
6
|
// Check if package.json exists in the current directory
|
package/esm/utils/parse.js
CHANGED
@@ -2,18 +2,16 @@ import { parse } from '@babel/parser';
|
|
2
2
|
import babelTraverse from '@babel/traverse';
|
3
3
|
export const parser = (codes) => {
|
4
4
|
const hash = {};
|
5
|
-
codes.forEach(code => {
|
6
|
-
const plugins = [
|
7
|
-
'typescript',
|
8
|
-
];
|
5
|
+
codes.forEach((code) => {
|
6
|
+
const plugins = ['typescript'];
|
9
7
|
const ast = parse(code, {
|
10
8
|
sourceType: 'module',
|
11
|
-
plugins
|
9
|
+
plugins,
|
12
10
|
});
|
13
11
|
const visitor = visitorFn({
|
14
12
|
addType(key, node) {
|
15
13
|
hash[key] = node;
|
16
|
-
}
|
14
|
+
},
|
17
15
|
});
|
18
16
|
babelTraverse(ast, visitor);
|
19
17
|
});
|
@@ -32,5 +30,5 @@ const visitorFn = (parser) => ({
|
|
32
30
|
},
|
33
31
|
TSInterfaceDeclaration(path) {
|
34
32
|
parser.addType(path.node.id.name, path.parentPath.node);
|
35
|
-
}
|
33
|
+
},
|
36
34
|
});
|
package/esm/utils/prompt.js
CHANGED
@@ -36,7 +36,7 @@ const transform = (questions) => {
|
|
36
36
|
return {
|
37
37
|
...q,
|
38
38
|
type: 'autocomplete',
|
39
|
-
source: getFuzzySearch(choices)
|
39
|
+
source: getFuzzySearch(choices),
|
40
40
|
};
|
41
41
|
}
|
42
42
|
else if (q.type === 'fuzzy:objects') {
|
@@ -45,7 +45,7 @@ const transform = (questions) => {
|
|
45
45
|
return {
|
46
46
|
...q,
|
47
47
|
type: 'autocomplete',
|
48
|
-
source: getFuzzySearchNames(choices)
|
48
|
+
source: getFuzzySearchNames(choices),
|
49
49
|
};
|
50
50
|
}
|
51
51
|
else {
|