UNPKG

3.31 kBJavaScriptView Raw
1"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=require("@diez/storage"),a=require("@sentry/node"),t=require("commander"),o=require("./reporting"),n=require("./utils");t.version(n.diezVersion).name("diez");const s=(e,a)=>{if(a)for(const t of a){let a=t.shortName?`-${t.shortName}, --${t.longName}`:`--${t.longName}`;t.valueName&&(a+=` <${t.valueName}>`),e.command.option(a,t.description),t.validator&&e.validators.push(t.validator)}},i=async(e,n)=>{e.preinstall&&await e.preinstall();const i=[],r=t.command(e.name).action(async(...t)=>{try{const s=Object.assign({},n,r);await Promise.all(i.map(e=>e(s)));const c=await e.loadAction(),l=(e=>e.hasOwnProperty("default"))(c)?c.default:c;await l.call(void 0,s,...t)}catch(e){if(!global.doNotTrack){a.captureException(e);const t=a.getCurrentHub().getClient();t&&await t.close(1e3)}e.stack?o.Log.error(e.stack):o.Log.error(e.message),process.exit(1)}}),c={validators:i,command:r};return e.description&&r.description(e.description),s(c,e.options),c},r=async(e,a,t,s)=>{if(s)for(const r of s)try{const s=n.cliRequire(a,r);if(e.has(s.name)){o.Log.warning(`Ignoring attempt to reregister command ${s.name}.`);continue}e.set(s.name,await i(s,t[s.name]))}catch(e){o.Log.warning(`An invalid command provider was specified at ${r}.`),o.Log.warning(e.message)}};exports.bootstrap=(async(e=global.process.cwd(),a)=>{const t=await n.findPlugins(e,a),i=new Map,c=[],l={};t.has(".")&&Object.assign(l,t.get(".").commandOptions);for(const[e,{providers:a}]of t)if(a&&(await r(i,e,l,a.commands),a.extensions))for(const t of a.extensions)try{c.push(n.cliRequire(e,t))}catch(e){o.Log.warning(`An invalid command extension was specified at ${t}.`)}for(const e of c)for(const a of e.names){const t=i.get(a);t&&s(t,e.options)}}),exports.run=(async s=>{const i=await e.Registry.get("analyticsEnabled"),r=!!global.process.env.DIEZ_DO_NOT_TRACK;global.doNotTrack=!i||r,void 0!==i||r||process.argv.includes("analytics")||(o.Log.infoTitle("Anonymous aggregate analytics:"),o.Log.info("\nDiez collects diagnostic and usage data each time you use the CLI using an\nanonymous, randomly generated ID. This ID is also used to report crashes\nthrough Sentry (IP address storage is disabled). We use these data to help\nimprove our services.\n\nBy default, anonymous aggregate analytics and crash reporting will be activated\nthe next time you run a Diez command. Learn more about what data we collect and\nhow to opt out here: https://diez.org/analytics\n"),await e.enableAnalytics()),global.doNotTrack||(global.analyticsUuid=await e.Registry.get("uuid"),e.emitDiagnostics("activity",n.diezVersion).catch(()=>{}),a.init({dsn:"https://58599c81fc834e9cb29d235c1e99b892@sentry.io/1460669",release:`v${n.diezVersion}`,beforeSend:e=>{const a=e.exception&&e.exception.values&&e.exception.values[0].stacktrace;if(a&&a.frames)for(const e of a.frames)e.filename&&e.filename.includes("@diez/")&&(e.filename=`app://${e.filename.replace(/^.*@diez/,"/@diez")}`);return e}}),a.configureScope(a=>{a.setUser({id:global.analyticsUuid}),a.setExtra("command_arguments",e.getCommandArguments())})),await exports.bootstrap(global.process.cwd(),s),t.on("command:*",()=>t.outputHelp()),t.parse(process.argv),t.args.length||t.outputHelp()});
2//# sourceMappingURL=/@diez/cli-core/lib/cli.js.map
\No newline at end of file