@cosmwasm/ts-codegen 0.34.2 → 0.35.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.
Files changed (82) hide show
  1. package/README.md +83 -20
  2. package/main/builder/builder.js +145 -247
  3. package/main/builder/index.js +0 -2
  4. package/main/bundler/bundler.js +3 -16
  5. package/main/bundler/index.js +0 -2
  6. package/main/cli.js +20 -38
  7. package/main/cmds.js +0 -5
  8. package/main/commands/create-boilerplate.js +132 -160
  9. package/main/commands/generate.js +168 -192
  10. package/main/commands/install.js +89 -123
  11. package/main/file.js +13 -25
  12. package/main/generators/client.js +55 -81
  13. package/main/generators/create-helpers.js +0 -14
  14. package/main/generators/message-composer.js +42 -68
  15. package/main/generators/msg-builder.js +49 -78
  16. package/main/generators/react-query.js +68 -92
  17. package/main/generators/recoil.js +47 -71
  18. package/main/generators/types.js +45 -73
  19. package/main/helpers/index.js +0 -6
  20. package/main/index.js +8 -30
  21. package/main/plugins/client.js +56 -90
  22. package/main/plugins/index.js +0 -2
  23. package/main/plugins/{msg-builder.js → message-builder.js} +56 -93
  24. package/main/plugins/message-composer.js +42 -76
  25. package/main/plugins/plugin-base.js +40 -70
  26. package/main/plugins/provider-bundle.js +42 -81
  27. package/main/plugins/provider.js +58 -103
  28. package/main/plugins/react-query.js +67 -99
  29. package/main/plugins/recoil.js +45 -82
  30. package/main/plugins/types.js +34 -68
  31. package/main/ts-codegen.js +7 -15
  32. package/main/utils/clean.js +8 -17
  33. package/main/utils/cleanse.js +10 -25
  34. package/main/utils/files.js +2 -22
  35. package/main/utils/header.js +0 -3
  36. package/main/utils/index.js +0 -2
  37. package/main/utils/parse.js +2 -7
  38. package/main/utils/prompt.js +16 -36
  39. package/main/utils/schemas.js +86 -133
  40. package/main/utils/unused.js +4 -15
  41. package/module/builder/builder.js +12 -33
  42. package/module/bundler/bundler.js +3 -3
  43. package/module/cli.js +0 -1
  44. package/module/commands/create-boilerplate.js +6 -19
  45. package/module/commands/generate.js +13 -18
  46. package/module/commands/install.js +14 -17
  47. package/module/file.js +0 -3
  48. package/module/generators/client.js +6 -7
  49. package/module/generators/create-helpers.js +0 -4
  50. package/module/generators/message-composer.js +4 -5
  51. package/module/generators/msg-builder.js +10 -14
  52. package/module/generators/react-query.js +8 -9
  53. package/module/generators/recoil.js +2 -3
  54. package/module/generators/types.js +4 -6
  55. package/module/plugins/client.js +4 -10
  56. package/module/plugins/{msg-builder.js → message-builder.js} +10 -18
  57. package/module/plugins/message-composer.js +4 -10
  58. package/module/plugins/plugin-base.js +10 -10
  59. package/module/plugins/provider-bundle.js +0 -10
  60. package/module/plugins/provider.js +0 -14
  61. package/module/plugins/react-query.js +8 -13
  62. package/module/plugins/recoil.js +2 -9
  63. package/module/plugins/types.js +4 -7
  64. package/module/ts-codegen.js +0 -2
  65. package/module/utils/clean.js +8 -13
  66. package/module/utils/cleanse.js +10 -21
  67. package/module/utils/files.js +2 -6
  68. package/module/utils/parse.js +2 -4
  69. package/module/utils/prompt.js +0 -5
  70. package/module/utils/schemas.js +2 -13
  71. package/module/utils/unused.js +4 -6
  72. package/package.json +3 -3
  73. package/src/builder/builder.ts +7 -6
  74. package/src/commands/generate.ts +13 -12
  75. package/src/generators/msg-builder.ts +7 -9
  76. package/src/plugins/{msg-builder.ts → message-builder.ts} +6 -6
  77. package/src/plugins/message-composer.ts +2 -2
  78. package/types/src/builder/builder.d.ts +3 -2
  79. package/types/src/generators/msg-builder.d.ts +2 -2
  80. package/types/src/generators/msg-builder.ts +2 -2
  81. package/types/src/plugins/message-builder.d.ts +12 -0
  82. package/types/src/plugins/msg-builder.d.ts +1 -1
@@ -1,191 +1,144 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.readSchemas = exports.findQueryMsg = exports.findExecuteMsg = exports.findAndParseTypes = void 0;
9
-
10
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
-
14
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
15
-
16
11
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
17
-
18
12
  var _glob = require("glob");
19
-
20
13
  var _fs = require("fs");
21
-
22
14
  var _cleanse = require("./cleanse");
23
-
24
15
  var _jsonSchemaToTypescript = require("@pyramation/json-schema-to-typescript");
25
-
26
16
  var _parse = require("./parse");
27
-
28
17
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
29
-
30
18
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
31
-
32
19
  ;
33
-
34
20
  var readSchemas = /*#__PURE__*/function () {
35
21
  var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(_ref) {
36
22
  var schemaDir, _ref$clean, clean, fn, files, schemas, idlObject, contract_name, contract_version, idl_version, responses, instantiate, execute, query, migrate, sudo;
37
-
38
23
  return _regenerator["default"].wrap(function _callee$(_context) {
39
- while (1) {
40
- switch (_context.prev = _context.next) {
41
- case 0:
42
- schemaDir = _ref.schemaDir, _ref$clean = _ref.clean, clean = _ref$clean === void 0 ? true : _ref$clean;
43
- fn = clean ? _cleanse.cleanse : function (str) {
44
- return str;
45
- };
46
- files = (0, _glob.sync)(schemaDir + '/**/*.json').filter(function (file) {
47
- return !file.match(/\/raw\//);
48
- });
49
- schemas = files.map(function (file) {
50
- return JSON.parse((0, _fs.readFileSync)(file, 'utf-8'));
51
- });
52
-
53
- if (!(schemas.length > 1)) {
54
- _context.next = 6;
55
- break;
56
- }
57
-
58
- return _context.abrupt("return", {
59
- schemas: fn(schemas)
60
- });
61
-
62
- case 6:
63
- if (!(schemas.length === 0)) {
64
- _context.next = 8;
65
- break;
66
- }
67
-
68
- throw new Error('Error [too few files]: requires one schema file per contract');
69
-
70
- case 8:
71
- if (!(schemas.length !== 1)) {
72
- _context.next = 10;
73
- break;
74
- }
75
-
76
- throw new Error('Error [too many files]: CosmWasm v1.1 schemas supports one file');
77
-
78
- case 10:
79
- idlObject = schemas[0];
80
- contract_name = idlObject.contract_name, contract_version = idlObject.contract_version, idl_version = idlObject.idl_version, responses = idlObject.responses, instantiate = idlObject.instantiate, execute = idlObject.execute, query = idlObject.query, migrate = idlObject.migrate, sudo = idlObject.sudo;
81
-
82
- if (!(typeof idl_version !== 'string')) {
83
- _context.next = 14;
84
- break;
85
- }
86
-
87
- return _context.abrupt("return", {
88
- schemas: fn(schemas)
89
- });
90
-
91
- case 14:
92
- return _context.abrupt("return", {
93
- schemas: [].concat((0, _toConsumableArray2["default"])(Object.values(fn({
94
- instantiate: instantiate,
95
- execute: execute,
96
- query: query,
97
- migrate: migrate,
98
- sudo: sudo
99
- })).filter(Boolean)), (0, _toConsumableArray2["default"])(Object.values(fn(_objectSpread({}, responses))).filter(Boolean))),
100
- responses: responses,
101
- idlObject: idlObject
102
- });
103
-
104
- case 15:
105
- case "end":
106
- return _context.stop();
107
- }
24
+ while (1) switch (_context.prev = _context.next) {
25
+ case 0:
26
+ schemaDir = _ref.schemaDir, _ref$clean = _ref.clean, clean = _ref$clean === void 0 ? true : _ref$clean;
27
+ fn = clean ? _cleanse.cleanse : function (str) {
28
+ return str;
29
+ };
30
+ files = (0, _glob.sync)(schemaDir + '/**/*.json').filter(function (file) {
31
+ return !file.match(/\/raw\//);
32
+ });
33
+ schemas = files.map(function (file) {
34
+ return JSON.parse((0, _fs.readFileSync)(file, 'utf-8'));
35
+ });
36
+ if (!(schemas.length > 1)) {
37
+ _context.next = 6;
38
+ break;
39
+ }
40
+ return _context.abrupt("return", {
41
+ schemas: fn(schemas)
42
+ });
43
+ case 6:
44
+ if (!(schemas.length === 0)) {
45
+ _context.next = 8;
46
+ break;
47
+ }
48
+ throw new Error('Error [too few files]: requires one schema file per contract');
49
+ case 8:
50
+ if (!(schemas.length !== 1)) {
51
+ _context.next = 10;
52
+ break;
53
+ }
54
+ throw new Error('Error [too many files]: CosmWasm v1.1 schemas supports one file');
55
+ case 10:
56
+ idlObject = schemas[0];
57
+ contract_name = idlObject.contract_name, contract_version = idlObject.contract_version, idl_version = idlObject.idl_version, responses = idlObject.responses, instantiate = idlObject.instantiate, execute = idlObject.execute, query = idlObject.query, migrate = idlObject.migrate, sudo = idlObject.sudo;
58
+ if (!(typeof idl_version !== 'string')) {
59
+ _context.next = 14;
60
+ break;
61
+ }
62
+ return _context.abrupt("return", {
63
+ schemas: fn(schemas)
64
+ });
65
+ case 14:
66
+ return _context.abrupt("return", {
67
+ schemas: [].concat((0, _toConsumableArray2["default"])(Object.values(fn({
68
+ instantiate: instantiate,
69
+ execute: execute,
70
+ query: query,
71
+ migrate: migrate,
72
+ sudo: sudo
73
+ })).filter(Boolean)), (0, _toConsumableArray2["default"])(Object.values(fn(_objectSpread({}, responses))).filter(Boolean))),
74
+ responses: responses,
75
+ idlObject: idlObject
76
+ });
77
+ case 15:
78
+ case "end":
79
+ return _context.stop();
108
80
  }
109
81
  }, _callee);
110
82
  }));
111
-
112
83
  return function readSchemas(_x) {
113
84
  return _ref2.apply(this, arguments);
114
85
  };
115
86
  }();
116
-
117
87
  exports.readSchemas = readSchemas;
118
-
119
88
  var findQueryMsg = function findQueryMsg(schemas) {
120
89
  var QueryMsg = schemas.find(function (schema) {
121
90
  return schema.title === 'QueryMsg';
122
91
  });
123
92
  return QueryMsg;
124
93
  };
125
-
126
94
  exports.findQueryMsg = findQueryMsg;
127
-
128
95
  var findExecuteMsg = function findExecuteMsg(schemas) {
129
96
  var ExecuteMsg = schemas.find(function (schema) {
130
97
  return schema.title.startsWith('ExecuteMsg');
131
98
  });
132
99
  return ExecuteMsg;
133
100
  };
134
-
135
101
  exports.findExecuteMsg = findExecuteMsg;
136
-
137
102
  var findAndParseTypes = /*#__PURE__*/function () {
138
103
  var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(schemas) {
139
104
  var Types, allTypes, typ, _i, _Object$keys, key, result, typeHash;
140
-
141
105
  return _regenerator["default"].wrap(function _callee2$(_context2) {
142
- while (1) {
143
- switch (_context2.prev = _context2.next) {
144
- case 0:
145
- Types = schemas;
146
- allTypes = [];
147
- _context2.t0 = _regenerator["default"].keys(Types);
148
-
149
- case 3:
150
- if ((_context2.t1 = _context2.t0()).done) {
151
- _context2.next = 12;
152
- break;
153
- }
154
-
155
- typ = _context2.t1.value;
156
-
157
- if (Types[typ].definitions) {
158
- for (_i = 0, _Object$keys = Object.keys(Types[typ].definitions); _i < _Object$keys.length; _i++) {
159
- key = _Object$keys[_i];
160
- // set title
161
- Types[typ].definitions[key].title = key;
162
- }
163
- }
164
-
165
- _context2.next = 8;
166
- return (0, _jsonSchemaToTypescript.compile)(Types[typ], Types[typ].title);
167
-
168
- case 8:
169
- result = _context2.sent;
170
- allTypes.push(result);
171
- _context2.next = 3;
106
+ while (1) switch (_context2.prev = _context2.next) {
107
+ case 0:
108
+ Types = schemas;
109
+ allTypes = [];
110
+ _context2.t0 = _regenerator["default"].keys(Types);
111
+ case 3:
112
+ if ((_context2.t1 = _context2.t0()).done) {
113
+ _context2.next = 12;
172
114
  break;
173
-
174
- case 12:
175
- typeHash = (0, _parse.parser)(allTypes);
176
- return _context2.abrupt("return", typeHash);
177
-
178
- case 14:
179
- case "end":
180
- return _context2.stop();
181
- }
115
+ }
116
+ typ = _context2.t1.value;
117
+ if (Types[typ].definitions) {
118
+ for (_i = 0, _Object$keys = Object.keys(Types[typ].definitions); _i < _Object$keys.length; _i++) {
119
+ key = _Object$keys[_i];
120
+ // set title
121
+ Types[typ].definitions[key].title = key;
122
+ }
123
+ }
124
+ _context2.next = 8;
125
+ return (0, _jsonSchemaToTypescript.compile)(Types[typ], Types[typ].title);
126
+ case 8:
127
+ result = _context2.sent;
128
+ allTypes.push(result);
129
+ _context2.next = 3;
130
+ break;
131
+ case 12:
132
+ typeHash = (0, _parse.parser)(allTypes);
133
+ return _context2.abrupt("return", typeHash);
134
+ case 14:
135
+ case "end":
136
+ return _context2.stop();
182
137
  }
183
138
  }, _callee2);
184
139
  }));
185
-
186
140
  return function findAndParseTypes(_x2) {
187
141
  return _ref3.apply(this, arguments);
188
142
  };
189
143
  }();
190
-
191
144
  exports.findAndParseTypes = findAndParseTypes;
@@ -1,50 +1,40 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  var _typeof = require("@babel/runtime/helpers/typeof");
6
-
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
8
  exports.unused = void 0;
11
-
12
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
-
14
10
  var t = _interopRequireWildcard(require("@babel/types"));
15
-
16
11
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
-
18
12
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
-
20
13
  //@ts-nocheck
14
+
21
15
  // https://github.com/chuyik/babel-plugin-danger-remove-unused-import
22
16
  // https://github.com/chuyik/babel-plugin-danger-remove-unused-import/blob/c5454c21e94698a2464a12baa5590761932a71a8/License#L1
17
+
23
18
  var unused = {
24
19
  Program: {
25
20
  exit: function exit(path) {
26
21
  var UnRefBindings = new Map();
27
-
28
22
  for (var _i = 0, _Object$entries = Object.entries(path.scope.bindings); _i < _Object$entries.length; _i++) {
29
23
  var _Object$entries$_i = (0, _slicedToArray2["default"])(_Object$entries[_i], 2),
30
- name = _Object$entries$_i[0],
31
- binding = _Object$entries$_i[1];
32
-
24
+ name = _Object$entries$_i[0],
25
+ binding = _Object$entries$_i[1];
33
26
  if (!binding.path.parentPath || binding.kind !== 'module') continue;
34
27
  var source = binding.path.parentPath.get('source');
35
28
  var importName = source.node.value;
36
29
  if (!t.isStringLiteral(source)) continue;
37
30
  var key = "".concat(importName, "(").concat(source.node.loc && source.node.loc.start.line, ")");
38
-
39
31
  if (!UnRefBindings.has(key)) {
40
32
  UnRefBindings.set(key, binding);
41
33
  }
42
-
43
34
  if (binding.referenced) {
44
35
  UnRefBindings.set(key, null);
45
36
  } else {
46
37
  var nodeType = binding.path.node.type;
47
-
48
38
  if (nodeType === 'ImportSpecifier') {
49
39
  binding.path.remove();
50
40
  } else if (nodeType === 'ImportDefaultSpecifier') {
@@ -56,7 +46,6 @@ var unused = {
56
46
  }
57
47
  }
58
48
  }
59
-
60
49
  UnRefBindings.forEach(function (binding, key) {
61
50
  if (binding && binding.path.parentPath) {
62
51
  binding.path.parentPath.remove();
@@ -13,7 +13,7 @@ import generate from '@babel/generator';
13
13
  import * as t from '@babel/types';
14
14
  import { ReactQueryPlugin } from "../plugins/react-query";
15
15
  import { RecoilPlugin } from "../plugins/recoil";
16
- import { MsgBuilderPlugin } from "../plugins/msg-builder";
16
+ import { MessageBuilderPlugin } from "../plugins/message-builder";
17
17
  import { MessageComposerPlugin } from "../plugins/message-composer";
18
18
  import { ClientPlugin } from "../plugins/client";
19
19
  import { TypesPlugin } from "../plugins/types";
@@ -25,13 +25,13 @@ const defaultOpts = {
25
25
  enabled: true,
26
26
  scope: 'contracts',
27
27
  bundleFile: 'bundle.ts'
28
- }
28
+ },
29
+ useShorthandCtor: true
29
30
  };
30
31
  ;
31
32
  ;
32
33
  ;
33
34
  ;
34
-
35
35
  function getContract(contractOpt) {
36
36
  if (typeof contractOpt === 'string') {
37
37
  const name = basename(contractOpt);
@@ -41,18 +41,15 @@ function getContract(contractOpt) {
41
41
  dir: contractOpt
42
42
  };
43
43
  }
44
-
45
44
  return {
46
45
  name: pascal(contractOpt.name),
47
46
  dir: contractOpt.dir
48
47
  };
49
48
  }
50
-
51
49
  export class TSBuilder {
52
50
  loadDefaultPlugins() {
53
- [].push.apply(this.plugins, [new TypesPlugin(this.options), new ClientPlugin(this.options), new MessageComposerPlugin(this.options), new ReactQueryPlugin(this.options), new RecoilPlugin(this.options), new MsgBuilderPlugin(this.options), new ContractsContextProviderPlugin(this.options)]);
51
+ [].push.apply(this.plugins, [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)]);
54
52
  }
55
-
56
53
  constructor({
57
54
  contracts,
58
55
  outPath,
@@ -60,86 +57,71 @@ export class TSBuilder {
60
57
  plugins
61
58
  }) {
62
59
  _defineProperty(this, "contracts", void 0);
63
-
64
60
  _defineProperty(this, "outPath", void 0);
65
-
66
61
  _defineProperty(this, "options", void 0);
67
-
68
62
  _defineProperty(this, "plugins", []);
69
-
70
63
  _defineProperty(this, "builderContext", new BuilderContext());
71
-
72
64
  _defineProperty(this, "files", []);
73
-
74
65
  this.contracts = contracts;
75
66
  this.outPath = outPath;
76
67
  this.options = deepmerge(deepmerge(defaultOptions, defaultOpts), options ?? {});
77
68
  this.loadDefaultPlugins();
78
-
79
69
  if (plugins && plugins.length) {
80
70
  [].push.apply(this.plugins, plugins);
81
71
  }
82
-
83
72
  this.plugins.forEach(plugin => plugin.setBuilder(this));
84
73
  }
85
-
86
74
  async build() {
87
75
  await this.process();
88
76
  await this.after();
89
- } // lifecycle functions
90
-
77
+ }
91
78
 
79
+ // lifecycle functions
92
80
  async process() {
93
81
  for (const contractOpt of this.contracts) {
94
- const contract = getContract(contractOpt); //resolve contract schema.
95
-
82
+ const contract = getContract(contractOpt);
83
+ //resolve contract schema.
96
84
  const contractInfo = await readSchemas({
97
85
  schemaDir: contract.dir
98
- }); //lifecycle and plugins.
86
+ });
99
87
 
88
+ //lifecycle and plugins.
100
89
  await this.render(contract.name, contractInfo);
101
90
  }
102
91
  }
103
-
104
92
  async render(name, contractInfo) {
105
93
  for (const plugin of this.plugins) {
106
94
  let files = await plugin.render(name, contractInfo, this.outPath);
107
-
108
95
  if (files && files.length) {
109
96
  [].push.apply(this.files, files);
110
97
  }
111
98
  }
112
99
  }
113
-
114
100
  async after() {
115
101
  //create useContracts bundle file
116
102
  const contractsProviderBundlePlugin = new ContractsProviderBundlePlugin(this.options);
117
- contractsProviderBundlePlugin.setBuilder(this); //contractContextProviders.ts
103
+ contractsProviderBundlePlugin.setBuilder(this);
118
104
 
105
+ //contractContextProviders.ts
119
106
  const files = await contractsProviderBundlePlugin.render("contractContextProviders", {
120
107
  schemas: []
121
108
  }, this.outPath);
122
-
123
109
  if (files && files.length) {
124
110
  [].push.apply(this.files, files);
125
111
  }
126
-
127
112
  const helpers = createHelpers({
128
113
  outPath: this.outPath,
129
114
  contracts: this.contracts,
130
115
  options: this.options,
131
116
  plugins: this.plugins
132
117
  }, this.builderContext);
133
-
134
118
  if (helpers && helpers.length) {
135
119
  [].push.apply(this.files, helpers);
136
120
  }
137
-
138
121
  if (this.options.bundle.enabled) {
139
122
  this.bundle();
140
123
  }
141
124
  }
142
-
143
125
  async bundle() {
144
126
  const allFiles = this.files;
145
127
  const bundleFile = this.options.bundle.bundleFile;
@@ -151,14 +133,11 @@ export class TSBuilder {
151
133
  });
152
134
  const ast = recursiveModuleBundle(bundleVariables);
153
135
  let code = generate(t.program([...importPaths, ...ast])).code;
154
-
155
136
  if (this.options?.bundle?.bundlePath) {
156
137
  mkdirp(this.options?.bundle?.bundlePath);
157
138
  }
158
-
159
139
  mkdirp(this.outPath);
160
140
  if (code.trim() === '') code = 'export {};';
161
141
  writeFileSync(bundlePath, header + code);
162
142
  }
163
-
164
143
  }
@@ -8,14 +8,14 @@ export const recursiveModuleBundle = obj => {
8
8
  // 1. create variable for abci
9
9
  // 2. splat ALL _0, parms into abci
10
10
  // 3. export that variable
11
+
11
12
  const nmspc = t.variableDeclaration('const', [t.variableDeclarator(t.identifier(key), t.objectExpression(Object.keys(obj[key]).filter(a => a !== '__export').filter(a => a.startsWith('_')).map(a => t.spreadElement(t.identifier(a)))))]);
12
13
  const others = Object.keys(obj[key]).filter(a => a !== '__export').filter(a => !a.startsWith('_'));
13
-
14
14
  if (others.length) {
15
15
  throw new Error('namespace and package not supported, yet.');
16
- } // return nmspc;
17
-
16
+ }
18
17
 
18
+ // return nmspc;
19
19
  return t.exportNamedDeclaration(nmspc, []);
20
20
  } else {
21
21
  // you can make a namespace for obj[key]
package/module/cli.js CHANGED
@@ -11,7 +11,6 @@ export const cli = async argv => {
11
11
  var {
12
12
  cmd
13
13
  } = await prompt(question, argv);
14
-
15
14
  if (typeof commands[cmd] === 'function') {
16
15
  await commands[cmd](argv);
17
16
  } else {
@@ -1,26 +1,18 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
-
3
2
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
-
5
3
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
-
7
4
  import * as shell from 'shelljs';
8
5
  import { prompt } from '../utils/prompt';
9
6
  import dargs from 'dargs';
10
-
11
7
  const glob = require('glob').sync;
12
-
13
8
  const fs = require('fs');
14
-
15
9
  const path = require('path');
16
-
17
10
  const repo = 'https://github.com/cosmology-tech/ts-codegen-module-boilerplate';
18
11
  export default (async argv => {
19
12
  if (!shell.which('git')) {
20
13
  shell.echo('Sorry, this script requires git');
21
14
  return shell.exit(1);
22
15
  }
23
-
24
16
  const {
25
17
  name
26
18
  } = await prompt([{
@@ -36,9 +28,10 @@ export default (async argv => {
36
28
  }).trim();
37
29
  const email = shell.exec('git config --global user.email', {
38
30
  silent: true
39
- }).trim(); // @__USERNAME__/__MODULENAME__
40
- // __PACKAGE_IDENTIFIER__
31
+ }).trim();
41
32
 
33
+ // @__USERNAME__/__MODULENAME__
34
+ // __PACKAGE_IDENTIFIER__
42
35
  const args = dargs(_objectSpread(_objectSpread({
43
36
  _: []
44
37
  }, argv), {}, {
@@ -57,7 +50,6 @@ export default (async argv => {
57
50
  type: 'list',
58
51
  required: true
59
52
  }], []);
60
-
61
53
  if (results.__ACCESS__ === 'public') {
62
54
  scopedResults = await prompt([{
63
55
  type: 'confirm',
@@ -66,26 +58,21 @@ export default (async argv => {
66
58
  required: true
67
59
  }], []);
68
60
  }
69
-
70
61
  const files = [].concat(glob(process.cwd() + '/**/.*')).concat(glob(process.cwd() + '/**/*'));
71
-
72
62
  for (let i = 0; i < files.length; i++) {
73
63
  const templateFile = files[i];
74
64
  if (fs.lstatSync(templateFile).isDirectory()) continue;
75
65
  let content = fs.readFileSync(templateFile).toString();
76
-
77
66
  if (path.basename(templateFile) === 'LICENSE' && license.__LICENSE__ === 'closed') {
78
67
  content = `Copyright (c) 2023 __USERFULLNAME__ <__USEREMAIL__> - All Rights Reserved
79
68
  Unauthorized copying via any medium is strictly prohibited
80
69
  Proprietary and confidential`;
81
70
  }
82
-
83
71
  Object.keys(results).forEach(key => {
84
72
  if (/^__/.test(key)) {
85
73
  content = content.replace(new RegExp(key, 'g'), results[key]);
86
74
  }
87
75
  });
88
-
89
76
  if (results.__ACCESS__ === 'public') {
90
77
  if (scopedResults.scoped) {
91
78
  content = content.replace(/__PACKAGE_IDENTIFIER__/g, `@${results.__USERNAME__}/${results.__MODULENAME__}`);
@@ -94,14 +81,14 @@ Proprietary and confidential`;
94
81
  }
95
82
  } else {
96
83
  content = content.replace(/__PACKAGE_IDENTIFIER__/g, `@${results.__USERNAME__}/${results.__MODULENAME__}`);
97
- } // if (path.basename(templateFile) === 'README.md') {
84
+ }
85
+
86
+ // if (path.basename(templateFile) === 'README.md') {
98
87
  // content = `# ${results.__MODULENAME__}`;
99
88
  // }
100
89
 
101
-
102
90
  fs.writeFileSync(templateFile, content);
103
91
  }
104
-
105
92
  shell.rm('-rf', '.git');
106
93
  shell.rm('-rf', '.questions.json');
107
94
  console.log(`