pinstripe 0.14.0 → 0.16.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 (218) hide show
  1. package/babel.config.cjs +18 -0
  2. package/cli.js +11 -9
  3. package/jest.config.cjs +6 -0
  4. package/lib/class.js +64 -0
  5. package/lib/client.js +13 -41
  6. package/lib/command.js +25 -55
  7. package/lib/commands/_file_importer.js +1 -0
  8. package/lib/commands/drop_database.js +5 -1
  9. package/lib/commands/generate_command.js +33 -26
  10. package/lib/commands/generate_migration.js +40 -38
  11. package/lib/commands/generate_model.js +38 -39
  12. package/lib/commands/generate_node_wrapper.js +34 -33
  13. package/lib/commands/generate_project.js +58 -58
  14. package/lib/commands/generate_service.js +28 -28
  15. package/lib/commands/generate_static_site.js +9 -13
  16. package/lib/commands/generate_view.js +40 -30
  17. package/lib/commands/init_database.js +8 -5
  18. package/lib/commands/list_commands.js +11 -8
  19. package/lib/commands/list_components.js +16 -0
  20. package/lib/commands/list_migrations.js +11 -8
  21. package/lib/commands/list_models.js +11 -8
  22. package/lib/commands/list_services.js +11 -9
  23. package/lib/commands/list_views.js +12 -8
  24. package/lib/commands/migrate_database.js +5 -1
  25. package/lib/commands/purge_old_sessions.js +12 -0
  26. package/lib/commands/reset_database.js +7 -3
  27. package/lib/commands/seed_database.js +4 -2
  28. package/lib/commands/start_repl.js +6 -0
  29. package/lib/commands/start_server.js +6 -73
  30. package/lib/{node_wrapper.js → component.js} +160 -154
  31. package/lib/components/_file_importer.js +1 -0
  32. package/lib/{node_wrappers → components}/helpers.js +12 -9
  33. package/lib/{node_wrappers/anchor.client.js → components/pinstripe_anchor.js} +2 -2
  34. package/lib/components/pinstripe_body.js +33 -0
  35. package/lib/components/pinstripe_document.js +49 -0
  36. package/lib/{node_wrappers/form.client.js → components/pinstripe_form.js} +4 -6
  37. package/lib/components/pinstripe_frame.js +47 -0
  38. package/lib/components/pinstripe_markdown_editor.js +74 -0
  39. package/lib/components/pinstripe_overlay.js +58 -0
  40. package/lib/components/pinstripe_progress_bar.js +76 -0
  41. package/lib/constants.js +1 -0
  42. package/lib/context.js +40 -0
  43. package/lib/database/client.js +199 -0
  44. package/lib/database/column_reference.js +13 -0
  45. package/lib/database/constants.js +64 -18
  46. package/lib/database/index.js +7 -0
  47. package/lib/database/migration.js +10 -54
  48. package/lib/database/migrator.js +18 -31
  49. package/lib/database/row.js +278 -180
  50. package/lib/database/singleton.js +12 -0
  51. package/lib/database/table.js +425 -255
  52. package/lib/database/table_reference.js +33 -0
  53. package/lib/database/union.js +87 -107
  54. package/lib/database.js +104 -65
  55. package/lib/defer.js +35 -0
  56. package/lib/{async_path_builder.test.js → defer.test.js} +9 -10
  57. package/lib/event_wrapper.js +13 -18
  58. package/lib/extensions/_file_importer.js +2 -0
  59. package/lib/extensions/multi-app/index.js +4 -0
  60. package/lib/extensions/multi-app/views/_file_importer.js +2 -0
  61. package/lib/extensions/multi-app/views/apps/default.js +6 -0
  62. package/lib/extensions/multi-app/views/apps/guard.js +7 -0
  63. package/lib/extensions/multi-app/views/guard.js +21 -0
  64. package/lib/extensions/multi-tenant/database/row.js +27 -0
  65. package/lib/extensions/multi-tenant/database/table.js +30 -0
  66. package/lib/extensions/multi-tenant/database.js +29 -0
  67. package/lib/extensions/multi-tenant/index.js +4 -0
  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 -29
  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 -5
  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 +69 -0
  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 +81 -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 -1
  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 +16 -6
  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/{stylesheets → assets/stylesheets}/global.css +0 -0
  138. package/lib/views/{stylesheets → assets/stylesheets}/reset.css +0 -0
  139. package/lib/views/{stylesheets → 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 +13 -12
  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 +19 -10
  147. package/LICENSE +0 -20
  148. package/README.md +0 -10
  149. package/lib/async_path_builder.js +0 -56
  150. package/lib/base.js +0 -140
  151. package/lib/base.test.js +0 -98
  152. package/lib/commands/_importer.js +0 -2
  153. package/lib/commands/create_database.js +0 -2
  154. package/lib/commands/list_node_wrappers.js +0 -12
  155. package/lib/commands/start_console.js +0 -49
  156. package/lib/css.js +0 -101
  157. package/lib/database/adapter.js +0 -23
  158. package/lib/database/adapters/mysql.js +0 -642
  159. package/lib/database/adapters/sqlite.js +0 -618
  160. package/lib/database/column.js +0 -52
  161. package/lib/database/sql.js +0 -77
  162. package/lib/database/sql.test.js +0 -58
  163. package/lib/environment.js +0 -38
  164. package/lib/get_all_props.js +0 -12
  165. package/lib/hookable.js +0 -39
  166. package/lib/initialize.client.js +0 -11
  167. package/lib/migrations/_importer.js +0 -2
  168. package/lib/models/_importer.js +0 -2
  169. package/lib/node_wrappers/_importer.js +0 -2
  170. package/lib/node_wrappers/document.client.js +0 -42
  171. package/lib/node_wrappers/frame.client.js +0 -105
  172. package/lib/node_wrappers/markdown_editor/line_inserter.client.js +0 -14
  173. package/lib/node_wrappers/markdown_editor.client.js +0 -41
  174. package/lib/node_wrappers/overlay.client.js +0 -39
  175. package/lib/node_wrappers/progress_bar.client.js +0 -43
  176. package/lib/overload.js +0 -68
  177. package/lib/overload.test.js +0 -153
  178. package/lib/registrable.js +0 -85
  179. package/lib/services/_importer.js +0 -2
  180. package/lib/services/command_names.js +0 -6
  181. package/lib/services/fork_environment.js +0 -16
  182. package/lib/services/global.js +0 -9
  183. package/lib/services/migration_names.js +0 -6
  184. package/lib/services/model_names.js +0 -6
  185. package/lib/services/node_wrapper_names.js +0 -6
  186. package/lib/services/read_file.js +0 -6
  187. package/lib/services/render_css.js +0 -6
  188. package/lib/services/render_file.js +0 -9
  189. package/lib/services/render_frame.js +0 -11
  190. package/lib/services/render_list.js +0 -58
  191. package/lib/services/render_table.js +0 -67
  192. package/lib/services/reset_environment.js +0 -19
  193. package/lib/services/service_names.js +0 -6
  194. package/lib/services/stylesheet_view_names.js +0 -10
  195. package/lib/services/theme_config.js +0 -76
  196. package/lib/services/view.js +0 -4
  197. package/lib/thatify.js +0 -6
  198. package/lib/url.js +0 -97
  199. package/lib/url.test.js +0 -25
  200. package/lib/views/_importer.js +0 -2
  201. package/lib/views/_layout.js +0 -53
  202. package/lib/views/blocks/default.js +0 -25
  203. package/lib/views/blocks/help.js +0 -139
  204. package/lib/views/bundle.js.js +0 -36
  205. package/lib/views/sign_in.js +0 -39
  206. package/lib/views/stylesheets/components/button.css.js +0 -56
  207. package/lib/views/stylesheets/components/card.css.js +0 -41
  208. package/lib/views/stylesheets/components/form.css.js +0 -11
  209. package/lib/views/stylesheets/components/frame.css.js +0 -10
  210. package/lib/views/stylesheets/components/input.css.js +0 -54
  211. package/lib/views/stylesheets/components/label.css.js +0 -14
  212. package/lib/views/stylesheets/components/markdown_editor.css.js +0 -53
  213. package/lib/views/stylesheets/components/modal.css.js +0 -77
  214. package/lib/views/stylesheets/components/overlay.css.js +0 -17
  215. package/lib/views/stylesheets/components/pagination.css.js +0 -80
  216. package/lib/views/stylesheets/components/progress_bar.css.js +0 -32
  217. package/lib/views/stylesheets/components/textarea.css.js +0 -17
  218. package/pinstripe_development.db +0 -0
@@ -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
@@ -1,13 +1,14 @@
1
- #!/usr/bin/env node --unhandled-rejections=strict
1
+ #!/usr/bin/env node
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,69 +1,39 @@
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));
13
+ normalizeName: (...args) => inflector.dasherize(...args),
14
+
15
+ get schedules(){
16
+ if(!this.hasOwnProperty('_schedules')){
17
+ this._schedules = [];
18
+ }
19
+ return this._schedules;
20
+ },
21
+
22
+ schedule(...args){
23
+ this.schedules.push(args);
24
+ return this;
18
25
  },
19
26
 
20
- run(name = 'list-commands', ...args){
21
- return this.create(name, ...args).run();
22
- }
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
+ },
23
33
  });
24
34
  },
25
35
 
26
- initialize(environment){
27
- this.environment = environment;
28
- },
29
-
30
36
  run(){
31
37
  console.error(`No such command "${this.constructor.name}" exists.`);
32
- },
33
-
34
- __getMissing(name){
35
- return this.environment[name];
36
38
  }
37
39
  });
38
-
39
-
40
- export const defineCommand = overload({
41
- ['string, object'](name, include){
42
- const abstract = include.abstract;
43
- delete include.abstract;
44
- Command.register(name, abstract).include(include);
45
- },
46
-
47
- ['string, function'](name, fn){
48
- defineCommand(name, { run: thatify(fn) });
49
- }
50
- });
51
-
52
- export const commandImporter = dirPath => {
53
- return async filePath => {
54
- const relativeFilePath = filePath.substr(dirPath.length).replace(/^\//, '');
55
-
56
- if(filePath.match(/\.js$/)){
57
- const relativeFilePathWithoutExtension = relativeFilePath.replace(/\.[^/]+$/, '');
58
- if(relativeFilePathWithoutExtension == '_importer'){
59
- return;
60
- }
61
- addFileToClient(filePath);
62
- const definition = await ( await import(filePath) ).default;
63
- if(definition !== undefined){
64
- defineCommand(relativeFilePathWithoutExtension, definition);
65
- }
66
- return;
67
- }
68
- };
69
- };
@@ -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
+ }