@cosmwasm/ts-codegen 0.35.7 → 1.0.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/LICENSE-Apache +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +2 -2
- package/{types/src/builder → builder}/builder.d.ts +2 -2
- package/builder/builder.js +172 -0
- package/builder/index.js +17 -0
- package/bundler/bundler.d.ts +8 -0
- package/bundler/bundler.js +79 -0
- package/bundler/index.js +17 -0
- package/cli.d.ts +2 -0
- package/cli.js +24 -0
- package/cmds.d.ts +2 -0
- package/cmds.js +14 -0
- package/commands/create-boilerplate.d.ts +3 -0
- package/commands/create-boilerplate.js +132 -0
- package/commands/generate.d.ts +3 -0
- package/commands/generate.js +175 -0
- package/commands/install.d.ts +3 -0
- package/commands/install.js +107 -0
- package/{src/builder/builder.ts → esm/builder/builder.js} +39 -139
- package/esm/builder/index.js +1 -0
- package/esm/bundler/bundler.js +47 -0
- package/esm/bundler/index.js +1 -0
- package/esm/cli.js +20 -0
- package/{src → esm}/cmds.js +0 -1
- package/{src/commands/create-boilerplate.ts → esm/commands/create-boilerplate.js} +35 -70
- package/{src/commands/generate.ts → esm/commands/generate.js} +19 -24
- package/{src/commands/install.ts → esm/commands/install.js} +22 -35
- package/esm/file.js +18 -0
- package/esm/generators/client.js +67 -0
- package/esm/generators/create-helpers.js +36 -0
- package/esm/generators/message-composer.js +55 -0
- package/esm/generators/msg-builder.js +58 -0
- package/esm/generators/react-query.js +76 -0
- package/esm/generators/recoil.js +58 -0
- package/esm/generators/types.js +58 -0
- package/{src/index.ts → esm/index.js} +3 -6
- package/esm/plugins/client.js +59 -0
- package/esm/plugins/message-builder.js +52 -0
- package/esm/plugins/message-composer.js +46 -0
- package/esm/plugins/plugin-base.js +47 -0
- package/esm/plugins/provider-bundle.js +58 -0
- package/esm/plugins/provider.js +73 -0
- package/esm/plugins/react-query.js +69 -0
- package/esm/plugins/recoil.js +51 -0
- package/esm/plugins/types.js +38 -0
- package/{src → esm}/ts-codegen.js +1 -2
- package/{src/utils/clean.ts → esm/utils/clean.js} +7 -7
- package/{src/utils/cleanse.ts → esm/utils/cleanse.js} +18 -22
- package/esm/utils/files.js +42 -0
- package/{src/utils/parse.ts → esm/utils/parse.js} +4 -13
- package/esm/utils/prompt.js +59 -0
- package/{src/utils/schemas.ts → esm/utils/schemas.js} +16 -44
- package/esm/utils/unused.js +47 -0
- package/file.js +20 -0
- package/generators/client.js +95 -0
- package/generators/create-helpers.js +43 -0
- package/generators/message-composer.js +83 -0
- package/generators/msg-builder.js +86 -0
- package/generators/react-query.js +104 -0
- package/generators/recoil.js +86 -0
- package/generators/types.js +86 -0
- package/{module/helpers → helpers}/contractContextBase.js +5 -2
- package/{module/helpers → helpers}/contractContextBaseShortHandCtor.js +5 -2
- package/{module/helpers → helpers}/contractsContextTSX.js +5 -2
- package/{module/helpers/index.js → helpers/index.d.ts} +1 -1
- package/helpers/index.js +19 -0
- package/index.js +39 -0
- package/package.json +27 -51
- package/plugins/client.js +86 -0
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +17 -0
- package/plugins/message-builder.js +79 -0
- package/plugins/message-composer.js +73 -0
- package/{types/src/plugins → plugins}/plugin-base.d.ts +1 -1
- package/plugins/plugin-base.js +77 -0
- package/plugins/provider-bundle.js +85 -0
- package/{types/src/plugins → plugins}/provider.d.ts +2 -2
- package/plugins/provider.js +102 -0
- package/plugins/react-query.js +96 -0
- package/plugins/recoil.js +78 -0
- package/plugins/types.js +65 -0
- package/ts-codegen.js +8 -0
- package/utils/clean.js +49 -0
- package/utils/cleanse.js +89 -0
- package/utils/files.js +73 -0
- package/utils/header.js +14 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +17 -0
- package/utils/parse.d.ts +1 -0
- package/utils/parse.js +43 -0
- package/utils/prompt.d.ts +3 -0
- package/utils/prompt.js +65 -0
- package/utils/schemas.d.ts +11 -0
- package/utils/schemas.js +81 -0
- package/utils/unused.js +73 -0
- package/main/builder/builder.js +0 -308
- package/main/builder/index.js +0 -16
- package/main/bundler/bundler.js +0 -61
- package/main/bundler/index.js +0 -16
- package/main/cli.js +0 -51
- package/main/cmds.js +0 -15
- package/main/commands/create-boilerplate.js +0 -166
- package/main/commands/generate.js +0 -196
- package/main/commands/install.js +0 -138
- package/main/file.js +0 -35
- package/main/generators/client.js +0 -90
- package/main/generators/create-helpers.js +0 -38
- package/main/generators/message-composer.js +0 -77
- package/main/generators/msg-builder.js +0 -84
- package/main/generators/react-query.js +0 -102
- package/main/generators/recoil.js +0 -81
- package/main/generators/types.js +0 -82
- package/main/helpers/contractContextBase.js +0 -8
- package/main/helpers/contractContextBaseShortHandCtor.js +0 -8
- package/main/helpers/contractsContextTSX.js +0 -8
- package/main/helpers/index.js +0 -38
- package/main/index.js +0 -119
- package/main/plugins/client.js +0 -112
- package/main/plugins/index.js +0 -16
- package/main/plugins/message-builder.js +0 -102
- package/main/plugins/message-composer.js +0 -98
- package/main/plugins/plugin-base.js +0 -103
- package/main/plugins/provider-bundle.js +0 -108
- package/main/plugins/provider.js +0 -126
- package/main/plugins/react-query.js +0 -120
- package/main/plugins/recoil.js +0 -108
- package/main/plugins/types.js +0 -89
- package/main/ts-codegen.js +0 -20
- package/main/utils/clean.js +0 -53
- package/main/utils/cleanse.js +0 -87
- package/main/utils/files.js +0 -57
- package/main/utils/header.js +0 -11
- package/main/utils/index.js +0 -16
- package/main/utils/parse.js +0 -44
- package/main/utils/prompt.js +0 -98
- package/main/utils/schemas.js +0 -144
- package/main/utils/unused.js +0 -57
- package/module/builder/builder.js +0 -143
- package/module/builder/index.js +0 -1
- package/module/bundler/bundler.js +0 -36
- package/module/bundler/index.js +0 -1
- package/module/cli.js +0 -19
- package/module/cmds.js +0 -8
- package/module/commands/create-boilerplate.js +0 -102
- package/module/commands/generate.js +0 -163
- package/module/commands/install.js +0 -98
- package/module/file.js +0 -18
- package/module/generators/client.js +0 -65
- package/module/generators/create-helpers.js +0 -33
- package/module/generators/message-composer.js +0 -52
- package/module/generators/msg-builder.js +0 -58
- package/module/generators/react-query.js +0 -75
- package/module/generators/recoil.js +0 -53
- package/module/generators/types.js +0 -55
- package/module/index.js +0 -14
- package/module/plugins/client.js +0 -63
- package/module/plugins/index.js +0 -1
- package/module/plugins/message-builder.js +0 -55
- package/module/plugins/message-composer.js +0 -49
- package/module/plugins/plugin-base.js +0 -66
- package/module/plugins/provider-bundle.js +0 -56
- package/module/plugins/provider.js +0 -68
- package/module/plugins/react-query.js +0 -72
- package/module/plugins/recoil.js +0 -57
- package/module/plugins/types.js +0 -42
- package/module/ts-codegen.js +0 -6
- package/module/utils/clean.js +0 -44
- package/module/utils/cleanse.js +0 -78
- package/module/utils/files.js +0 -40
- package/module/utils/header.js +0 -8
- package/module/utils/index.js +0 -1
- package/module/utils/parse.js +0 -35
- package/module/utils/prompt.js +0 -63
- package/module/utils/schemas.js +0 -85
- package/module/utils/unused.js +0 -43
- package/src/builder/index.ts +0 -1
- package/src/bundler/bundler.ts +0 -67
- package/src/bundler/index.ts +0 -1
- package/src/cli.js +0 -21
- package/src/file.js +0 -20
- package/src/generators/client.ts +0 -109
- package/src/generators/create-helpers.ts +0 -71
- package/src/generators/message-composer.ts +0 -86
- package/src/generators/msg-builder.ts +0 -78
- package/src/generators/react-query.ts +0 -102
- package/src/generators/recoil.ts +0 -92
- package/src/generators/types.ts +0 -94
- package/src/helpers/index.ts +0 -3
- package/src/plugins/client.ts +0 -124
- package/src/plugins/index.ts +0 -1
- package/src/plugins/message-builder.ts +0 -85
- package/src/plugins/message-composer.ts +0 -89
- package/src/plugins/plugin-base.ts +0 -122
- package/src/plugins/provider-bundle.ts +0 -98
- package/src/plugins/provider.ts +0 -115
- package/src/plugins/react-query.ts +0 -115
- package/src/plugins/recoil.ts +0 -89
- package/src/plugins/types.ts +0 -74
- package/src/utils/files.ts +0 -73
- package/src/utils/index.ts +0 -1
- package/src/utils/prompt.js +0 -65
- package/src/utils/unused.ts +0 -52
- package/types/src/bundler/bundler.d.ts +0 -4
- package/types/src/cli.d.ts +0 -1
- package/types/src/cmds.d.ts +0 -1
- package/types/src/commands/create-boilerplate.d.ts +0 -2
- package/types/src/commands/generate.d.ts +0 -2
- package/types/src/commands/install.d.ts +0 -2
- package/types/src/generators/msg-builder.ts +0 -5
- package/types/src/plugins/msg-builder.d.ts +0 -12
- package/types/src/plugins/use-contracts.d.ts +0 -12
- package/types/src/types.d.ts +0 -16
- package/types/src/utils/parse.d.ts +0 -1
- package/types/src/utils/prompt.d.ts +0 -3
- package/types/src/utils/schemas.d.ts +0 -10
- /package/{types/src/builder → builder}/index.d.ts +0 -0
- /package/{types/src/bundler → bundler}/index.d.ts +0 -0
- /package/{src/helpers/contractContextBase.ts → esm/helpers/contractContextBase.js} +0 -0
- /package/{src/helpers/contractContextBaseShortHandCtor.ts → esm/helpers/contractContextBaseShortHandCtor.js} +0 -0
- /package/{src/helpers/contractsContextTSX.ts → esm/helpers/contractsContextTSX.js} +0 -0
- /package/{types/src/helpers/index.d.ts → esm/helpers/index.js} +0 -0
- /package/{types/src/plugins/index.d.ts → esm/plugins/index.js} +0 -0
- /package/{src/utils/header.ts → esm/utils/header.js} +0 -0
- /package/{types/src/utils/index.d.ts → esm/utils/index.js} +0 -0
- /package/{types/src/file.d.ts → file.d.ts} +0 -0
- /package/{types/src/generators → generators}/client.d.ts +0 -0
- /package/{types/src/generators → generators}/create-helpers.d.ts +0 -0
- /package/{types/src/generators → generators}/message-composer.d.ts +0 -0
- /package/{types/src/generators → generators}/msg-builder.d.ts +0 -0
- /package/{types/src/generators → generators}/react-query.d.ts +0 -0
- /package/{types/src/generators → generators}/recoil.d.ts +0 -0
- /package/{types/src/generators → generators}/types.d.ts +0 -0
- /package/{types/src/helpers → helpers}/contractContextBase.d.ts +0 -0
- /package/{types/src/helpers → helpers}/contractContextBaseShortHandCtor.d.ts +0 -0
- /package/{types/src/helpers → helpers}/contractsContextTSX.d.ts +0 -0
- /package/{types/src/index.d.ts → index.d.ts} +0 -0
- /package/{types/src/plugins → plugins}/client.d.ts +0 -0
- /package/{types/src/plugins → plugins}/message-builder.d.ts +0 -0
- /package/{types/src/plugins → plugins}/message-composer.d.ts +0 -0
- /package/{types/src/plugins → plugins}/provider-bundle.d.ts +0 -0
- /package/{types/src/plugins → plugins}/react-query.d.ts +0 -0
- /package/{types/src/plugins → plugins}/recoil.d.ts +0 -0
- /package/{types/src/plugins → plugins}/types.d.ts +0 -0
- /package/{types/src/ts-codegen.d.ts → ts-codegen.d.ts} +0 -0
- /package/{types/src/utils → utils}/clean.d.ts +0 -0
- /package/{types/src/utils → utils}/cleanse.d.ts +0 -0
- /package/{types/src/utils → utils}/files.d.ts +0 -0
- /package/{types/src/utils → utils}/header.d.ts +0 -0
- /package/{types/src/utils → utils}/unused.d.ts +0 -0
@@ -1,18 +1,13 @@
|
|
1
|
-
import {
|
2
|
-
|
1
|
+
import { defaultOptions, BuilderContext } from "wasm-ast-types";
|
3
2
|
import { header } from '../utils/header';
|
4
3
|
import { join } from "path";
|
5
4
|
import { writeFileSync } from 'fs';
|
6
5
|
import { sync as mkdirp } from "mkdirp";
|
7
|
-
|
8
6
|
import { basename } from 'path';
|
9
7
|
import { readSchemas } from '../utils';
|
10
|
-
import { IBuilderPlugin } from '../plugins';
|
11
|
-
|
12
8
|
import deepmerge from 'deepmerge';
|
13
9
|
import { pascal } from "case";
|
14
10
|
import { createFileBundle, recursiveModuleBundle } from "../bundler";
|
15
|
-
|
16
11
|
import generate from '@babel/generator';
|
17
12
|
import * as t from '@babel/types';
|
18
13
|
import { ReactQueryPlugin } from "../plugins/react-query";
|
@@ -24,219 +19,124 @@ import { TypesPlugin } from "../plugins/types";
|
|
24
19
|
import { ContractsContextProviderPlugin } from "../plugins/provider";
|
25
20
|
import { createHelpers } from "../generators/create-helpers";
|
26
21
|
import { ContractsProviderBundlePlugin } from "../plugins/provider-bundle";
|
27
|
-
|
28
|
-
const defaultOpts: TSBuilderOptions = {
|
22
|
+
const defaultOpts = {
|
29
23
|
bundle: {
|
30
24
|
enabled: true,
|
31
25
|
scope: 'contracts',
|
32
26
|
bundleFile: 'bundle.ts'
|
33
27
|
},
|
34
28
|
useShorthandCtor: true
|
35
|
-
}
|
36
|
-
|
37
|
-
export interface TSBuilderInput {
|
38
|
-
contracts: Array<ContractFile | string>;
|
39
|
-
outPath: string;
|
40
|
-
options?: TSBuilderOptions;
|
41
|
-
plugins?: IBuilderPlugin[];
|
42
|
-
};
|
43
|
-
|
44
|
-
export interface BundleOptions {
|
45
|
-
enabled?: boolean;
|
46
|
-
scope?: string;
|
47
|
-
bundleFile?: string;
|
48
|
-
bundlePath?: string;
|
49
|
-
};
|
50
|
-
|
51
|
-
export interface UseContractsOptions {
|
52
|
-
enabled?: boolean;
|
53
29
|
};
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
* Default: true
|
60
|
-
*/
|
61
|
-
useShorthandCtor?: boolean;
|
62
|
-
useContractsHooks?: UseContractsOptions;
|
63
|
-
} & RenderOptions;
|
64
|
-
|
65
|
-
export type BuilderFileType = 'type' | 'client' | 'recoil' | 'react-query' | 'message-composer' | 'message-builder' | 'plugin';
|
66
|
-
|
67
|
-
export interface BuilderFile {
|
68
|
-
type: BuilderFileType;
|
69
|
-
pluginType?: string;
|
70
|
-
contract: string;
|
71
|
-
//filename only: Factory.client.ts
|
72
|
-
localname: string;
|
73
|
-
//full path: contracts/Factory.client.ts
|
74
|
-
filename: string;
|
75
|
-
};
|
76
|
-
|
77
|
-
export interface ContractFile {
|
78
|
-
name: string;
|
79
|
-
dir: string;
|
80
|
-
}
|
81
|
-
|
82
|
-
function getContract(contractOpt): ContractFile {
|
30
|
+
;
|
31
|
+
;
|
32
|
+
;
|
33
|
+
;
|
34
|
+
function getContract(contractOpt) {
|
83
35
|
if (typeof contractOpt === 'string') {
|
84
36
|
const name = basename(contractOpt);
|
85
37
|
const contractName = pascal(name);
|
86
38
|
return {
|
87
39
|
name: contractName,
|
88
40
|
dir: contractOpt
|
89
|
-
}
|
41
|
+
};
|
90
42
|
}
|
91
43
|
return {
|
92
44
|
name: pascal(contractOpt.name),
|
93
45
|
dir: contractOpt.dir
|
94
46
|
};
|
95
47
|
}
|
96
|
-
|
97
48
|
export class TSBuilder {
|
98
|
-
contracts
|
99
|
-
outPath
|
100
|
-
options
|
101
|
-
plugins
|
102
|
-
builderContext
|
103
|
-
|
104
|
-
protected files: BuilderFile[] = [];
|
105
|
-
|
49
|
+
contracts;
|
50
|
+
outPath;
|
51
|
+
options;
|
52
|
+
plugins = [];
|
53
|
+
builderContext = new BuilderContext();
|
54
|
+
files = [];
|
106
55
|
loadDefaultPlugins() {
|
107
|
-
|
108
|
-
new TypesPlugin(this.options),
|
109
|
-
new ClientPlugin(this.options),
|
110
|
-
new MessageComposerPlugin(this.options),
|
111
|
-
new ReactQueryPlugin(this.options),
|
112
|
-
new RecoilPlugin(this.options),
|
113
|
-
new MessageBuilderPlugin(this.options),
|
114
|
-
new ContractsContextProviderPlugin(this.options),
|
115
|
-
]);
|
56
|
+
this.plugins.push(new TypesPlugin(this.options), new ClientPlugin(this.options), new MessageComposerPlugin(this.options), new ReactQueryPlugin(this.options), new RecoilPlugin(this.options), new MessageBuilderPlugin(this.options), new ContractsContextProviderPlugin(this.options));
|
116
57
|
}
|
117
|
-
|
118
|
-
constructor({ contracts, outPath, options, plugins }: TSBuilderInput) {
|
58
|
+
constructor({ contracts, outPath, options, plugins }) {
|
119
59
|
this.contracts = contracts;
|
120
60
|
this.outPath = outPath;
|
121
|
-
this.options = deepmerge(
|
122
|
-
deepmerge(
|
123
|
-
defaultOptions,
|
124
|
-
defaultOpts
|
125
|
-
),
|
126
|
-
options ?? {}
|
127
|
-
);
|
128
|
-
|
61
|
+
this.options = deepmerge(deepmerge(defaultOptions, defaultOpts), options ?? {});
|
129
62
|
this.loadDefaultPlugins();
|
130
|
-
|
131
63
|
if (plugins && plugins.length) {
|
132
|
-
|
64
|
+
this.plugins.push(...plugins);
|
133
65
|
}
|
134
|
-
|
135
|
-
this.plugins.forEach(plugin => plugin.setBuilder(this))
|
66
|
+
this.plugins.forEach(plugin => plugin.setBuilder(this));
|
136
67
|
}
|
137
|
-
|
138
68
|
async build() {
|
139
69
|
await this.process();
|
140
70
|
await this.after();
|
141
71
|
}
|
142
|
-
|
143
72
|
// lifecycle functions
|
144
|
-
|
73
|
+
async process() {
|
145
74
|
for (const contractOpt of this.contracts) {
|
146
75
|
const contract = getContract(contractOpt);
|
147
76
|
//resolve contract schema.
|
148
77
|
const contractInfo = await readSchemas({
|
149
78
|
schemaDir: contract.dir
|
150
79
|
});
|
151
|
-
|
152
80
|
//lifecycle and plugins.
|
153
81
|
await this.render(contract.name, contractInfo);
|
154
82
|
}
|
155
83
|
}
|
156
|
-
|
157
|
-
private async render(name: string, contractInfo: ContractInfo) {
|
84
|
+
async render(name, contractInfo) {
|
158
85
|
for (const plugin of this.plugins) {
|
159
86
|
let files = await plugin.render(name, contractInfo, this.outPath);
|
160
87
|
if (files && files.length) {
|
161
|
-
|
88
|
+
this.files.push(...files);
|
162
89
|
}
|
163
90
|
}
|
164
91
|
}
|
165
|
-
|
166
|
-
private async after() {
|
167
|
-
|
92
|
+
async after() {
|
168
93
|
//create useContracts bundle file
|
169
94
|
const contractsProviderBundlePlugin = new ContractsProviderBundlePlugin(this.options);
|
170
95
|
contractsProviderBundlePlugin.setBuilder(this);
|
171
|
-
|
172
96
|
//contractContextProviders.ts
|
173
|
-
const files = await contractsProviderBundlePlugin.render(
|
174
|
-
|
175
|
-
|
176
|
-
schemas: [],
|
177
|
-
},
|
178
|
-
this.outPath
|
179
|
-
);
|
180
|
-
|
97
|
+
const files = await contractsProviderBundlePlugin.render("contractContextProviders", {
|
98
|
+
schemas: [],
|
99
|
+
}, this.outPath);
|
181
100
|
if (files && files.length) {
|
182
|
-
|
101
|
+
this.files.push(...files);
|
183
102
|
}
|
184
|
-
|
185
103
|
const helpers = createHelpers({
|
186
104
|
outPath: this.outPath,
|
187
105
|
contracts: this.contracts,
|
188
106
|
options: this.options,
|
189
107
|
plugins: this.plugins,
|
190
108
|
}, this.builderContext);
|
191
|
-
|
192
109
|
if (helpers && helpers.length) {
|
193
|
-
|
110
|
+
this.files.push(...helpers);
|
194
111
|
}
|
195
|
-
|
196
112
|
if (this.options.bundle.enabled) {
|
197
113
|
this.bundle();
|
198
114
|
}
|
199
115
|
}
|
200
|
-
|
201
116
|
async bundle() {
|
202
117
|
const allFiles = this.files;
|
203
|
-
|
204
118
|
const bundleFile = this.options.bundle.bundleFile;
|
205
|
-
const bundlePath = join(
|
206
|
-
this.options?.bundle?.bundlePath ?? this.outPath,
|
207
|
-
bundleFile
|
208
|
-
);
|
119
|
+
const bundlePath = join(this.options?.bundle?.bundlePath ?? this.outPath, bundleFile);
|
209
120
|
const bundleVariables = {};
|
210
121
|
const importPaths = [];
|
211
|
-
|
212
122
|
allFiles.forEach(file => {
|
213
|
-
createFileBundle(
|
214
|
-
`${this.options.bundle.scope}.${file.contract}`,
|
215
|
-
file.filename,
|
216
|
-
bundlePath,
|
217
|
-
importPaths,
|
218
|
-
bundleVariables
|
219
|
-
);
|
220
|
-
|
123
|
+
createFileBundle(`${this.options.bundle.scope}.${file.contract}`, file.filename, bundlePath, importPaths, bundleVariables);
|
221
124
|
});
|
222
|
-
|
223
125
|
const ast = recursiveModuleBundle(bundleVariables);
|
126
|
+
const nodes = [
|
127
|
+
...importPaths,
|
128
|
+
...ast
|
129
|
+
];
|
130
|
+
// @ts-ignore
|
224
131
|
let code = generate(t.program(
|
225
|
-
|
226
|
-
|
227
|
-
...ast
|
228
|
-
]
|
229
|
-
)).code;
|
230
|
-
|
132
|
+
// @ts-ignore
|
133
|
+
nodes)).code;
|
231
134
|
if (this.options?.bundle?.bundlePath) {
|
232
135
|
mkdirp(this.options?.bundle?.bundlePath);
|
233
136
|
}
|
234
|
-
|
235
137
|
mkdirp(this.outPath);
|
236
|
-
|
237
|
-
|
238
|
-
|
138
|
+
if (code.trim() === '')
|
139
|
+
code = 'export {};';
|
239
140
|
writeFileSync(bundlePath, header + code);
|
240
|
-
|
241
141
|
}
|
242
142
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './builder';
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import * as t from '@babel/types';
|
2
|
+
import nested from 'nested-obj';
|
3
|
+
import { relative, dirname, extname } from 'path';
|
4
|
+
export const recursiveModuleBundle = (obj) => {
|
5
|
+
return Object.keys(obj).map(key => {
|
6
|
+
const value = obj[key];
|
7
|
+
if (typeof value === 'object' && value && value.__export) {
|
8
|
+
// e.g. abci
|
9
|
+
// 1. create variable for abci
|
10
|
+
// 2. splat ALL _0, parms into abci
|
11
|
+
// 3. export that variable
|
12
|
+
const nmspc = t.variableDeclaration('const', [t.variableDeclarator(t.identifier(key), t.objectExpression(Object.keys(obj[key])
|
13
|
+
.filter(a => a !== '__export')
|
14
|
+
.filter(a => a.startsWith('_'))
|
15
|
+
.map(a => t.spreadElement(t.identifier(a)))))]);
|
16
|
+
const others = Object.keys(obj[key])
|
17
|
+
.filter(a => a !== '__export')
|
18
|
+
.filter(a => !a.startsWith('_'));
|
19
|
+
if (others.length) {
|
20
|
+
throw new Error('namespace and package not supported, yet.');
|
21
|
+
}
|
22
|
+
// return nmspc;
|
23
|
+
return t.exportNamedDeclaration(nmspc, []);
|
24
|
+
}
|
25
|
+
else if (typeof value === 'object' && value) {
|
26
|
+
// you can make a namespace for obj[key]
|
27
|
+
// e.g. libs
|
28
|
+
return t.exportNamedDeclaration(t.tsModuleDeclaration(t.identifier(key), t.tsModuleBlock(recursiveModuleBundle(obj[key]))));
|
29
|
+
}
|
30
|
+
else {
|
31
|
+
throw new Error('Invalid structure for BundleData');
|
32
|
+
}
|
33
|
+
});
|
34
|
+
};
|
35
|
+
export const importNamespace = (ident, path) => t.importDeclaration([
|
36
|
+
t.importNamespaceSpecifier(t.identifier(ident))
|
37
|
+
], t.stringLiteral(path.replace(extname(path), '')));
|
38
|
+
let counter = 0;
|
39
|
+
export const createFileBundle = (pkg, filename, bundleFile, importPaths, bundleVariables) => {
|
40
|
+
let rel = relative(dirname(bundleFile), filename);
|
41
|
+
if (!rel.startsWith('.'))
|
42
|
+
rel = `./${rel}`;
|
43
|
+
const variable = `_${counter++}`;
|
44
|
+
importPaths.push(importNamespace(variable, rel));
|
45
|
+
nested.set(bundleVariables, pkg + '.__export', true);
|
46
|
+
nested.set(bundleVariables, pkg + '.' + variable, true);
|
47
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './bundler';
|
package/esm/cli.js
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
import { prompt } from './utils/prompt';
|
2
|
+
import { Commands as commands } from './cmds';
|
3
|
+
const question = [
|
4
|
+
{
|
5
|
+
_: true,
|
6
|
+
type: 'fuzzy',
|
7
|
+
name: 'cmd',
|
8
|
+
message: 'what do you want to do?',
|
9
|
+
choices: Object.keys(commands)
|
10
|
+
}
|
11
|
+
];
|
12
|
+
export const cli = async (argv) => {
|
13
|
+
var { cmd } = await prompt(question, argv);
|
14
|
+
if (typeof commands[cmd] === 'function') {
|
15
|
+
await commands[cmd](argv);
|
16
|
+
}
|
17
|
+
else {
|
18
|
+
console.log('command not found.');
|
19
|
+
}
|
20
|
+
};
|
package/{src → esm}/cmds.js
RENAMED
@@ -4,14 +4,12 @@ import dargs from 'dargs';
|
|
4
4
|
const glob = require('glob').sync;
|
5
5
|
const fs = require('fs');
|
6
6
|
const path = require('path');
|
7
|
-
|
8
7
|
const repo = 'https://github.com/cosmology-tech/ts-codegen-module-boilerplate';
|
9
|
-
export default async argv => {
|
8
|
+
export default async (argv) => {
|
10
9
|
if (!shell.which('git')) {
|
11
10
|
shell.echo('Sorry, this script requires git');
|
12
11
|
return shell.exit(1);
|
13
12
|
}
|
14
|
-
|
15
13
|
const { name } = await prompt([
|
16
14
|
{
|
17
15
|
type: 'string',
|
@@ -19,115 +17,82 @@ export default async argv => {
|
|
19
17
|
message: 'Enter your new module name',
|
20
18
|
}
|
21
19
|
], argv);
|
22
|
-
|
23
20
|
shell.exec(`git clone ${repo} ${name}`);
|
24
21
|
shell.cd(name);
|
25
|
-
|
26
22
|
const questions = JSON.parse(fs.readFileSync(`.questions.json`));
|
27
|
-
|
28
23
|
const fullname = shell
|
29
24
|
.exec('git config --global user.name', { silent: true })
|
30
25
|
.trim();
|
31
26
|
const email = shell
|
32
27
|
.exec('git config --global user.email', { silent: true })
|
33
28
|
.trim();
|
34
|
-
|
35
29
|
// @__USERNAME__/__MODULENAME__
|
36
30
|
// __PACKAGE_IDENTIFIER__
|
37
|
-
const args = dargs(
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
},
|
45
|
-
{ allowCamelCase: true }
|
46
|
-
);
|
47
|
-
|
31
|
+
const args = dargs({
|
32
|
+
_: [],
|
33
|
+
...argv,
|
34
|
+
__MODULENAME__: name,
|
35
|
+
__USERFULLNAME__: fullname,
|
36
|
+
__USEREMAIL__: email,
|
37
|
+
}, { allowCamelCase: true });
|
48
38
|
const results = await prompt(questions, args);
|
49
39
|
let scopedResults;
|
50
|
-
|
51
|
-
|
52
|
-
|
40
|
+
const license = await prompt([
|
41
|
+
{
|
42
|
+
name: '__LICENSE__',
|
43
|
+
message: 'Which license?',
|
44
|
+
choices: ['MIT', 'closed'],
|
45
|
+
type: 'list',
|
46
|
+
required: true,
|
47
|
+
},
|
48
|
+
], []);
|
49
|
+
if (results.__ACCESS__ === 'public') {
|
50
|
+
scopedResults = await prompt([
|
53
51
|
{
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
type: 'list',
|
52
|
+
type: 'confirm',
|
53
|
+
name: 'scoped',
|
54
|
+
message: 'use npm scopes?',
|
58
55
|
required: true,
|
59
56
|
},
|
60
|
-
],
|
61
|
-
[]
|
62
|
-
);
|
63
|
-
|
64
|
-
if (results.__ACCESS__ === 'public') {
|
65
|
-
scopedResults = await prompt(
|
66
|
-
[
|
67
|
-
{
|
68
|
-
type: 'confirm',
|
69
|
-
name: 'scoped',
|
70
|
-
message: 'use npm scopes?',
|
71
|
-
required: true,
|
72
|
-
},
|
73
|
-
],
|
74
|
-
[]
|
75
|
-
);
|
57
|
+
], []);
|
76
58
|
}
|
77
|
-
|
78
59
|
const files = []
|
79
60
|
.concat(glob(process.cwd() + '/**/.*'))
|
80
61
|
.concat(glob(process.cwd() + '/**/*'));
|
81
|
-
|
82
62
|
for (let i = 0; i < files.length; i++) {
|
83
63
|
const templateFile = files[i];
|
84
|
-
if (fs.lstatSync(templateFile).isDirectory())
|
85
|
-
|
64
|
+
if (fs.lstatSync(templateFile).isDirectory())
|
65
|
+
continue;
|
86
66
|
let content = fs.readFileSync(templateFile).toString();
|
87
|
-
if (
|
88
|
-
|
89
|
-
license.__LICENSE__ === 'closed'
|
90
|
-
) {
|
67
|
+
if (path.basename(templateFile) === 'LICENSE' &&
|
68
|
+
license.__LICENSE__ === 'closed') {
|
91
69
|
content = `Copyright (c) 2023 __USERFULLNAME__ <__USEREMAIL__> - All Rights Reserved
|
92
70
|
Unauthorized copying via any medium is strictly prohibited
|
93
71
|
Proprietary and confidential`;
|
94
72
|
}
|
95
|
-
|
96
73
|
Object.keys(results).forEach(key => {
|
97
74
|
if (/^__/.test(key)) {
|
98
75
|
content = content.replace(new RegExp(key, 'g'), results[key]);
|
99
76
|
}
|
100
77
|
});
|
101
|
-
|
102
78
|
if (results.__ACCESS__ === 'public') {
|
103
79
|
if (scopedResults.scoped) {
|
104
|
-
content = content.replace(
|
105
|
-
|
106
|
-
|
107
|
-
);
|
108
|
-
} else {
|
109
|
-
content = content.replace(
|
110
|
-
/__PACKAGE_IDENTIFIER__/g,
|
111
|
-
`${results.__MODULENAME__}`
|
112
|
-
);
|
80
|
+
content = content.replace(/__PACKAGE_IDENTIFIER__/g, `@${results.__USERNAME__}/${results.__MODULENAME__}`);
|
81
|
+
}
|
82
|
+
else {
|
83
|
+
content = content.replace(/__PACKAGE_IDENTIFIER__/g, `${results.__MODULENAME__}`);
|
113
84
|
}
|
114
|
-
} else {
|
115
|
-
content = content.replace(
|
116
|
-
/__PACKAGE_IDENTIFIER__/g,
|
117
|
-
`@${results.__USERNAME__}/${results.__MODULENAME__}`
|
118
|
-
);
|
119
85
|
}
|
120
|
-
|
86
|
+
else {
|
87
|
+
content = content.replace(/__PACKAGE_IDENTIFIER__/g, `@${results.__USERNAME__}/${results.__MODULENAME__}`);
|
88
|
+
}
|
121
89
|
// if (path.basename(templateFile) === 'README.md') {
|
122
90
|
// content = `# ${results.__MODULENAME__}`;
|
123
91
|
// }
|
124
|
-
|
125
92
|
fs.writeFileSync(templateFile, content);
|
126
93
|
}
|
127
|
-
|
128
94
|
shell.rm('-rf', '.git');
|
129
95
|
shell.rm('-rf', '.questions.json');
|
130
|
-
|
131
96
|
console.log(`
|
132
97
|
|
133
98
|
|||
|
@@ -136,4 +101,4 @@ Proprietary and confidential`;
|
|
136
101
|
|
137
102
|
✨ Great work!
|
138
103
|
`);
|
139
|
-
};
|
104
|
+
};
|
@@ -1,7 +1,6 @@
|
|
1
|
+
// @ts-nocheck
|
1
2
|
import { prompt } from '../utils/prompt';
|
2
3
|
import codegen from '../index';
|
3
|
-
import { TSBuilderOptions } from '../builder';
|
4
|
-
|
5
4
|
export default async (argv) => {
|
6
5
|
const questions = [
|
7
6
|
{
|
@@ -42,17 +41,16 @@ export default async (argv) => {
|
|
42
41
|
default: true
|
43
42
|
}
|
44
43
|
];
|
45
|
-
|
46
44
|
if (argv.typesOnly) {
|
47
45
|
argv.plugin = 'types';
|
48
46
|
}
|
49
|
-
|
50
47
|
let { schema, out, name, plugin, bundle } = await prompt(questions, argv);
|
51
|
-
if (!Array.isArray(plugin))
|
52
|
-
|
48
|
+
if (!Array.isArray(plugin))
|
49
|
+
plugin = [plugin];
|
53
50
|
///////// REACT QUERY
|
54
51
|
const questions2 = [];
|
55
52
|
if (plugin.includes('react-query')) {
|
53
|
+
// @ts-ignore
|
56
54
|
[].push.apply(questions2, [
|
57
55
|
{
|
58
56
|
type: 'confirm',
|
@@ -73,8 +71,9 @@ export default async (argv) => {
|
|
73
71
|
message: 'queryKeys?',
|
74
72
|
default: false
|
75
73
|
},
|
76
|
-
])
|
77
|
-
}
|
74
|
+
]);
|
75
|
+
}
|
76
|
+
;
|
78
77
|
const { optionalClient, version, queryKeys } = await prompt(questions2, argv);
|
79
78
|
const questions3 = [];
|
80
79
|
if (version === 'v4') {
|
@@ -86,11 +85,10 @@ export default async (argv) => {
|
|
86
85
|
message: 'Generate useMutation hooks?',
|
87
86
|
default: false
|
88
87
|
}
|
89
|
-
|
90
|
-
|
91
|
-
|
88
|
+
]);
|
89
|
+
}
|
90
|
+
;
|
92
91
|
const { mutations } = await prompt(questions3, argv);
|
93
|
-
|
94
92
|
const queryFactoryQuestions = [];
|
95
93
|
if (queryKeys) {
|
96
94
|
[].push.apply(queryFactoryQuestions, [
|
@@ -101,11 +99,11 @@ export default async (argv) => {
|
|
101
99
|
message: 'queryFactory? ',
|
102
100
|
default: false
|
103
101
|
}
|
104
|
-
])
|
105
|
-
}
|
102
|
+
]);
|
103
|
+
}
|
104
|
+
;
|
106
105
|
const { queryFactory } = await prompt(queryFactoryQuestions, argv);
|
107
106
|
///////// END REACT QUERY
|
108
|
-
|
109
107
|
///////// BUNDLE
|
110
108
|
const questions4 = [];
|
111
109
|
if (bundle) {
|
@@ -122,18 +120,17 @@ export default async (argv) => {
|
|
122
120
|
message: 'bundleScope?',
|
123
121
|
default: 'contracts'
|
124
122
|
}
|
125
|
-
])
|
126
|
-
}
|
123
|
+
]);
|
124
|
+
}
|
125
|
+
;
|
127
126
|
const { bundleFile, bundleScope } = await prompt(questions4, argv);
|
128
127
|
///////// END BUNDLE
|
129
|
-
|
130
|
-
const options: TSBuilderOptions = {
|
128
|
+
const options = {
|
131
129
|
types: {
|
132
130
|
enabled: true
|
133
131
|
},
|
134
132
|
client: {
|
135
|
-
enabled:
|
136
|
-
plugin.includes('client') ||
|
133
|
+
enabled: plugin.includes('client') ||
|
137
134
|
plugin.includes('recoil') ||
|
138
135
|
plugin.includes('react-query')
|
139
136
|
},
|
@@ -152,7 +149,6 @@ export default async (argv) => {
|
|
152
149
|
enabled: plugin.includes('message-composer')
|
153
150
|
},
|
154
151
|
messageBuilder: {
|
155
|
-
|
156
152
|
enabled: plugin.includes('message-builder')
|
157
153
|
},
|
158
154
|
bundle: {
|
@@ -161,7 +157,6 @@ export default async (argv) => {
|
|
161
157
|
bundleFile
|
162
158
|
}
|
163
159
|
};
|
164
|
-
|
165
160
|
await codegen({
|
166
161
|
contracts: [
|
167
162
|
{
|
@@ -171,5 +166,5 @@ export default async (argv) => {
|
|
171
166
|
],
|
172
167
|
outPath: out,
|
173
168
|
options
|
174
|
-
})
|
169
|
+
});
|
175
170
|
};
|