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.
- package/babel.config.cjs +18 -0
- package/cli.js +11 -9
- package/jest.config.cjs +6 -0
- package/lib/class.js +64 -0
- package/lib/client.js +13 -41
- package/lib/command.js +25 -55
- package/lib/commands/_file_importer.js +1 -0
- package/lib/commands/drop_database.js +5 -1
- package/lib/commands/generate_command.js +33 -26
- package/lib/commands/generate_migration.js +40 -38
- package/lib/commands/generate_model.js +38 -39
- package/lib/commands/generate_node_wrapper.js +34 -33
- package/lib/commands/generate_project.js +58 -58
- package/lib/commands/generate_service.js +28 -28
- package/lib/commands/generate_static_site.js +9 -13
- package/lib/commands/generate_view.js +40 -30
- package/lib/commands/init_database.js +8 -5
- package/lib/commands/list_commands.js +11 -8
- package/lib/commands/list_components.js +16 -0
- package/lib/commands/list_migrations.js +11 -8
- package/lib/commands/list_models.js +11 -8
- package/lib/commands/list_services.js +11 -9
- package/lib/commands/list_views.js +12 -8
- package/lib/commands/migrate_database.js +5 -1
- package/lib/commands/purge_old_sessions.js +12 -0
- package/lib/commands/reset_database.js +7 -3
- package/lib/commands/seed_database.js +4 -2
- package/lib/commands/start_repl.js +6 -0
- package/lib/commands/start_server.js +6 -73
- package/lib/{node_wrapper.js → component.js} +160 -154
- package/lib/components/_file_importer.js +1 -0
- package/lib/{node_wrappers → components}/helpers.js +12 -9
- package/lib/{node_wrappers/anchor.client.js → components/pinstripe_anchor.js} +2 -2
- package/lib/components/pinstripe_body.js +33 -0
- package/lib/components/pinstripe_document.js +49 -0
- package/lib/{node_wrappers/form.client.js → components/pinstripe_form.js} +4 -6
- package/lib/components/pinstripe_frame.js +47 -0
- package/lib/components/pinstripe_markdown_editor.js +74 -0
- package/lib/components/pinstripe_overlay.js +58 -0
- package/lib/components/pinstripe_progress_bar.js +76 -0
- package/lib/constants.js +1 -0
- package/lib/context.js +40 -0
- package/lib/database/client.js +199 -0
- package/lib/database/column_reference.js +13 -0
- package/lib/database/constants.js +64 -18
- package/lib/database/index.js +7 -0
- package/lib/database/migration.js +10 -54
- package/lib/database/migrator.js +18 -31
- package/lib/database/row.js +278 -180
- package/lib/database/singleton.js +12 -0
- package/lib/database/table.js +425 -255
- package/lib/database/table_reference.js +33 -0
- package/lib/database/union.js +87 -107
- package/lib/database.js +104 -65
- package/lib/defer.js +35 -0
- package/lib/{async_path_builder.test.js → defer.test.js} +9 -10
- package/lib/event_wrapper.js +13 -18
- package/lib/extensions/_file_importer.js +2 -0
- package/lib/extensions/multi-app/index.js +4 -0
- package/lib/extensions/multi-app/views/_file_importer.js +2 -0
- package/lib/extensions/multi-app/views/apps/default.js +6 -0
- package/lib/extensions/multi-app/views/apps/guard.js +7 -0
- package/lib/extensions/multi-app/views/guard.js +21 -0
- package/lib/extensions/multi-tenant/database/row.js +27 -0
- package/lib/extensions/multi-tenant/database/table.js +30 -0
- package/lib/extensions/multi-tenant/database.js +29 -0
- package/lib/extensions/multi-tenant/index.js +4 -0
- package/lib/extensions/multi-tenant/services/_file_importer.js +2 -0
- package/lib/extensions/multi-tenant/services/database.js +17 -0
- package/lib/extensions/multi-tenant/services/migrations/1627976174_create_tenant_table_and_add_tenant_id_to_existing_tables.js +20 -0
- package/lib/extensions/multi-tenant/services/migrations/_file_importer.js +2 -0
- package/lib/html.js +23 -22
- package/lib/import_all.js +26 -29
- package/lib/index.js +14 -20
- package/lib/inflector.js +165 -172
- package/lib/initialize.js +11 -0
- package/lib/migrations/1627976184_create_user.js +11 -7
- package/lib/migrations/1628057822_create_session.js +8 -5
- package/lib/migrations/_file_importer.js +1 -0
- package/lib/{validatable.js → model.js} +51 -7
- package/lib/models/_file_importer.js +1 -0
- package/lib/models/user.js +36 -28
- package/lib/project.js +7 -4
- package/lib/registry.js +133 -0
- package/lib/service_consumer.js +16 -0
- package/lib/service_factory.js +8 -87
- package/lib/services/_file_importer.js +1 -0
- package/lib/services/args.js +8 -1
- package/lib/services/bot.js +69 -0
- package/lib/services/cli_utils.js +69 -63
- package/lib/services/client_builder.js +68 -0
- package/lib/services/config.js +34 -15
- package/lib/services/cookies.js +13 -14
- package/lib/services/create_model.js +8 -0
- package/lib/services/database.js +8 -6
- package/lib/services/defer.js +8 -0
- package/lib/services/fetch.js +81 -75
- package/lib/services/format_date.js +4 -2
- package/lib/services/fs_builder.js +120 -118
- package/lib/services/inflector.js +8 -0
- package/lib/services/initial_params.js +13 -0
- package/lib/services/params.js +12 -1
- package/lib/services/parse_html.js +8 -0
- package/lib/services/project.js +6 -2
- package/lib/services/render_form.js +42 -105
- package/lib/services/render_html.js +5 -3
- package/lib/services/render_markdown.js +31 -31
- package/lib/services/render_view.js +4 -14
- package/lib/services/repl.js +54 -0
- package/lib/services/run_command.js +4 -5
- package/lib/services/send_mail.js +30 -26
- package/lib/services/server.js +92 -0
- package/lib/services/session.js +16 -6
- package/lib/services/view_names.js +4 -2
- package/lib/singleton.js +13 -0
- package/lib/string_reader.js +6 -8
- package/lib/trapify.js +32 -0
- package/lib/unescape_html.test.js +3 -0
- package/lib/view.js +33 -115
- package/lib/view_file_importers/ejs.js +82 -0
- package/lib/view_file_importers/md.js +42 -0
- package/lib/views/_file_importer.js +1 -0
- package/lib/views/assets/javascripts/all.js.js +7 -0
- package/lib/views/assets/javascripts/all.js.map.js +7 -0
- package/lib/views/assets/stylesheets/all.css.js +28 -0
- package/lib/views/assets/stylesheets/components/button.css +43 -0
- package/lib/views/assets/stylesheets/components/card.css +29 -0
- package/lib/views/assets/stylesheets/components/form.css +4 -0
- package/lib/views/assets/stylesheets/components/frame.css +3 -0
- package/lib/views/assets/stylesheets/components/input.css +40 -0
- package/lib/views/assets/stylesheets/components/label.css +9 -0
- package/lib/views/assets/stylesheets/components/modal.css +62 -0
- package/lib/views/assets/stylesheets/components/overlay.css +11 -0
- package/lib/views/assets/stylesheets/components/pagination.css +60 -0
- package/lib/views/assets/stylesheets/components/progress_bar.css +20 -0
- package/lib/views/assets/stylesheets/components/textarea.css +10 -0
- package/lib/views/{stylesheets → assets/stylesheets}/global.css +0 -0
- package/lib/views/{stylesheets → assets/stylesheets}/reset.css +0 -0
- package/lib/views/{stylesheets → assets/stylesheets}/vars.css +0 -0
- package/lib/views/sign_in/index.js +32 -0
- package/lib/views/sign_in/verify_password.js +52 -0
- package/lib/views/sign_out.js +13 -12
- package/lib/virtual_node.js +30 -33
- package/lib/virtual_node.test.js +4 -0
- package/lib/workspace.js +21 -0
- package/package.json +19 -10
- package/LICENSE +0 -20
- package/README.md +0 -10
- package/lib/async_path_builder.js +0 -56
- package/lib/base.js +0 -140
- package/lib/base.test.js +0 -98
- package/lib/commands/_importer.js +0 -2
- package/lib/commands/create_database.js +0 -2
- package/lib/commands/list_node_wrappers.js +0 -12
- package/lib/commands/start_console.js +0 -49
- package/lib/css.js +0 -101
- package/lib/database/adapter.js +0 -23
- package/lib/database/adapters/mysql.js +0 -642
- package/lib/database/adapters/sqlite.js +0 -618
- package/lib/database/column.js +0 -52
- package/lib/database/sql.js +0 -77
- package/lib/database/sql.test.js +0 -58
- package/lib/environment.js +0 -38
- package/lib/get_all_props.js +0 -12
- package/lib/hookable.js +0 -39
- package/lib/initialize.client.js +0 -11
- package/lib/migrations/_importer.js +0 -2
- package/lib/models/_importer.js +0 -2
- package/lib/node_wrappers/_importer.js +0 -2
- package/lib/node_wrappers/document.client.js +0 -42
- package/lib/node_wrappers/frame.client.js +0 -105
- package/lib/node_wrappers/markdown_editor/line_inserter.client.js +0 -14
- package/lib/node_wrappers/markdown_editor.client.js +0 -41
- package/lib/node_wrappers/overlay.client.js +0 -39
- package/lib/node_wrappers/progress_bar.client.js +0 -43
- package/lib/overload.js +0 -68
- package/lib/overload.test.js +0 -153
- package/lib/registrable.js +0 -85
- package/lib/services/_importer.js +0 -2
- package/lib/services/command_names.js +0 -6
- package/lib/services/fork_environment.js +0 -16
- package/lib/services/global.js +0 -9
- package/lib/services/migration_names.js +0 -6
- package/lib/services/model_names.js +0 -6
- package/lib/services/node_wrapper_names.js +0 -6
- package/lib/services/read_file.js +0 -6
- package/lib/services/render_css.js +0 -6
- package/lib/services/render_file.js +0 -9
- package/lib/services/render_frame.js +0 -11
- package/lib/services/render_list.js +0 -58
- package/lib/services/render_table.js +0 -67
- package/lib/services/reset_environment.js +0 -19
- package/lib/services/service_names.js +0 -6
- package/lib/services/stylesheet_view_names.js +0 -10
- package/lib/services/theme_config.js +0 -76
- package/lib/services/view.js +0 -4
- package/lib/thatify.js +0 -6
- package/lib/url.js +0 -97
- package/lib/url.test.js +0 -25
- package/lib/views/_importer.js +0 -2
- package/lib/views/_layout.js +0 -53
- package/lib/views/blocks/default.js +0 -25
- package/lib/views/blocks/help.js +0 -139
- package/lib/views/bundle.js.js +0 -36
- package/lib/views/sign_in.js +0 -39
- package/lib/views/stylesheets/components/button.css.js +0 -56
- package/lib/views/stylesheets/components/card.css.js +0 -41
- package/lib/views/stylesheets/components/form.css.js +0 -11
- package/lib/views/stylesheets/components/frame.css.js +0 -10
- package/lib/views/stylesheets/components/input.css.js +0 -54
- package/lib/views/stylesheets/components/label.css.js +0 -14
- package/lib/views/stylesheets/components/markdown_editor.css.js +0 -53
- package/lib/views/stylesheets/components/modal.css.js +0 -77
- package/lib/views/stylesheets/components/overlay.css.js +0 -17
- package/lib/views/stylesheets/components/pagination.css.js +0 -80
- package/lib/views/stylesheets/components/progress_bar.css.js +0 -32
- package/lib/views/stylesheets/components/textarea.css.js +0 -17
- package/pinstripe_development.db +0 -0
package/babel.config.cjs
ADDED
package/cli.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { spawn } from 'child_process';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Project } from './lib/project.js';
|
|
6
6
|
import { Command } from './lib/command.js';
|
|
7
|
-
import {
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
})();
|
package/jest.config.cjs
ADDED
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 {
|
|
3
|
-
import {
|
|
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
|
|
12
|
-
|
|
13
|
-
this.
|
|
7
|
+
export const Client = Class.extend().include({
|
|
8
|
+
meta(){
|
|
9
|
+
this.include(Singleton);
|
|
14
10
|
},
|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
[
|
|
18
|
-
this.files[filePath] = fn;
|
|
19
|
-
},
|
|
12
|
+
initialize(){
|
|
13
|
+
this.modules = [];
|
|
20
14
|
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
29
|
-
|
|
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
|
-
})
|
|
48
|
-
|
|
49
|
-
export const addFileToClient = (...args) => client.addFile(...args);
|
|
21
|
+
});
|
package/lib/command.js
CHANGED
|
@@ -1,69 +1,39 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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 =
|
|
7
|
+
export const Command = Class.extend().include({
|
|
10
8
|
meta(){
|
|
11
|
-
this.include(
|
|
12
|
-
|
|
13
|
-
const { register } = this;
|
|
9
|
+
this.include(Registry);
|
|
10
|
+
this.include(ServiceConsumer);
|
|
14
11
|
|
|
15
12
|
this.assignProps({
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
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,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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
28
|
-
|
|
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
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
42
|
-
|
|
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
|
|
3
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
40
|
-
|
|
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
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
32
|
-
line();
|
|
34
|
+
|
|
33
35
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
36
|
+
}
|
|
37
|
+
}
|