create-directus-docker 1.3.3 → 1.3.5

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-directus-docker",
3
3
  "description": "An installer for Dockerized Directus + MySQL + Adminer + GraphiQL with a helper Node app",
4
- "version": "1.3.3",
4
+ "version": "1.3.5",
5
5
  "type": "module",
6
6
  "author": {
7
7
  "name": "Dave Kobrenski",
package/src/cli.js CHANGED
@@ -5,9 +5,9 @@ import chalk from 'chalk';
5
5
  import path from 'path';
6
6
  import {fileURLToPath} from 'url';
7
7
  import { create } from 'create-create-app';
8
- import { spawn } from 'node:child_process';
9
- import logUpdate from 'log-update';
10
- import {execa} from 'execa';
8
+ // import { spawn } from 'node:child_process';
9
+ // import logUpdate from 'log-update';
10
+ // import {execa} from 'execa';
11
11
 
12
12
  const __filename = fileURLToPath(import.meta.url);
13
13
  const __dirname = path.dirname(__filename);
@@ -20,24 +20,22 @@ create('create-directus-docker', {
20
20
  promptForLicense: false,
21
21
 
22
22
  // after: ({packageDir}) => {
23
-
23
+ // const cd = spawn('cd', [packageDir]);
24
+ // cd.on('close', code => {
25
+ // const install = spawn('npm', ['install']);
26
+
27
+ // install.stdout.on('data', (data) => {
28
+ // logUpdate(`${data}`);
29
+ // });
30
+
31
+ // install.on('close', (code) => {
32
+ // logUpdate.done();
33
+ // execa('npm', ['start']).stdout.pipe(process.stdout);
34
+ // });
35
+ // });
24
36
  // },
25
37
 
26
38
  caveat: ({ packageDir }) => {
27
- const cd = spawn('cd', [packageDir]);
28
- cd.on('close', code => {
29
- const install = spawn('npm', ['install']);
30
-
31
- install.stdout.on('data', (data) => {
32
- logUpdate(`${data}`);
33
- });
34
-
35
- install.on('close', (code) => {
36
- logUpdate.done();
37
- execa('npm', ['start']).stdout.pipe(process.stdout);
38
- });
39
- });
40
-
41
39
  return `
42
40
  ${chalk.bold.yellowBright("Directus with MySQL, Adminer, and GraphiQL:")}
43
41
 
@@ -7,7 +7,7 @@ services:
7
7
  image: mysql:8
8
8
  restart: always
9
9
  healthcheck:
10
- test: ['mysqladmin', 'ping', '--silent']
10
+ test: ['CMD', 'mysqladmin', 'ping', '--silent']
11
11
  interval: 5s
12
12
  timeout: 20s
13
13
  retries: 3
@@ -47,8 +47,9 @@ services:
47
47
  directus:
48
48
  container_name: directus
49
49
  image: directus/directus:latest
50
+ restart: always
50
51
  ports:
51
- - 8055:8055
52
+ - ${DIRECTUS_PORT}:8055
52
53
  volumes:
53
54
  - ./directus/uploads:/directus/uploads
54
55
  networks:
@@ -72,7 +73,7 @@ services:
72
73
  ADMIN_EMAIL: ${ADMIN_EMAIL}
73
74
  ADMIN_PASSWORD: ${ADMIN_PASSWORD}
74
75
  CORS_ENABLED: 'true'
75
- CORS_ORIGIN: '*'
76
+ CORS_ORIGIN: 'true'
76
77
 
77
78
  PUBLIC_URL: ${PUBLIC_URL}
78
79
 
@@ -103,6 +103,16 @@ try {
103
103
  name: 'MYSQL_ROOT_PASS',
104
104
  message: "Root password:",
105
105
  default: generator.generate({ length: 14, numbers: true, symbols: false })
106
+ },
107
+ {
108
+ name: 'DIRECTUS_DOMAIN',
109
+ message: "Web address to run on. For example, 'https://mydomain.com' Leave as localhost if running in dev environment.",
110
+ default: 'localhost'
111
+ },
112
+ {
113
+ name: 'DIRECTUS_PORT',
114
+ message: "Port to access Directus on:",
115
+ default: '8055'
106
116
  }
107
117
  ]).then(answers => {
108
118
  console.log(chalk.magentaBright("\nWriting to environment file. Be sure to take note of your credentials below, you'll need them shortly!\n"));
@@ -136,12 +146,29 @@ try {
136
146
  writeStream.write("# Set the domain for directus to use:\n");
137
147
  writeStream.write("# eg, https://mydomain.com\n");
138
148
  writeStream.write("# in local dev environments, just leave it set to localhost:port\n");
139
- writeStream.write("PUBLIC_URL=\"http://localhost:8055\"\n");
140
- writeStream.write("API_ENDPOINT=\"http://localhost:8055/graphql\"");
149
+ writeStream.write(`DIRECTUS_DOMAIN="${answers.DIRECTUS_DOMAIN}"\n`);
150
+ writeStream.write(`DIRECTUS_PORT="${answers.DIRECTUS_PORT}"\n`);
151
+
152
+ if(answers.DIRECTUS_DOMAIN === "localhost") {
153
+ if(answers.DIRECTUS_PORT === 80) {
154
+ writeStream.write(`PUBLIC_URL="http://localhost"\n`);
155
+ writeStream.write(`API_ENDPOINT="http://localhost/graphql"`);
156
+ } else {
157
+ writeStream.write(`PUBLIC_URL="http://localhost:${answers.DIRECTUS_PORT}"\n`);
158
+ writeStream.write(`API_ENDPOINT="http://localhost:${answers.DIRECTUS_PORT}/graphql"`);
159
+ }
160
+ } else {
161
+ if(answers.DIRECTUS_PORT === 80) {
162
+ writeStream.write(`PUBLIC_URL="${answers.DIRECTUS_DOMAIN}"\n`);
163
+ writeStream.write(`API_ENDPOINT="${answers.DIRECTUS_DOMAIN}/graphql"`);
164
+ } else {
165
+ writeStream.write(`PUBLIC_URL="${answers.DIRECTUS_DOMAIN}:${answers.DIRECTUS_PORT}"\n`);
166
+ writeStream.write(`API_ENDPOINT="${answers.DIRECTUS_DOMAIN}:${answers.DIRECTUS_PORT}/graphql"`);
167
+ }
168
+ }
141
169
 
142
170
  writeStream.end();
143
171
 
144
- //console.log(chalk.greenBright("\nAll set!"));
145
172
  console.log("\nYou can always edit the variables that we've just set in the .env file manually.\n");
146
173
 
147
174
  inquirer.prompt([
@@ -5,9 +5,11 @@ import { spawn } from 'node:child_process';
5
5
  import logUpdate from 'log-update';
6
6
  import open from 'open';
7
7
  import inquirer from 'inquirer';
8
+ import * as dotenv from 'dotenv';
9
+ dotenv.config();
8
10
 
9
11
  export default function launchServices() {
10
- const launch = spawn('docker', ['compose', 'up', 'mysql', '-d']);
12
+ const launch = spawn('docker-compose', ['up', '-d', 'mysql']);
11
13
 
12
14
  const opts = {
13
15
  resources: [
@@ -42,7 +44,7 @@ export default function launchServices() {
42
44
  logUpdate("Building and launching containers:\n");
43
45
  logUpdate.done();
44
46
 
45
- const launch2 = spawn('docker', ['compose', 'up', '-d']);
47
+ const launch2 = spawn('docker-compose', ['up', '-d']);
46
48
 
47
49
  launch2.stderr.on('data', (data) => {
48
50
  logUpdate(`${data}`);
@@ -52,9 +54,15 @@ export default function launchServices() {
52
54
  logUpdate('Done.');
53
55
  logUpdate.done();
54
56
 
57
+ if(process.env.DIRECTUS_DOMAIN === 'localhost') {
58
+ var appURL = 'http://localhost';
59
+ } else {
60
+ var appURL = process.env.DIRECTUS_DOMAIN;
61
+ }
62
+
55
63
  const pingOpts = {
56
64
  resources: [
57
- 'http://localhost:8055'
65
+ `${process.env.PUBLIC_URL}`
58
66
  ],
59
67
  delay: 1000,
60
68
  interval: 300,
@@ -70,10 +78,9 @@ export default function launchServices() {
70
78
  logUpdate.done();
71
79
 
72
80
  console.log(chalk.green("\nAll services should be ready. You can access them at the following URLs:\n"));
73
-
74
- console.log(`Directus CMS: ${chalk.cyan("http://localhost:8055")}`);
75
- console.log(`Adminer: ${chalk.cyan("http://localhost:8080")}`);
76
- console.log(`GraphiQL Playground: ${chalk.cyan("http://localhost:4000/graphql")}`);
81
+ console.log(`Directus CMS: ${chalk.cyan(process.env.PUBLIC_URL)}`);
82
+ console.log(`Adminer: ${chalk.cyan(appURL + ":8080")}`);
83
+ console.log(`GraphiQL Playground: ${chalk.cyan(appURL + ":4000/graphql")}`);
77
84
 
78
85
  console.log(`\n${chalk.redBright("Note: learn how to avoid CORS errors in the GraphiQL Playground when running on localhost:")}`);
79
86
  console.log(`https://github.com/rollmug/directus-mysql-template#cors-problems-on-localhost`)
@@ -91,9 +98,9 @@ export default function launchServices() {
91
98
  }
92
99
  ]).then(answers => {
93
100
  if(answers.open_now === true) {
94
- open('http://localhost:8055');
95
- open('http://localhost:8080');
96
- open('http://localhost:4000/graphql');
101
+ open(process.env.PUBLIC_URL);
102
+ open(`${appURL}:8080`);
103
+ open(`${appURL}:4000/graphql`);
97
104
  } else {
98
105
  process.exit(1);
99
106
  }