@builderbot/cli 1.1.5 → 1.1.6-y.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/bin/cli.cjs CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
  const index = require('../dist/index.cjs')
3
- index.startInteractive()
3
+ index.start()
package/dist/index.cjs CHANGED
@@ -9120,12 +9120,8 @@ const createApp = async (templateName) => {
9120
9120
  await promises.rename(require$$1.join(pathTemplate, '_gitignore'), require$$1.join(pathTemplate, '.gitignore'));
9121
9121
  return pathTemplate;
9122
9122
  };
9123
- const startInteractive = async () => {
9123
+ const startInteractive = async (version) => {
9124
9124
  try {
9125
- const version = await getVersion();
9126
- console.clear();
9127
- console.log('');
9128
- oe(` Let's create a ${color.bgCyan(' Chatbot ' + 'v' + version)} ✨`);
9129
9125
  const stepContinue = await se({
9130
9126
  message: 'Do you want to continue?',
9131
9127
  });
@@ -9161,6 +9157,19 @@ const startInteractive = async () => {
9161
9157
  ue('Operation canceled');
9162
9158
  return process.exit(0);
9163
9159
  }
9160
+ await createBot({
9161
+ stepLanguage: stepLanguage,
9162
+ stepProvider: stepProvider,
9163
+ stepDatabase: stepDatabase,
9164
+ version,
9165
+ });
9166
+ }
9167
+ catch (e) {
9168
+ logError(e);
9169
+ }
9170
+ };
9171
+ const createBot = async ({ stepLanguage, stepProvider, stepDatabase, version, }) => {
9172
+ try {
9164
9173
  const s = de();
9165
9174
  s.start('Checking requirements');
9166
9175
  await systemRequirements();
@@ -9174,15 +9183,79 @@ const startInteractive = async () => {
9174
9183
  $e(color.bgGreen(' Successfully completed! '));
9175
9184
  }
9176
9185
  catch (e) {
9177
- console.log(e);
9178
- if (e?.code === 'ERR_TTY_INIT_FAILED')
9179
- return handleLegacyCli();
9180
- ue([`Oops! 🙄 something is not right.`, `Check the minimum requirements in the documentation`].join('\n'));
9181
- return process.exit(0);
9186
+ logError(e);
9187
+ }
9188
+ };
9189
+ const startWithArgs = async (version, args) => {
9190
+ try {
9191
+ const stepProvider = args['provider'];
9192
+ const stepDatabase = args['database'];
9193
+ const stepLanguage = args['language'];
9194
+ await createBot({
9195
+ stepLanguage,
9196
+ stepProvider,
9197
+ stepDatabase,
9198
+ version,
9199
+ });
9200
+ }
9201
+ catch (e) {
9202
+ logError(e);
9203
+ }
9204
+ };
9205
+ function getArgs(args) {
9206
+ const result = {};
9207
+ for (let i = 0; i < args.length; i++) {
9208
+ const arg = args[i];
9209
+ if (arg.startsWith('--')) {
9210
+ const [key, value] = arg.split('=');
9211
+ result[key.slice(2)] = value;
9212
+ }
9213
+ }
9214
+ return result;
9215
+ }
9216
+ function validateArgs(args) {
9217
+ if (!args['provider'] || !args['database'] || !args['language']) {
9218
+ ue(`\nInvalid arguments: You must send all three arguments: --provider, --database and --language
9219
+ \nExample: --provider=baileys --database=mongo --language=js
9220
+ \nIf you want to use the interactive mode, just run the command without arguments.`);
9221
+ process.exit(0);
9222
+ }
9223
+ if (args['provider'] && !PROVIDER_LIST.some((p) => p.value === args['provider'])) {
9224
+ ue(`Invalid provider: ${args['provider']}`);
9225
+ process.exit(0);
9226
+ }
9227
+ if (args['database'] && !PROVIDER_DATA.some((p) => p.value === args['database'])) {
9228
+ ue(`Invalid database: ${args['database']}`);
9229
+ process.exit(0);
9230
+ }
9231
+ if (args['language'] && !AVAILABLE_LANGUAGES.some((p) => p.value === args['language'])) {
9232
+ ue(`Invalid language: ${args['language']}`);
9233
+ process.exit(0);
9234
+ }
9235
+ }
9236
+ const logError = async (e) => {
9237
+ console.log(e);
9238
+ if (e?.code === 'ERR_TTY_INIT_FAILED')
9239
+ return handleLegacyCli();
9240
+ ue([`Oops! 🙄 something is not right.`, `Check the minimum requirements in the documentation`].join('\n'));
9241
+ return process.exit(0);
9242
+ };
9243
+ const start = async () => {
9244
+ const version = await getVersion();
9245
+ console.clear();
9246
+ console.log('');
9247
+ oe(` Let's create a ${color.bgCyan(' Chatbot ' + 'v' + version)} ✨`);
9248
+ const args = getArgs(process.argv.slice(2));
9249
+ if (!Object.keys(args).length) {
9250
+ await startInteractive(version);
9251
+ }
9252
+ else {
9253
+ validateArgs(args);
9254
+ await startWithArgs(version, args);
9182
9255
  }
9183
9256
  };
9184
9257
 
9185
9258
  if (process.env.NODE_ENV === 'dev')
9186
- startInteractive();
9259
+ start();
9187
9260
 
9188
- exports.startInteractive = startInteractive;
9261
+ exports.start = start;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { startInteractive } from './interactive';
2
- export { startInteractive };
1
+ import { start } from './interactive';
2
+ export { start };
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEhD,OAAO,EAAE,gBAAgB,EAAE,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAErC,OAAO,EAAE,KAAK,EAAE,CAAA"}
@@ -1,3 +1,3 @@
1
- declare const startInteractive: () => Promise<void>;
2
- export { startInteractive };
1
+ declare const start: () => Promise<void>;
2
+ export { start };
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interactive/index.ts"],"names":[],"mappings":"AAkHA,QAAA,MAAM,gBAAgB,QAAa,QAAQ,IAAI,CAsE9C,CAAA;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interactive/index.ts"],"names":[],"mappings":"AAgQA,QAAA,MAAM,KAAK,QAAa,QAAQ,IAAI,CAanC,CAAA;AAED,OAAO,EAAE,KAAK,EAAE,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builderbot/cli",
3
- "version": "1.1.5",
3
+ "version": "1.1.6-y.0",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs",
6
6
  "types": "dist/index.d.ts",
@@ -41,5 +41,5 @@
41
41
  "type": "git",
42
42
  "url": "https://github.com/codigoencasa/bot-whatsapp/tree/main/packages/cli"
43
43
  },
44
- "gitHead": "4d84c286c2e440c998de1c19d4d43b7d5bf6e7bc"
44
+ "gitHead": "d56d7f50d1d141a70c2b7ba5625e080411f8e9ee"
45
45
  }