pinstripe 0.15.0 → 0.16.1

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 (225) hide show
  1. package/LICENSE +1 -1
  2. package/babel.config.cjs +18 -0
  3. package/cli.js +10 -8
  4. package/jest.config.cjs +6 -0
  5. package/lib/class.js +64 -0
  6. package/lib/client.js +13 -41
  7. package/lib/command.js +16 -58
  8. package/lib/commands/_file_importer.js +1 -0
  9. package/lib/commands/drop_database.js +5 -1
  10. package/lib/commands/generate_command.js +33 -26
  11. package/lib/commands/generate_migration.js +40 -38
  12. package/lib/commands/generate_model.js +38 -39
  13. package/lib/commands/generate_node_wrapper.js +34 -33
  14. package/lib/commands/generate_project.js +58 -58
  15. package/lib/commands/generate_service.js +28 -28
  16. package/lib/commands/generate_static_site.js +6 -10
  17. package/lib/commands/generate_view.js +40 -31
  18. package/lib/commands/init_database.js +8 -5
  19. package/lib/commands/list_commands.js +11 -8
  20. package/lib/commands/list_components.js +16 -0
  21. package/lib/commands/list_migrations.js +11 -8
  22. package/lib/commands/list_models.js +11 -8
  23. package/lib/commands/list_services.js +11 -9
  24. package/lib/commands/list_views.js +12 -8
  25. package/lib/commands/migrate_database.js +5 -1
  26. package/lib/commands/purge_old_sessions.js +1 -1
  27. package/lib/commands/reset_database.js +7 -3
  28. package/lib/commands/seed_database.js +4 -2
  29. package/lib/commands/start_repl.js +6 -0
  30. package/lib/commands/start_server.js +6 -75
  31. package/lib/{node_wrapper.js → component.js} +160 -154
  32. package/lib/components/_file_importer.js +1 -0
  33. package/lib/{node_wrappers → components}/helpers.js +12 -9
  34. package/lib/{node_wrappers/anchor.client.js → components/pinstripe_anchor.js} +2 -2
  35. package/lib/components/pinstripe_body.js +33 -0
  36. package/lib/components/pinstripe_document.js +49 -0
  37. package/lib/{node_wrappers/form.client.js → components/pinstripe_form.js} +4 -6
  38. package/lib/components/pinstripe_frame.js +47 -0
  39. package/lib/components/pinstripe_markdown_editor.js +74 -0
  40. package/lib/components/pinstripe_overlay.js +58 -0
  41. package/lib/components/pinstripe_progress_bar.js +76 -0
  42. package/lib/constants.js +1 -0
  43. package/lib/context.js +40 -0
  44. package/lib/database/client.js +199 -0
  45. package/lib/database/column_reference.js +13 -0
  46. package/lib/database/constants.js +64 -18
  47. package/lib/database/index.js +7 -0
  48. package/lib/database/migration.js +10 -54
  49. package/lib/database/migrator.js +18 -31
  50. package/lib/database/row.js +278 -181
  51. package/lib/database/singleton.js +12 -0
  52. package/lib/database/table.js +425 -255
  53. package/lib/database/table_reference.js +33 -0
  54. package/lib/database/union.js +87 -107
  55. package/lib/database.js +104 -76
  56. package/lib/defer.js +35 -0
  57. package/lib/{async_path_builder.test.js → defer.test.js} +9 -10
  58. package/lib/event_wrapper.js +13 -18
  59. package/lib/extensions/{_importer.js → _file_importer.js} +0 -0
  60. package/lib/extensions/multi-app/index.js +4 -0
  61. package/lib/extensions/multi-app/views/_file_importer.js +2 -0
  62. package/lib/extensions/multi-app/views/apps/default.js +6 -0
  63. package/lib/extensions/multi-app/views/apps/guard.js +7 -0
  64. package/lib/extensions/multi-app/views/guard.js +21 -0
  65. package/lib/extensions/multi-tenant/database/row.js +27 -0
  66. package/lib/extensions/multi-tenant/database/table.js +16 -4
  67. package/lib/extensions/multi-tenant/database.js +24 -1
  68. package/lib/extensions/multi-tenant/services/_file_importer.js +2 -0
  69. package/lib/extensions/multi-tenant/services/database.js +17 -0
  70. package/lib/extensions/multi-tenant/services/migrations/1627976174_create_tenant_table_and_add_tenant_id_to_existing_tables.js +20 -0
  71. package/lib/extensions/multi-tenant/services/migrations/_file_importer.js +2 -0
  72. package/lib/html.js +23 -22
  73. package/lib/import_all.js +26 -30
  74. package/lib/index.js +14 -20
  75. package/lib/inflector.js +165 -172
  76. package/lib/initialize.js +11 -0
  77. package/lib/migrations/1627976184_create_user.js +11 -7
  78. package/lib/migrations/1628057822_create_session.js +8 -6
  79. package/lib/migrations/_file_importer.js +1 -0
  80. package/lib/{validatable.js → model.js} +51 -7
  81. package/lib/models/_file_importer.js +1 -0
  82. package/lib/models/user.js +36 -28
  83. package/lib/project.js +7 -4
  84. package/lib/registry.js +133 -0
  85. package/lib/service_consumer.js +16 -0
  86. package/lib/service_factory.js +8 -87
  87. package/lib/services/_file_importer.js +1 -0
  88. package/lib/services/args.js +8 -1
  89. package/lib/services/bot.js +12 -12
  90. package/lib/services/cli_utils.js +69 -63
  91. package/lib/services/client_builder.js +68 -0
  92. package/lib/services/config.js +34 -15
  93. package/lib/services/cookies.js +13 -14
  94. package/lib/services/create_model.js +8 -0
  95. package/lib/services/database.js +8 -6
  96. package/lib/services/defer.js +8 -0
  97. package/lib/services/fetch.js +82 -75
  98. package/lib/services/format_date.js +4 -2
  99. package/lib/services/fs_builder.js +120 -118
  100. package/lib/services/inflector.js +8 -0
  101. package/lib/services/initial_params.js +13 -0
  102. package/lib/services/params.js +12 -6
  103. package/lib/services/parse_html.js +8 -0
  104. package/lib/services/project.js +6 -2
  105. package/lib/services/render_form.js +42 -105
  106. package/lib/services/render_html.js +5 -3
  107. package/lib/services/render_markdown.js +31 -31
  108. package/lib/services/render_view.js +4 -14
  109. package/lib/services/repl.js +54 -0
  110. package/lib/services/run_command.js +4 -5
  111. package/lib/services/send_mail.js +30 -26
  112. package/lib/services/server.js +92 -0
  113. package/lib/services/session.js +15 -11
  114. package/lib/services/view_names.js +4 -2
  115. package/lib/singleton.js +13 -0
  116. package/lib/string_reader.js +6 -8
  117. package/lib/trapify.js +32 -0
  118. package/lib/unescape_html.test.js +3 -0
  119. package/lib/view.js +33 -115
  120. package/lib/view_file_importers/ejs.js +82 -0
  121. package/lib/view_file_importers/md.js +42 -0
  122. package/lib/views/_file_importer.js +1 -0
  123. package/lib/views/assets/javascripts/all.js.js +7 -0
  124. package/lib/views/assets/javascripts/all.js.map.js +7 -0
  125. package/lib/views/assets/stylesheets/all.css.js +28 -0
  126. package/lib/views/assets/stylesheets/components/button.css +43 -0
  127. package/lib/views/assets/stylesheets/components/card.css +29 -0
  128. package/lib/views/assets/stylesheets/components/form.css +4 -0
  129. package/lib/views/assets/stylesheets/components/frame.css +3 -0
  130. package/lib/views/assets/stylesheets/components/input.css +40 -0
  131. package/lib/views/assets/stylesheets/components/label.css +9 -0
  132. package/lib/views/assets/stylesheets/components/modal.css +62 -0
  133. package/lib/views/assets/stylesheets/components/overlay.css +11 -0
  134. package/lib/views/assets/stylesheets/components/pagination.css +60 -0
  135. package/lib/views/assets/stylesheets/components/progress_bar.css +20 -0
  136. package/lib/views/assets/stylesheets/components/textarea.css +10 -0
  137. package/lib/views/{main → assets}/stylesheets/global.css +0 -0
  138. package/lib/views/{main → assets}/stylesheets/reset.css +0 -0
  139. package/lib/views/{main → assets}/stylesheets/vars.css +0 -0
  140. package/lib/views/sign_in/index.js +32 -0
  141. package/lib/views/sign_in/verify_password.js +52 -0
  142. package/lib/views/sign_out.js +16 -0
  143. package/lib/virtual_node.js +30 -33
  144. package/lib/virtual_node.test.js +4 -0
  145. package/lib/workspace.js +21 -0
  146. package/package.json +16 -7
  147. package/README.md +0 -10
  148. package/lib/async_path_builder.js +0 -56
  149. package/lib/base.js +0 -140
  150. package/lib/base.test.js +0 -98
  151. package/lib/commands/_importer.js +0 -2
  152. package/lib/commands/create_database.js +0 -2
  153. package/lib/commands/list_node_wrappers.js +0 -12
  154. package/lib/commands/start_console.js +0 -49
  155. package/lib/css.js +0 -101
  156. package/lib/database/adapter.js +0 -23
  157. package/lib/database/adapters/mysql.js +0 -673
  158. package/lib/database/adapters/sqlite.js +0 -649
  159. package/lib/database/column.js +0 -52
  160. package/lib/database/sql.js +0 -77
  161. package/lib/database/sql.test.js +0 -58
  162. package/lib/environment.js +0 -38
  163. package/lib/extensions/multi-tenant/migrations/1627976174_create_tenant_table_and_add_tenant_id_to_existing_tables.js +0 -16
  164. package/lib/extensions/multi-tenant/migrations/_importer.js +0 -2
  165. package/lib/extensions/multi-tenant/models/_importer.js +0 -2
  166. package/lib/extensions/multi-tenant/models/tenant.js +0 -7
  167. package/lib/extensions/multi-tenant/services/_importer.js +0 -2
  168. package/lib/extensions/multi-tenant/services/tenant.js +0 -7
  169. package/lib/get_all_props.js +0 -12
  170. package/lib/hookable.js +0 -39
  171. package/lib/initialize.client.js +0 -11
  172. package/lib/migrations/_importer.js +0 -2
  173. package/lib/models/_importer.js +0 -2
  174. package/lib/node_wrappers/_importer.js +0 -2
  175. package/lib/node_wrappers/document.client.js +0 -42
  176. package/lib/node_wrappers/frame.client.js +0 -105
  177. package/lib/node_wrappers/markdown_editor/line_inserter.client.js +0 -14
  178. package/lib/node_wrappers/markdown_editor.client.js +0 -41
  179. package/lib/node_wrappers/overlay.client.js +0 -39
  180. package/lib/node_wrappers/progress_bar.client.js +0 -43
  181. package/lib/overload.js +0 -68
  182. package/lib/overload.test.js +0 -153
  183. package/lib/registrable.js +0 -85
  184. package/lib/services/_importer.js +0 -2
  185. package/lib/services/app.js +0 -2
  186. package/lib/services/command_names.js +0 -6
  187. package/lib/services/fork_environment.js +0 -16
  188. package/lib/services/global.js +0 -9
  189. package/lib/services/migration_names.js +0 -6
  190. package/lib/services/model_names.js +0 -6
  191. package/lib/services/node_wrapper_names.js +0 -6
  192. package/lib/services/read_file.js +0 -6
  193. package/lib/services/render_css.js +0 -6
  194. package/lib/services/render_file.js +0 -9
  195. package/lib/services/render_frame.js +0 -11
  196. package/lib/services/render_list.js +0 -58
  197. package/lib/services/render_table.js +0 -67
  198. package/lib/services/reset_environment.js +0 -19
  199. package/lib/services/service_names.js +0 -6
  200. package/lib/services/stylesheets.js +0 -16
  201. package/lib/services/theme_config.js +0 -76
  202. package/lib/services/view.js +0 -4
  203. package/lib/thatify.js +0 -6
  204. package/lib/url.js +0 -97
  205. package/lib/url.test.js +0 -25
  206. package/lib/views/_importer.js +0 -2
  207. package/lib/views/main/_layout.js +0 -53
  208. package/lib/views/main/blocks/default.js +0 -23
  209. package/lib/views/main/blocks/help.js +0 -139
  210. package/lib/views/main/bundle.js.js +0 -36
  211. package/lib/views/main/sign_in.js +0 -40
  212. package/lib/views/main/sign_out.js +0 -15
  213. package/lib/views/main/stylesheets/components/button.css.js +0 -56
  214. package/lib/views/main/stylesheets/components/card.css.js +0 -41
  215. package/lib/views/main/stylesheets/components/form.css.js +0 -11
  216. package/lib/views/main/stylesheets/components/frame.css.js +0 -10
  217. package/lib/views/main/stylesheets/components/input.css.js +0 -54
  218. package/lib/views/main/stylesheets/components/label.css.js +0 -14
  219. package/lib/views/main/stylesheets/components/markdown_editor.css.js +0 -53
  220. package/lib/views/main/stylesheets/components/modal.css.js +0 -77
  221. package/lib/views/main/stylesheets/components/overlay.css.js +0 -17
  222. package/lib/views/main/stylesheets/components/pagination.css.js +0 -80
  223. package/lib/views/main/stylesheets/components/progress_bar.css.js +0 -32
  224. package/lib/views/main/stylesheets/components/textarea.css.js +0 -17
  225. package/pinstripe_development.db +0 -0
package/LICENSE CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2020 Jody Salt
2
+ Copyright (c) 2022 Jody Salt
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,18 @@
1
+ module.exports = {
2
+ presets: [
3
+ [
4
+ '@babel/preset-env',
5
+ {
6
+ targets: {
7
+ node: 'current',
8
+ },
9
+ },
10
+ ],
11
+ ],
12
+ env: {
13
+ test: {
14
+ plugins: ["@babel/plugin-transform-modules-commonjs"]
15
+ }
16
+ }
17
+ };
18
+
package/cli.js CHANGED
@@ -2,12 +2,13 @@
2
2
 
3
3
  import { spawn } from 'child_process';
4
4
 
5
- import { project } from './lib/project.js';
5
+ import { Project } from './lib/project.js';
6
6
  import { Command } from './lib/command.js';
7
- import { createEnvironment } from './lib/environment.js';
7
+ import { importAll } from './lib/import_all.js';
8
+ import { Workspace } from './lib/workspace.js';
8
9
 
9
10
  (async () => {
10
- const { entryPath, localPinstripePath, exists } = await project;
11
+ const { entryPath, localPinstripePath, exists } = await Project.instance;
11
12
  const { argv, env, execPath } = process;
12
13
  const args = argv.slice(2);
13
14
 
@@ -21,13 +22,13 @@ import { createEnvironment } from './lib/environment.js';
21
22
  import(entryPath);
22
23
  }
23
24
 
24
- const { runCommand, resetEnvironment } = await createEnvironment();
25
+ await importAll();
25
26
 
26
27
  if(exists){
27
28
  Command.unregister('generate-project');
28
29
  } else {
29
- const allowedCommands = ['generate-project', 'list-commands']
30
- Object.keys(Command.classes).forEach(commandName => {
30
+ const allowedCommands = ['generate-project', 'list-commands'];
31
+ Command.names.forEach(commandName => {
31
32
  if(!allowedCommands.includes(commandName)){
32
33
  Command.unregister(commandName);
33
34
  }
@@ -35,10 +36,11 @@ import { createEnvironment } from './lib/environment.js';
35
36
  }
36
37
 
37
38
  try {
38
- await runCommand(...args);
39
+ await Workspace.run(async function(){
40
+ await this.runCommand(...args);
41
+ });
39
42
  } catch(e) {
40
43
  console.error(e);
41
44
  }
42
- await resetEnvironment();
43
45
  }
44
46
  })();
@@ -0,0 +1,6 @@
1
+ // jest.config.js
2
+ module.exports = {
3
+ "transform": {
4
+ "^.+\\.[t|j]sx?$": "babel-jest"
5
+ },
6
+ };
package/lib/class.js ADDED
@@ -0,0 +1,64 @@
1
+
2
+ export class Class {
3
+
4
+ static extend(){
5
+ return class extends this {};
6
+ }
7
+
8
+ static include(...includes){
9
+ includes.forEach(include => {
10
+ if(typeof include.meta == 'function') include.meta.call(this);
11
+ this.prototype.assignProps(include, name => name != 'meta');
12
+ });
13
+ return this;
14
+ }
15
+
16
+ static assignProps(...sources){
17
+ return assignProps(this, ...sources);
18
+ }
19
+
20
+ static new(...args){
21
+ return new this(...args);
22
+ }
23
+
24
+ static get parent(){
25
+ return this.__proto__;
26
+ }
27
+
28
+ constructor(...args){
29
+ let out = this.initialize(...args);
30
+ if(typeof out?.then == 'function'){
31
+ return out.then(out => out || this);
32
+ }
33
+ return out || this;
34
+ }
35
+
36
+ initialize(){
37
+
38
+ }
39
+
40
+ assignProps(...sources){
41
+ return assignProps(this, ...sources);
42
+ }
43
+ }
44
+
45
+ const assignProps = (target, ...sources) => {
46
+ const fn = typeof sources[sources.length - 1] == 'function' ? sources.pop() : () => true;
47
+
48
+ sources.forEach(source => {
49
+ Object.getOwnPropertyNames(source).forEach(name => {
50
+ if(!fn(name)){
51
+ return;
52
+ }
53
+ const descriptor = { ...Object.getOwnPropertyDescriptor(source, name) };
54
+ const { get: targetGet, set: targetSet } = (Object.getOwnPropertyDescriptor(target, name) || {});
55
+ const { get = targetGet, set = targetSet } = descriptor;
56
+
57
+ if(get) descriptor.get = get;
58
+ if(set) descriptor.set = set;
59
+
60
+ Object.defineProperty(target, name, descriptor);
61
+ });
62
+ });
63
+ return target;
64
+ };
package/lib/client.js CHANGED
@@ -1,49 +1,21 @@
1
+ import { fileURLToPath } from 'url';
1
2
 
2
- import { promisify } from 'util';
3
- import { readFile } from 'fs';
4
- import { Volume as MemFs } from 'memfs';
5
- import * as fs from 'fs';
6
- import { Union as UnionFs } from 'unionfs';
3
+ import { Class } from "./class.js";
4
+ import { Singleton } from "./singleton.js";
7
5
 
8
- import { Base } from './base.js';
9
- import { overload } from './overload.js';
10
6
 
11
- export const client = Base.extend().include({
12
- initialize(){
13
- this.files = {};
7
+ export const Client = Class.extend().include({
8
+ meta(){
9
+ this.include(Singleton);
14
10
  },
15
11
 
16
- addFile: overload({
17
- ['string, function'](filePath, fn){
18
- this.files[filePath] = fn;
19
- },
12
+ initialize(){
13
+ this.modules = [];
20
14
 
21
- string(filePath){
22
- this.addFile(filePath, async () => {
23
- return (await promisify(readFile)(filePath)).toString();
24
- });
25
- },
26
- }),
15
+ this.addModule(`import ${JSON.stringify(fileURLToPath(`${import.meta.url}/../index.js`))};`);
16
+ },
27
17
 
28
- async createFs(entryFilePath){
29
- const files = {};
30
- const filePaths = Object.keys(this.files);
31
- while(filePaths.length){
32
- const filePath = filePaths.pop();
33
- const data = await this.files[filePath]();
34
- files[filePath] = data.replace(/(.*)\/\/\s*pinstripe-if-client:\s*(.*)/g, '$2 // pinstripe-if-server: $1');
35
- }
36
- return new UnionFs().use(fs).use(new MemFs.fromJSON({
37
- ...files,
38
- [entryFilePath]: `
39
- ${
40
- Object.keys(this.files).filter(filePath => filePath.match(/\/[^\.\/]+(\.client\.js)$/)).map(filePath => `
41
- import ${JSON.stringify(filePath)};
42
- `).join('\n')
43
- }
44
- `
45
- }));
18
+ addModule(...modules){
19
+ this.modules.push(...modules);
46
20
  }
47
- }).new();
48
-
49
- export const addFileToClient = (...args) => client.addFile(...args);
21
+ });
package/lib/command.js CHANGED
@@ -1,25 +1,16 @@
1
1
 
2
- import { Base } from './base.js';
3
- import { Registrable } from './registrable.js';
4
- import { dasherize } from './inflector.js';
5
- import { overload } from './overload.js';
6
- import { thatify } from './thatify.js';
7
- import { addFileToClient } from './client.js';
2
+ import { Class } from './class.js';
3
+ import { Registry } from './registry.js';
4
+ import { ServiceConsumer } from './service_consumer.js';
5
+ import { inflector } from "./inflector.js";
8
6
 
9
- export const Command = Base.extend().include({
7
+ export const Command = Class.extend().include({
10
8
  meta(){
11
- this.include(Registrable);
12
-
13
- const { register } = this;
9
+ this.include(Registry);
10
+ this.include(ServiceConsumer);
14
11
 
15
12
  this.assignProps({
16
- register(name){
17
- return register.call(this, dasherize(name));
18
- },
19
-
20
- run(name = 'list-commands', ...args){
21
- return this.create(name, ...args).run();
22
- },
13
+ normalizeName: (...args) => inflector.dasherize(...args),
23
14
 
24
15
  get schedules(){
25
16
  if(!this.hasOwnProperty('_schedules')){
@@ -31,51 +22,18 @@ export const Command = Base.extend().include({
31
22
  schedule(...args){
32
23
  this.schedules.push(args);
33
24
  return this;
34
- }
25
+ },
26
+
27
+ async run(context, name = 'list-commands', ...args){
28
+ return context.fork().run(async context => {
29
+ context.args = [ ...args ];
30
+ await this.create(name, context).run();
31
+ });
32
+ },
35
33
  });
36
34
  },
37
35
 
38
- initialize(environment){
39
- this.environment = environment;
40
- },
41
-
42
36
  run(){
43
37
  console.error(`No such command "${this.constructor.name}" exists.`);
44
- },
45
-
46
- __getMissing(name){
47
- return this.environment[name];
48
38
  }
49
39
  });
50
-
51
-
52
- export const defineCommand = overload({
53
- ['string, object'](name, include){
54
- const abstract = include.abstract;
55
- delete include.abstract;
56
- Command.register(name, abstract).include(include);
57
- },
58
-
59
- ['string, function'](name, fn){
60
- defineCommand(name, { run: thatify(fn) });
61
- }
62
- });
63
-
64
- export const commandImporter = dirPath => {
65
- return async filePath => {
66
- const relativeFilePath = filePath.substr(dirPath.length).replace(/^\//, '');
67
-
68
- if(filePath.match(/\.js$/)){
69
- const relativeFilePathWithoutExtension = relativeFilePath.replace(/\.[^/]+$/, '');
70
- if(relativeFilePathWithoutExtension == '_importer'){
71
- return;
72
- }
73
- addFileToClient(filePath);
74
- const definition = await ( await import(filePath) ).default;
75
- if(definition !== undefined){
76
- defineCommand(relativeFilePathWithoutExtension, definition);
77
- }
78
- return;
79
- }
80
- };
81
- };
@@ -0,0 +1 @@
1
+ export { Command as default } from 'pinstripe';
@@ -1,2 +1,6 @@
1
1
 
2
- export default ({ database }) => database.drop();
2
+ export default {
3
+ async run(){
4
+ await this.database.drop()
5
+ }
6
+ };
@@ -1,32 +1,39 @@
1
1
 
2
- export default async ({
3
- cliUtils: { extractArg },
4
- fsBuilder: { inProjectRootDir, generateFile, line, indent },
5
- snakeify, dasherize
6
- }) => {
7
- const name = snakeify(extractArg(''));
8
- if(name == ''){
9
- console.error('A command name must be given.');
10
- process.exit();
11
- }
12
-
13
- await inProjectRootDir(async () => {
14
2
 
15
- await generateFile(`lib/commands/_importer.js`, { skipIfExists: true }, () => {
16
- line();
17
- line(`export { commandImporter as default } from 'pinstripe';`);
18
- line();
19
- });
3
+ export default {
4
+ async run(){
5
+ const [ name = '' ] = this.args;
6
+ const normalizedName = this.inflector.snakeify(name);
7
+ if(normalizedName == ''){
8
+ console.error('A command name must be given.');
9
+ process.exit();
10
+ }
20
11
 
21
- await generateFile(`lib/commands/${name}.js`, () => {
22
- line();
23
- line(`export default () => {`);
24
- indent(() => {
25
- line(`console.log('${dasherize(name)} command coming soon!')`);
12
+ const { inProjectRootDir, generateFile, line, indent } = this.fsBuilder;
13
+
14
+ await inProjectRootDir(async () => {
15
+
16
+ await generateFile(`lib/commands/_file_importer.js`, { skipIfExists: true }, () => {
17
+ line();
18
+ line(`export { Command as default } from 'pinstripe';`);
19
+ line();
26
20
  });
27
- line('};');
28
- line();
21
+
22
+ await generateFile(`lib/commands/${normalizedName}.js`, () => {
23
+ line();
24
+ line(`export default {`);
25
+ indent(() => {
26
+ line('run(){');
27
+ indent(() => {
28
+ line(`console.log('${this.inflector.dasherize(normalizedName)} command coming soon!')`);
29
+ });
30
+ line('}');
31
+ });
32
+ line('};');
33
+ line();
34
+ });
35
+
29
36
  });
37
+ }
38
+ }
30
39
 
31
- });
32
- };
@@ -1,45 +1,47 @@
1
1
 
2
- export default async ({
3
- cliUtils: { extractArg, extractFields, extractOptions },
4
- fsBuilder: { inProjectRootDir, generateFile, line, indent },
5
- snakeify
6
- }) => {
7
- const suffix = snakeify(extractArg('migration'));
8
- const fields = extractFields();
9
- const { table } = extractOptions({
10
- table: (() => {
11
- const matches = suffix.match(/_to_(.+)$/);
12
- if(matches){
13
- return matches[1];
14
- }
15
- })()
16
- });
2
+ export default {
3
+ async run(){
4
+ const { extractArg, extractFields, extractOptions } = this.cliUtils;
17
5
 
18
- const unixTime = Math.floor(new Date().getTime() / 1000);
19
- const name = `${unixTime}_${suffix}`;
20
-
21
- await inProjectRootDir(async () => {
22
-
23
- await generateFile(`lib/migrations/_importer.js`, { skipIfExists: true }, () => {
24
- line();
25
- line(`export { migrationImporter as default } from 'pinstripe';`);
26
- line();
6
+ const suffix = this.inflector.snakeify(extractArg('migration'));
7
+ const fields = extractFields();
8
+ const { table } = extractOptions({
9
+ table: (() => {
10
+ const matches = suffix.match(/_to_(.+)$/);
11
+ if(matches){
12
+ return matches[1];
13
+ }
14
+ })()
27
15
  });
28
16
 
29
- await generateFile(`lib/migrations/${name}.js`, () => {
30
- line();
31
- line(`export default async ({ database }) => {`);
32
- indent(() => {
17
+ const unixTime = Math.floor(new Date().getTime() / 1000);
18
+ const name = `${unixTime}_${suffix}`;
19
+
20
+ const { inProjectRootDir, generateFile, line, indent } = this.fsBuilder;
21
+
22
+ await inProjectRootDir(async () => {
23
+
24
+ await generateFile(`lib/migrations/_importer.js`, { skipIfExists: true }, () => {
33
25
  line();
34
- if(table && fields.length){
35
- fields.forEach(({ name, type }) => {
36
- line(`await database.${table}.addColumn('${name}', '${type}');`);
37
- });
26
+ line(`export { migrationImporter as default } from 'pinstripe';`);
27
+ line();
28
+ });
29
+
30
+ await generateFile(`lib/migrations/${name}.js`, () => {
31
+ line();
32
+ line(`export default async ({ database }) => {`);
33
+ indent(() => {
38
34
  line();
39
- }
40
- })
41
- line('};');
42
- line();
35
+ if(table && fields.length){
36
+ fields.forEach(({ name, type }) => {
37
+ line(`await database.${table}.addColumn('${name}', '${type}');`);
38
+ });
39
+ line();
40
+ }
41
+ })
42
+ line('};');
43
+ line();
44
+ });
43
45
  });
44
- });
45
- };
46
+ }
47
+ }
@@ -1,44 +1,43 @@
1
1
 
2
- export default async ({
3
- cliUtils: { extractArg, extractFields },
4
- fsBuilder: { inProjectRootDir, generateFile, line, indent },
5
- snakeify, pluralize, camelize,
6
- database,
7
- runCommand
8
- }) => {
9
- const name = snakeify(extractArg(''));
10
- if(name == ''){
11
- console.error('A model name must be given.');
12
- process.exit();
13
- }
14
-
15
- const fields = extractFields();
16
-
17
- const collectionName = camelize(pluralize(name));
18
- if(!await database[collectionName].exists()){
19
- const denormalizedFields = fields.map(({ mandatory, name, type }) => {
20
- return `${ mandatory ? '^' : '' }${name}:${type}`
21
- });
22
- await runCommand('generate-migration', `create_${name}`, ...denormalizedFields, '--table', collectionName)
23
- }
24
-
25
- await inProjectRootDir(async () => {
26
-
27
- await generateFile(`lib/models/_importer.js`, { skipIfExists: true }, () => {
28
- line();
29
- line(`export { modelImporter as default } from 'pinstripe';`);
30
- line();
31
- });
2
+ export default {
3
+ async run(){
32
4
 
33
- await generateFile(`lib/models/${name}.js`, () => {
34
- line();
35
- line(`export default {`);
36
- indent(() => {
5
+ const { extractArg, extractFields } = this.cliUtils;
6
+ const name = this.inflector.snakeify(extractArg(''));
7
+ if(name == ''){
8
+ console.error('A model name must be given.');
9
+ process.exit();
10
+ }
11
+ const fields = extractFields();
12
+
13
+ const collectionName = this.inflector.camelize(this.inflector.pluralize(name));
14
+ if(!await this.database[collectionName].exists){
15
+ const denormalizedFields = fields.map(({ mandatory, name, type }) => {
16
+ return `${ mandatory ? '^' : '' }${name}:${type}`
17
+ });
18
+ await this.runCommand('generate-migration', `create_${name}`, ...denormalizedFields, '--table', collectionName)
19
+ }
20
+
21
+ const { inProjectRootDir, generateFile, line, indent } = this.fsBuilder;
22
+
23
+ await inProjectRootDir(async () => {
24
+
25
+ await generateFile(`lib/models/_importer.js`, { skipIfExists: true }, () => {
26
+ line();
27
+ line(`export { modelImporter as default } from 'pinstripe';`);
37
28
  line();
38
29
  });
39
- line('};');
40
- line();
30
+
31
+ await generateFile(`lib/models/${name}.js`, () => {
32
+ line();
33
+ line(`export default {`);
34
+ indent(() => {
35
+ line();
36
+ });
37
+ line('};');
38
+ line();
39
+ });
40
+
41
41
  });
42
-
43
- });
44
- };
42
+ }
43
+ }
@@ -1,36 +1,37 @@
1
1
 
2
- export default async ({
3
- cliUtils: { extractArg },
4
- fsBuilder: { inProjectRootDir, generateFile, line, indent },
5
- snakeify
6
- }) => {
7
- const name = snakeify(extractArg(''));
8
- if(name == ''){
9
- console.error('A node wrapper name must be given.');
10
- process.exit();
11
- }
12
-
13
- await inProjectRootDir(async () => {
14
-
15
- await generateFile(`lib/node_wrappers/_importer.js`, { skipIfExists: true }, () => {
16
- line();
17
- line(`export { nodeWrapperImporter as default } from 'pinstripe';`);
18
- line();
19
- });
20
-
21
- await generateFile(`lib/node_wrappers/${name}.client.js`, () => {
22
- line();
23
- line(`export default {`);
24
- indent(() => {
25
- line(`initialize(){`);
26
- indent(() => {
27
- line(`this.constructor.parent.prototype.initialize.call(this, ...args);`);
28
- });
29
- line(`}`);
2
+ export default {
3
+ async run(){
4
+ const [ name = '' ] = this.args;
5
+ const normalizedName = this.inflector.snakeify(name);
6
+ if(normalizedName == ''){
7
+ console.error('A node wrapper name must be given.');
8
+ process.exit();
9
+ }
10
+
11
+ const { inProjectRootDir, generateFile, line, indent } = this.fsBuilder;
12
+
13
+ await inProjectRootDir(async () => {
14
+
15
+ await generateFile(`lib/node_wrappers/_importer.js`, { skipIfExists: true }, () => {
16
+ line();
17
+ line(`export { componentImporter as default } from 'pinstripe';`);
18
+ line();
19
+ });
20
+
21
+ await generateFile(`lib/node_wrappers/${normalizedName}.client.js`, () => {
22
+ line();
23
+ line(`export default {`);
24
+ indent(() => {
25
+ line(`initialize(){`);
26
+ indent(() => {
27
+ line(`this.constructor.parent.prototype.initialize.call(this, ...args);`);
28
+ });
29
+ line(`}`);
30
+ });
31
+ line('};');
32
+ line();
30
33
  });
31
- line('};');
32
- line();
34
+
33
35
  });
34
-
35
- });
36
- };
36
+ }
37
+ }