pinstripe 0.27.0 → 0.29.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 (134) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -3
  3. package/babel.config.cjs +18 -0
  4. package/cli.js +46 -0
  5. package/jest.config.cjs +6 -0
  6. package/lib/app.js +37 -0
  7. package/lib/apps/_file_importer.js +1 -0
  8. package/lib/apps/main.js +6 -0
  9. package/lib/class.js +63 -1
  10. package/lib/client.js +20 -0
  11. package/lib/command.js +43 -0
  12. package/lib/commands/_file_importer.js +1 -0
  13. package/lib/commands/drop_database.js +6 -0
  14. package/lib/commands/generate_app.js +41 -0
  15. package/lib/commands/generate_command.js +39 -0
  16. package/lib/commands/generate_component.js +51 -0
  17. package/lib/commands/generate_migration.js +55 -0
  18. package/lib/commands/generate_model.js +43 -0
  19. package/lib/commands/generate_project.js +142 -0
  20. package/lib/commands/generate_service.js +34 -0
  21. package/lib/commands/generate_static_site.js +94 -0
  22. package/lib/commands/generate_view.js +80 -0
  23. package/lib/commands/init_database.js +9 -0
  24. package/lib/commands/list_apps.js +15 -0
  25. package/lib/commands/list_commands.js +15 -0
  26. package/lib/commands/list_components.js +16 -0
  27. package/lib/commands/list_migrations.js +15 -0
  28. package/lib/commands/list_models.js +15 -0
  29. package/lib/commands/list_services.js +15 -0
  30. package/lib/commands/list_views.js +39 -0
  31. package/lib/commands/migrate_database.js +6 -0
  32. package/lib/commands/reset_database.js +9 -0
  33. package/lib/commands/seed_database.js +6 -0
  34. package/lib/commands/show_config.js +6 -0
  35. package/lib/commands/start_repl.js +6 -0
  36. package/lib/commands/start_server.js +31 -0
  37. package/lib/component.js +83 -9
  38. package/lib/components/helpers.js +18 -5
  39. package/lib/components/pinstripe_anchor.js +4 -4
  40. package/lib/components/pinstripe_document.js +2 -2
  41. package/lib/components/pinstripe_form.js +12 -3
  42. package/lib/components/pinstripe_frame.js +6 -6
  43. package/lib/components/pinstripe_modal.js +3 -1
  44. package/lib/constants.js +26 -1
  45. package/lib/context.js +40 -0
  46. package/lib/database/client.js +257 -0
  47. package/lib/database/column_reference.js +13 -0
  48. package/lib/database/constants.js +87 -0
  49. package/lib/database/index.js +7 -0
  50. package/lib/database/migration.js +32 -0
  51. package/lib/database/migrator.js +28 -0
  52. package/lib/database/row.js +392 -0
  53. package/lib/database/singleton.js +12 -0
  54. package/lib/database/table.js +518 -0
  55. package/lib/database/table_reference.js +33 -0
  56. package/lib/database/union.js +130 -0
  57. package/lib/database.js +139 -0
  58. package/lib/defer.js +35 -0
  59. package/lib/defer.test.js +37 -0
  60. package/lib/escape_html.js +2 -0
  61. package/lib/html.js +72 -0
  62. package/lib/import_all.js +94 -0
  63. package/lib/index.js +12 -2
  64. package/lib/inflector.js +184 -1
  65. package/lib/lru_cache.js +52 -1
  66. package/lib/lru_cache.test.js +45 -0
  67. package/lib/markdown.js +58 -0
  68. package/lib/model.js +110 -0
  69. package/lib/project.js +72 -0
  70. package/lib/registry.js +137 -1
  71. package/lib/service_consumer.js +16 -0
  72. package/lib/service_factory.js +22 -0
  73. package/lib/services/_file_importer.js +1 -0
  74. package/lib/services/app.js +11 -0
  75. package/lib/services/args.js +9 -0
  76. package/lib/services/bot.js +70 -0
  77. package/lib/services/cli_utils.js +77 -0
  78. package/lib/services/client_builder.js +70 -0
  79. package/lib/services/config.js +66 -0
  80. package/lib/services/cookies.js +19 -0
  81. package/lib/services/create_model.js +8 -0
  82. package/lib/services/css_classes_for.js +13 -0
  83. package/lib/services/database.js +14 -0
  84. package/lib/services/defer.js +8 -0
  85. package/lib/services/fetch.js +115 -0
  86. package/lib/services/format_date.js +8 -0
  87. package/lib/services/fs_builder.js +132 -0
  88. package/lib/services/inflector.js +8 -0
  89. package/lib/services/initial_params.js +13 -0
  90. package/lib/services/params.js +13 -0
  91. package/lib/services/parse_html.js +8 -0
  92. package/lib/services/project.js +8 -0
  93. package/lib/services/render_form.js +118 -0
  94. package/lib/services/render_html.js +8 -0
  95. package/lib/services/render_markdown.js +9 -0
  96. package/lib/services/render_view.js +6 -0
  97. package/lib/services/repl.js +54 -0
  98. package/lib/services/run_command.js +8 -0
  99. package/lib/services/run_in_new_workspace.js +11 -0
  100. package/lib/services/send_mail.js +47 -0
  101. package/lib/services/server.js +105 -0
  102. package/lib/services/session.js +19 -0
  103. package/lib/services/trapify.js +8 -0
  104. package/lib/services/view.js +6 -0
  105. package/lib/singleton.js +13 -0
  106. package/lib/string_reader.js +22 -0
  107. package/lib/trapify.js +31 -1
  108. package/lib/unescape_html.js +2 -0
  109. package/lib/unescape_html.test.js +9 -0
  110. package/lib/util.js +12 -0
  111. package/lib/validation_error.js +7 -0
  112. package/lib/view.js +115 -0
  113. package/lib/view_file_importers/js.js +38 -0
  114. package/lib/view_file_importers/md.js +50 -0
  115. package/lib/views/_file_importer.js +1 -0
  116. package/lib/views/shared/_button.js +59 -0
  117. package/lib/views/shared/_content.js +85 -0
  118. package/lib/views/shared/_editable_area.js +37 -0
  119. package/lib/views/shared/_form.js +239 -0
  120. package/lib/views/shared/_navbar.js +138 -0
  121. package/lib/views/shared/_panel.js +65 -0
  122. package/lib/views/shared/_section.js +41 -0
  123. package/lib/views/shared/assets/javascripts/all.js.js +7 -0
  124. package/lib/views/shared/assets/javascripts/all.js.map.js +7 -0
  125. package/lib/views/shared/assets/stylesheets/all.css +4 -0
  126. package/lib/views/shared/assets/stylesheets/global.css +126 -0
  127. package/lib/views/shared/assets/stylesheets/reset.css +74 -0
  128. package/lib/views/shared/assets/stylesheets/vars.css +25 -0
  129. package/lib/views/shared/assets/stylesheets/view.css.js +43 -0
  130. package/lib/virtual_node.js +171 -1
  131. package/lib/virtual_node.test.js +28 -0
  132. package/lib/workspace.js +21 -0
  133. package/package.json +40 -7
  134. package/lib/internal.js +0 -7
package/LICENSE CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2020 Jody Salt
2
+ Copyright (c) 2020-present 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
package/README.md CHANGED
@@ -3,9 +3,7 @@
3
3
 
4
4
  ## What is Pinstripe?
5
5
 
6
- Is front-end framework that surgically updates your app's DOM when a page changes.
7
-
8
- This gives the performance of a SPA using with a fraction of the complexity using well established classical patterns.
6
+ Pinstripe is a slick [content management system (CMS)](https://en.wikipedia.org/wiki/Content_management_system) for Node.js.
9
7
 
10
8
  ## License
11
9
 
@@ -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 ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawn } from 'child_process';
4
+
5
+ import { Project } from './lib/project.js';
6
+ import { Command } from './lib/command.js';
7
+ import { importAll } from './lib/import_all.js';
8
+ import { Workspace } from './lib/workspace.js';
9
+
10
+ (async () => {
11
+ const { entryPath, localPinstripePath, exists } = await Project.instance;
12
+ const { argv, env, execPath } = process;
13
+ const args = argv.slice(2);
14
+
15
+ if (env.IS_LOCAL_PINSTRIPE != 'true' && localPinstripePath) {
16
+ spawn(execPath, [localPinstripePath, ...args], {
17
+ env: { ...env, IS_LOCAL_PINSTRIPE: 'true' },
18
+ stdio: 'inherit'
19
+ });
20
+ } else {
21
+ if(entryPath){
22
+ import(entryPath);
23
+ }
24
+
25
+ await importAll();
26
+
27
+ if(exists){
28
+ Command.unregister('generate-project');
29
+ } else {
30
+ const allowedCommands = ['generate-project', 'list-commands'];
31
+ Command.names.forEach(commandName => {
32
+ if(!allowedCommands.includes(commandName)){
33
+ Command.unregister(commandName);
34
+ }
35
+ });
36
+ }
37
+
38
+ try {
39
+ await Workspace.run(async function(){
40
+ await this.runCommand(...args);
41
+ });
42
+ } catch(e) {
43
+ console.error(e);
44
+ }
45
+ }
46
+ })();
@@ -0,0 +1,6 @@
1
+ // jest.config.js
2
+ module.exports = {
3
+ "transform": {
4
+ "^.+\\.[t|j]sx?$": "babel-jest"
5
+ },
6
+ };
package/lib/app.js ADDED
@@ -0,0 +1,37 @@
1
+
2
+ import { Class } from './class.js';
3
+ import { Registry } from './registry.js';
4
+ import { View } from './view.js';
5
+ import { ServiceConsumer } from './service_consumer.js';
6
+
7
+ export const App = Class.extend().include({
8
+ meta(){
9
+ this.assignProps({ name: 'App' });
10
+
11
+ this.include(Registry);
12
+ this.include(ServiceConsumer);
13
+ },
14
+
15
+ compose(){
16
+ return [];
17
+ },
18
+
19
+ get viewMapper(){
20
+ if(!this._viewMapper){
21
+ this._viewMapper = View.mapperFor(this.compose());
22
+ }
23
+ return this._viewMapper;
24
+ },
25
+
26
+ renderView(...args){
27
+ return this.viewMapper.renderView(this.context, ...args);
28
+ },
29
+
30
+ isView(...args){
31
+ return this.viewMapper.isView(...args);
32
+ },
33
+
34
+ get viewNames(){
35
+ return this.viewMapper.viewNames;
36
+ }
37
+ });
@@ -0,0 +1 @@
1
+ export { App as default } from 'pinstripe';
@@ -0,0 +1,6 @@
1
+
2
+ export default {
3
+ compose(){
4
+ return ['shared', 'main'];
5
+ }
6
+ };
package/lib/class.js CHANGED
@@ -1,2 +1,64 @@
1
1
 
2
- export { Class } from '@blognami/util';
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 ADDED
@@ -0,0 +1,20 @@
1
+ import { fileURLToPath } from 'url';
2
+
3
+ import { Class } from './class.js';
4
+ import { Singleton } from './singleton.js';
5
+
6
+ export const Client = Class.extend().include({
7
+ meta(){
8
+ this.include(Singleton);
9
+ },
10
+
11
+ initialize(){
12
+ this.modules = [];
13
+
14
+ this.addModule(`import ${JSON.stringify(fileURLToPath(`${import.meta.url}/../index.js`))};`);
15
+ },
16
+
17
+ addModule(...modules){
18
+ this.modules.push(...modules);
19
+ }
20
+ });
package/lib/command.js ADDED
@@ -0,0 +1,43 @@
1
+
2
+ import { Class } from './class.js';
3
+ import { inflector } from './inflector.js';
4
+ import { Registry } from './registry.js';
5
+ import { ServiceConsumer } from './service_consumer.js';
6
+
7
+ export const Command = Class.extend().include({
8
+ meta(){
9
+ this.assignProps({ name: 'Command' });
10
+
11
+ this.include(Registry);
12
+ this.include(ServiceConsumer);
13
+
14
+ this.assignProps({
15
+ normalizeName(name){
16
+ return inflector.dasherize(name);
17
+ },
18
+
19
+ get schedules(){
20
+ if(!this.hasOwnProperty('_schedules')){
21
+ this._schedules = [];
22
+ }
23
+ return this._schedules;
24
+ },
25
+
26
+ schedule(...args){
27
+ this.schedules.push(args);
28
+ return this;
29
+ },
30
+
31
+ async run(context, name = 'list-commands', ...args){
32
+ await context.fork().run(async context => {
33
+ context.args = [ ...args ];
34
+ await this.create(name, context).run();
35
+ });
36
+ },
37
+ });
38
+ },
39
+
40
+ run(){
41
+ console.error(`No such command "${this.constructor.name}" exists.`);
42
+ }
43
+ });
@@ -0,0 +1 @@
1
+ export { Command as default } from 'pinstripe';
@@ -0,0 +1,6 @@
1
+
2
+ export default {
3
+ async run(){
4
+ await this.database.drop()
5
+ }
6
+ };
@@ -0,0 +1,41 @@
1
+
2
+
3
+ export default {
4
+ async run(){
5
+ const [ name = '' ] = this.args;
6
+ const normalizedName = this.inflector.snakeify(name);
7
+ if(normalizedName == ''){
8
+ console.error('An app name must be given.');
9
+ process.exit();
10
+ }
11
+
12
+ const { inProjectRootDir, generateFile, line, indent } = this.fsBuilder;
13
+
14
+ await inProjectRootDir(async () => {
15
+
16
+ await generateFile(`lib/apps/_file_importer.js`, { skipIfExists: true }, () => {
17
+ line();
18
+ line(`export { App as default } from 'pinstripe';`);
19
+ line();
20
+ });
21
+
22
+ await generateFile(`lib/apps/${normalizedName}.js`, () => {
23
+ line();
24
+ line(`export default {`);
25
+ indent(() => {
26
+ line('compose(){');
27
+ indent(() => {
28
+ line(`return ['shared', '${this.inflector.dasherize(normalizedName)}'];`);
29
+ });
30
+ line('}');
31
+ });
32
+ line('};');
33
+ line();
34
+ });
35
+
36
+ });
37
+
38
+ await this.runCommand('generate-view', `${normalizedName}/index`);
39
+ }
40
+ }
41
+
@@ -0,0 +1,39 @@
1
+
2
+
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
+ }
11
+
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();
20
+ });
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
+
36
+ });
37
+ }
38
+ }
39
+
@@ -0,0 +1,51 @@
1
+
2
+ export default {
3
+ async run(){
4
+ const { extractArg } = this.cliUtils;
5
+ const name = this.inflector.snakeify(extractArg(''));
6
+ if(name == ''){
7
+ console.error('A component 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/components/_file_importer.js`, { skipIfExists: true }, () => {
16
+ line();
17
+ line(`export { Component as default } from 'pinstripe';`);
18
+ line();
19
+ });
20
+
21
+ await generateFile(`lib/components/${name}.js`, () => {
22
+ line();
23
+ line(`export default {`);
24
+ indent(() => {
25
+ line(`initialize(...args){`);
26
+ indent(() => {
27
+ line(`this.constructor.parent.prototype.initialize.call(this, ...args);`);
28
+ line();
29
+ line('this.shadow.patch(`');
30
+ indent(() => {
31
+ line(`<style>`);
32
+ indent(() => {
33
+ line(`.root {`);
34
+ indent(() => {
35
+ line(`background: yellow;`)
36
+ })
37
+ line(`}`);
38
+ });
39
+ line(`</style>`);
40
+ line(`<div class="root"><slot></div>`);
41
+ });
42
+ line('`);');
43
+ });
44
+ line(`}`);
45
+ });
46
+ line('};');
47
+ line();
48
+ });
49
+ });
50
+ }
51
+ }
@@ -0,0 +1,55 @@
1
+
2
+ export default {
3
+ async run(){
4
+ const { extractArg, extractFields, extractOptions } = this.cliUtils;
5
+
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
+ })()
15
+ });
16
+
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/_file_importer.js`, { skipIfExists: true }, () => {
25
+ line();
26
+ line(`export { Migration as default } from 'pinstripe/database';`);
27
+ line();
28
+ });
29
+
30
+ await generateFile(`lib/migrations/${name}.js`, () => {
31
+ line();
32
+ line(`export default {`);
33
+ indent(() => {
34
+ line(`async migrate(){`);
35
+ indent(() => {
36
+ if(table && fields.length){
37
+ line(`await this.database.table('${table}', async ${table} => {`);
38
+ indent(() => {
39
+ fields.forEach(({ name, type }) => {
40
+ line(`await ${table}.addColumn('${name}', '${type}');`);
41
+ });
42
+ })
43
+ line(`});`);
44
+ } else {
45
+ line();
46
+ }
47
+ })
48
+ line(`}`);
49
+ })
50
+ line('};');
51
+ line();
52
+ });
53
+ });
54
+ }
55
+ }
@@ -0,0 +1,43 @@
1
+
2
+ export default {
3
+ async run(){
4
+
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]){
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/_file_importer.js`, { skipIfExists: true }, () => {
26
+ line();
27
+ line(`export { Row as default } from 'pinstripe/database';`);
28
+ line();
29
+ });
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
+ });
42
+ }
43
+ }
@@ -0,0 +1,142 @@
1
+
2
+ import { spawnSync } from 'child_process';
3
+ import * as crypto from 'crypto';
4
+
5
+ const defaultDependencies = [
6
+ 'blognami'
7
+ ];
8
+
9
+ export default {
10
+ async run(){
11
+
12
+ const { extractArg, extractOptions } = this.cliUtils;
13
+ const name = extractArg('');
14
+ if(name == ''){
15
+ console.error('A project name must be given.');
16
+ process.exit();
17
+ }
18
+ const { with: dependencies, core } = extractOptions({
19
+ with: [],
20
+ core: false
21
+ });
22
+
23
+ if(!core) defaultDependencies.forEach(dependency => {
24
+ if(!dependencies.includes(dependency)) dependencies.unshift(dependency);
25
+ });
26
+ if(!dependencies.includes('pinstripe')) dependencies.unshift('pinstripe');
27
+
28
+
29
+ const { generateDir, generateFile, line, indent, echo } = this.fsBuilder;
30
+
31
+ await generateDir(name, async () => {
32
+
33
+ await generateFile(`package.json`, () => {
34
+ echo(JSON.stringify({
35
+ type: "module",
36
+ name,
37
+ version: "0.0.0",
38
+ license: "MIT",
39
+ exports: {
40
+ ".": "./lib/index.js"
41
+ },
42
+ }, null, 2));
43
+ });
44
+
45
+ await generateFile(`pinstripe.config.js`, () => {
46
+ line();
47
+ line(`const environment = process.env.NODE_ENV || 'development';`);
48
+ line();
49
+ line(`let database;`);
50
+ line(`if(environment == 'production'){`)
51
+ indent(() => {
52
+ line(`database = {`);
53
+ indent(() => {
54
+ line(`adapter: 'mysql',`)
55
+ line(`host: 'localhost',`);
56
+ line(`user: 'root',`);
57
+ line(`password: '',`);
58
+ line(`database: \`${this.inflector.snakeify(name)}_\${environment}\``);
59
+ });
60
+ line(`};`);
61
+ });
62
+ line(`} else {`);
63
+ indent(() => {
64
+ line(`database = {`);
65
+ indent(() => {
66
+ line(`adapter: 'sqlite',`);
67
+ line(`filename: \`\${environment}.db\``)
68
+ });
69
+ line(`};`);
70
+ });
71
+ line(`}`);
72
+ line();
73
+ line(`let mail;`);
74
+ line(`if(environment == 'production'){`)
75
+ indent(() => {
76
+ line(`mail = {`);
77
+ indent(() => {
78
+ line(`adapter: 'smtp',`)
79
+ line(`host: "smtp.example.com",`)
80
+ line(`port: 465,`);
81
+ line(`secure: true, // use TLS`);
82
+ line(`auth: {`);
83
+ indent(() => {
84
+ line(`user: "username",`);
85
+ line(`pass: "password",`);
86
+ });
87
+ line(`}`);
88
+ });
89
+ line(`};`);
90
+ });
91
+ line(`} else {`);
92
+ indent(() => {
93
+ line(`mail = {`);
94
+ indent(() => {
95
+ line(`adapter: 'dummy'`);
96
+ });
97
+ line(`};`);
98
+ });
99
+ line(`}`);
100
+ line();
101
+ line(`export default {`);
102
+ indent(() => {
103
+ line(`database,`);
104
+ line(`mail,`);
105
+ line(`salt: '${crypto.randomUUID()}'`)
106
+ })
107
+ line(`};`);
108
+ });
109
+
110
+ await generateFile(`lib/index.js`, () => {
111
+ line();
112
+ dependencies.forEach((dependency) => {
113
+ if(dependency != 'pinstripe') line(`import '${dependency}';`);
114
+ });
115
+ line();
116
+ line(`import { importAll } from 'pinstripe';`);
117
+ line();
118
+ line(`importAll(import.meta.url);`);
119
+ line();
120
+ });
121
+
122
+ await generateFile(`README.md`, () => {
123
+ line();
124
+ line(`# ${name}`);
125
+ line();
126
+ line('## Getting started');
127
+ line();
128
+ line('```bash');
129
+ indent(() => {
130
+ line('pinstripe init-database');
131
+ line('pinstripe start-server');
132
+ });
133
+ line('```');
134
+ line();
135
+ });
136
+
137
+ spawnSync('yarn', [ 'add', ...dependencies ], {
138
+ stdio: 'inherit'
139
+ });
140
+ });
141
+ }
142
+ };