UI for Zipcoin Blue

generate.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const tslib_1 = require("tslib");
  4. const app_scripts_1 = require("./app-scripts");
  5. function generate(args) {
  6. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  7. const { minimistOptionsToArray } = yield Promise.resolve().then(() => require('../utils/command'));
  8. if (!args.env.project.directory) {
  9. return [];
  10. }
  11. const appScriptsArgs = minimistOptionsToArray(args.options, { useEquals: false, ignoreFalse: true, allowCamelCase: true });
  12. process.argv = ['node', 'appscripts'].concat(appScriptsArgs);
  13. const AppScripts = yield app_scripts_1.importAppScripts(args.env);
  14. const context = AppScripts.generateContext();
  15. const [type, name] = args.inputs;
  16. const commandOptions = {
  17. module: false,
  18. constants: false,
  19. };
  20. if (args.options['module']) {
  21. commandOptions.module = true;
  22. }
  23. if (args.options['constants']) {
  24. commandOptions.constants = true;
  25. }
  26. switch (type) {
  27. case 'page':
  28. yield AppScripts.processPageRequest(context, name, commandOptions);
  29. break;
  30. case 'component':
  31. const componentData = yield getModules(context, 'component');
  32. yield AppScripts.processComponentRequest(context, name, componentData);
  33. break;
  34. case 'directive':
  35. const directiveData = yield getModules(context, 'directive');
  36. yield AppScripts.processDirectiveRequest(context, name, directiveData);
  37. break;
  38. case 'pipe':
  39. const pipeData = yield getModules(context, 'pipe');
  40. yield AppScripts.processPipeRequest(context, name, pipeData);
  41. break;
  42. case 'provider':
  43. const providerData = yield promptQuestions(context);
  44. yield AppScripts.processProviderRequest(context, name, providerData);
  45. break;
  46. case 'tabs':
  47. const tabsData = yield tabsPrompt(args.env);
  48. yield AppScripts.processTabsRequest(context, name, tabsData, commandOptions);
  49. break;
  50. }
  51. return [];
  52. });
  53. }
  54. exports.generate = generate;
  55. function promptQuestions(context) {
  56. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  57. return yield prompt(context);
  58. });
  59. }
  60. // async function getPages(context: any) {
  61. // const AppScripts = await import('@ionic/app-scripts');
  62. // const pages = await AppScripts.getNgModules(context, ['page', 'component']);
  63. // const ngModuleSuffix = await AppScripts.getStringPropertyValue('IONIC_NG_MODULE_FILENAME_SUFFIX');
  64. // return pages.map((page: any) => {
  65. // return {
  66. // fileName: path.basename(page.absolutePath, ngModuleSuffix),
  67. // absolutePath: page.absolutePath,
  68. // relativePath: path.relative(context.rootDir, page.absolutePath)
  69. // };
  70. // });
  71. // }
  72. function prompt(context) {
  73. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  74. return context.appNgModulePath;
  75. });
  76. }
  77. function getModules(context, kind) {
  78. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  79. switch (kind) {
  80. case 'component':
  81. return context.componentsNgModulePath ? context.componentsNgModulePath : context.appNgModulePath;
  82. case 'pipe':
  83. return context.pipesNgModulePath ? context.pipesNgModulePath : context.appNgModulePath;
  84. case 'directive':
  85. return context.directivesNgModulePath ? context.directivesNgModulePath : context.appNgModulePath;
  86. }
  87. });
  88. }
  89. function tabsPrompt(env) {
  90. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  91. const { validators } = yield Promise.resolve().then(() => require('@ionic/cli-framework/lib'));
  92. const tabNames = [];
  93. const howMany = yield env.prompt({
  94. type: 'input',
  95. name: 'howMany',
  96. message: 'How many tabs?',
  97. validate: v => validators.numeric(v),
  98. });
  99. for (let i = 0; i < parseInt(howMany, 10); i++) {
  100. const tabName = yield env.prompt({
  101. type: 'input',
  102. name: 'tabName',
  103. message: 'Name of this tab:'
  104. });
  105. tabNames.push(tabName);
  106. }
  107. return tabNames;
  108. });
  109. }
  110. exports.tabsPrompt = tabsPrompt;