@vendure/create 3.0.4 → 3.0.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/README.md +2 -32
- package/assets/Dockerfile.hbs +3 -3
- package/assets/docker-compose.hbs +114 -38
- package/assets/readme.hbs +22 -8
- package/lib/create-vendure-app.js +201 -57
- package/lib/create-vendure-app.js.map +1 -1
- package/lib/gather-user-responses.d.ts +3 -3
- package/lib/gather-user-responses.js +69 -31
- package/lib/gather-user-responses.js.map +1 -1
- package/lib/helpers.d.ts +24 -3
- package/lib/helpers.js +189 -73
- package/lib/helpers.js.map +1 -1
- package/lib/logger.d.ts +6 -0
- package/lib/logger.js +22 -0
- package/lib/logger.js.map +1 -0
- package/lib/types.d.ts +2 -2
- package/package.json +5 -4
|
@@ -3,18 +3,69 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getCiConfiguration = exports.getManualConfiguration = exports.getQuickStartConfiguration = void 0;
|
|
7
7
|
const prompts_1 = require("@clack/prompts");
|
|
8
8
|
const shared_constants_1 = require("@vendure/common/lib/shared-constants");
|
|
9
9
|
const crypto_1 = require("crypto");
|
|
10
10
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
11
11
|
const handlebars_1 = __importDefault(require("handlebars"));
|
|
12
12
|
const path_1 = __importDefault(require("path"));
|
|
13
|
+
const helpers_1 = require("./helpers");
|
|
13
14
|
/* eslint-disable no-console */
|
|
15
|
+
async function getQuickStartConfiguration(root, packageManager) {
|
|
16
|
+
// First we want to detect whether Docker is running
|
|
17
|
+
const { result: dockerStatus } = await (0, helpers_1.isDockerAvailable)();
|
|
18
|
+
let usePostgres;
|
|
19
|
+
switch (dockerStatus) {
|
|
20
|
+
case 'running':
|
|
21
|
+
usePostgres = true;
|
|
22
|
+
break;
|
|
23
|
+
case 'not-found':
|
|
24
|
+
usePostgres = false;
|
|
25
|
+
break;
|
|
26
|
+
case 'not-running': {
|
|
27
|
+
let useSqlite = false;
|
|
28
|
+
let dockerIsNowRunning = false;
|
|
29
|
+
do {
|
|
30
|
+
const useSqliteResponse = await (0, prompts_1.select)({
|
|
31
|
+
message: 'We could not automatically start Docker. How should we proceed?',
|
|
32
|
+
options: [
|
|
33
|
+
{ label: `Let's use SQLite as the database`, value: true },
|
|
34
|
+
{ label: 'I have manually started Docker', value: false },
|
|
35
|
+
],
|
|
36
|
+
initialValue: true,
|
|
37
|
+
});
|
|
38
|
+
(0, helpers_1.checkCancel)(useSqlite);
|
|
39
|
+
useSqlite = useSqliteResponse;
|
|
40
|
+
if (useSqlite === false) {
|
|
41
|
+
const { result: dockerStatusManual } = await (0, helpers_1.isDockerAvailable)();
|
|
42
|
+
dockerIsNowRunning = dockerStatusManual === 'running';
|
|
43
|
+
}
|
|
44
|
+
} while (dockerIsNowRunning !== true && useSqlite === false);
|
|
45
|
+
usePostgres = !useSqlite;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const quickStartAnswers = {
|
|
50
|
+
dbType: usePostgres ? 'postgres' : 'sqlite',
|
|
51
|
+
dbHost: usePostgres ? 'localhost' : '',
|
|
52
|
+
dbPort: usePostgres ? '6543' : '',
|
|
53
|
+
dbName: usePostgres ? 'vendure' : '',
|
|
54
|
+
dbUserName: usePostgres ? 'vendure' : '',
|
|
55
|
+
dbPassword: usePostgres ? (0, crypto_1.randomBytes)(16).toString('base64url') : '',
|
|
56
|
+
dbSchema: usePostgres ? 'public' : '',
|
|
57
|
+
populateProducts: true,
|
|
58
|
+
superadminIdentifier: shared_constants_1.SUPER_ADMIN_USER_IDENTIFIER,
|
|
59
|
+
superadminPassword: shared_constants_1.SUPER_ADMIN_USER_PASSWORD,
|
|
60
|
+
};
|
|
61
|
+
const responses = Object.assign(Object.assign({}, (await generateSources(root, quickStartAnswers, packageManager))), { dbType: quickStartAnswers.dbType, populateProducts: quickStartAnswers.populateProducts, superadminIdentifier: quickStartAnswers.superadminIdentifier, superadminPassword: quickStartAnswers.superadminPassword });
|
|
62
|
+
return responses;
|
|
63
|
+
}
|
|
64
|
+
exports.getQuickStartConfiguration = getQuickStartConfiguration;
|
|
14
65
|
/**
|
|
15
66
|
* Prompts the user to determine how the new Vendure app should be configured.
|
|
16
67
|
*/
|
|
17
|
-
async function
|
|
68
|
+
async function getManualConfiguration(root, packageManager) {
|
|
18
69
|
const dbType = (await (0, prompts_1.select)({
|
|
19
70
|
message: 'Which database are you using?',
|
|
20
71
|
options: [
|
|
@@ -22,40 +73,39 @@ async function gatherUserResponses(root, alreadyRanScaffold, packageManager) {
|
|
|
22
73
|
{ label: 'MariaDB', value: 'mariadb' },
|
|
23
74
|
{ label: 'Postgres', value: 'postgres' },
|
|
24
75
|
{ label: 'SQLite', value: 'sqlite' },
|
|
25
|
-
{ label: 'SQL.js', value: 'sqljs' },
|
|
26
76
|
],
|
|
27
77
|
initialValue: 'sqlite',
|
|
28
78
|
}));
|
|
29
|
-
checkCancel(dbType);
|
|
30
|
-
const hasConnection = dbType !== 'sqlite'
|
|
79
|
+
(0, helpers_1.checkCancel)(dbType);
|
|
80
|
+
const hasConnection = dbType !== 'sqlite';
|
|
31
81
|
const dbHost = hasConnection
|
|
32
82
|
? await (0, prompts_1.text)({
|
|
33
83
|
message: "What's the database host address?",
|
|
34
84
|
initialValue: 'localhost',
|
|
35
85
|
})
|
|
36
86
|
: '';
|
|
37
|
-
checkCancel(dbHost);
|
|
87
|
+
(0, helpers_1.checkCancel)(dbHost);
|
|
38
88
|
const dbPort = hasConnection
|
|
39
89
|
? await (0, prompts_1.text)({
|
|
40
90
|
message: 'What port is the database listening on?',
|
|
41
91
|
initialValue: defaultDBPort(dbType).toString(),
|
|
42
92
|
})
|
|
43
93
|
: '';
|
|
44
|
-
checkCancel(dbPort);
|
|
94
|
+
(0, helpers_1.checkCancel)(dbPort);
|
|
45
95
|
const dbName = hasConnection
|
|
46
96
|
? await (0, prompts_1.text)({
|
|
47
97
|
message: "What's the name of the database?",
|
|
48
98
|
initialValue: 'vendure',
|
|
49
99
|
})
|
|
50
100
|
: '';
|
|
51
|
-
checkCancel(dbName);
|
|
101
|
+
(0, helpers_1.checkCancel)(dbName);
|
|
52
102
|
const dbSchema = dbType === 'postgres'
|
|
53
103
|
? await (0, prompts_1.text)({
|
|
54
104
|
message: "What's the schema name we should use?",
|
|
55
105
|
initialValue: 'public',
|
|
56
106
|
})
|
|
57
107
|
: '';
|
|
58
|
-
checkCancel(dbSchema);
|
|
108
|
+
(0, helpers_1.checkCancel)(dbSchema);
|
|
59
109
|
const dbSSL = dbType === 'postgres'
|
|
60
110
|
? await (0, prompts_1.select)({
|
|
61
111
|
message: 'Use SSL to connect to the database? (only enable if your database provider supports SSL)',
|
|
@@ -66,30 +116,30 @@ async function gatherUserResponses(root, alreadyRanScaffold, packageManager) {
|
|
|
66
116
|
initialValue: false,
|
|
67
117
|
})
|
|
68
118
|
: false;
|
|
69
|
-
checkCancel(dbSSL);
|
|
119
|
+
(0, helpers_1.checkCancel)(dbSSL);
|
|
70
120
|
const dbUserName = hasConnection
|
|
71
121
|
? await (0, prompts_1.text)({
|
|
72
122
|
message: "What's the database user name?",
|
|
73
123
|
})
|
|
74
124
|
: '';
|
|
75
|
-
checkCancel(dbUserName);
|
|
125
|
+
(0, helpers_1.checkCancel)(dbUserName);
|
|
76
126
|
const dbPassword = hasConnection
|
|
77
127
|
? await (0, prompts_1.text)({
|
|
78
128
|
message: "What's the database password?",
|
|
79
129
|
defaultValue: '',
|
|
80
130
|
})
|
|
81
131
|
: '';
|
|
82
|
-
checkCancel(dbPassword);
|
|
132
|
+
(0, helpers_1.checkCancel)(dbPassword);
|
|
83
133
|
const superadminIdentifier = await (0, prompts_1.text)({
|
|
84
134
|
message: 'What identifier do you want to use for the superadmin user?',
|
|
85
135
|
initialValue: shared_constants_1.SUPER_ADMIN_USER_IDENTIFIER,
|
|
86
136
|
});
|
|
87
|
-
checkCancel(superadminIdentifier);
|
|
137
|
+
(0, helpers_1.checkCancel)(superadminIdentifier);
|
|
88
138
|
const superadminPassword = await (0, prompts_1.text)({
|
|
89
139
|
message: 'What password do you want to use for the superadmin user?',
|
|
90
140
|
initialValue: shared_constants_1.SUPER_ADMIN_USER_PASSWORD,
|
|
91
141
|
});
|
|
92
|
-
checkCancel(superadminPassword);
|
|
142
|
+
(0, helpers_1.checkCancel)(superadminPassword);
|
|
93
143
|
const populateProducts = await (0, prompts_1.select)({
|
|
94
144
|
message: 'Populate with some sample product data?',
|
|
95
145
|
options: [
|
|
@@ -98,7 +148,7 @@ async function gatherUserResponses(root, alreadyRanScaffold, packageManager) {
|
|
|
98
148
|
],
|
|
99
149
|
initialValue: true,
|
|
100
150
|
});
|
|
101
|
-
checkCancel(populateProducts);
|
|
151
|
+
(0, helpers_1.checkCancel)(populateProducts);
|
|
102
152
|
const answers = {
|
|
103
153
|
dbType,
|
|
104
154
|
dbHost,
|
|
@@ -114,11 +164,11 @@ async function gatherUserResponses(root, alreadyRanScaffold, packageManager) {
|
|
|
114
164
|
};
|
|
115
165
|
return Object.assign(Object.assign({}, (await generateSources(root, answers, packageManager))), { dbType, populateProducts: answers.populateProducts, superadminIdentifier: answers.superadminIdentifier, superadminPassword: answers.superadminPassword });
|
|
116
166
|
}
|
|
117
|
-
exports.
|
|
167
|
+
exports.getManualConfiguration = getManualConfiguration;
|
|
118
168
|
/**
|
|
119
169
|
* Returns mock "user response" without prompting, for use in CI
|
|
120
170
|
*/
|
|
121
|
-
async function
|
|
171
|
+
async function getCiConfiguration(root, packageManager) {
|
|
122
172
|
const ciAnswers = {
|
|
123
173
|
dbType: 'sqlite',
|
|
124
174
|
dbHost: '',
|
|
@@ -132,15 +182,7 @@ async function gatherCiUserResponses(root, packageManager) {
|
|
|
132
182
|
};
|
|
133
183
|
return Object.assign(Object.assign({}, (await generateSources(root, ciAnswers, packageManager))), { dbType: ciAnswers.dbType, populateProducts: ciAnswers.populateProducts, superadminIdentifier: ciAnswers.superadminIdentifier, superadminPassword: ciAnswers.superadminPassword });
|
|
134
184
|
}
|
|
135
|
-
exports.
|
|
136
|
-
function checkCancel(value) {
|
|
137
|
-
if ((0, prompts_1.isCancel)(value)) {
|
|
138
|
-
(0, prompts_1.cancel)('Setup cancelled.');
|
|
139
|
-
process.exit(0);
|
|
140
|
-
}
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
exports.checkCancel = checkCancel;
|
|
185
|
+
exports.getCiConfiguration = getCiConfiguration;
|
|
144
186
|
/**
|
|
145
187
|
* Create the server index, worker and config source code based on the options specified by the CLI prompts.
|
|
146
188
|
*/
|
|
@@ -154,7 +196,7 @@ async function generateSources(root, answers, packageManager) {
|
|
|
154
196
|
handlebars_1.default.registerHelper('escapeSingle', (aString) => {
|
|
155
197
|
return typeof aString === 'string' ? aString.replace(/'/g, "\\'") : aString;
|
|
156
198
|
});
|
|
157
|
-
const templateContext = Object.assign(Object.assign({}, answers), {
|
|
199
|
+
const templateContext = Object.assign(Object.assign({}, answers), { dbType: answers.dbType === 'sqlite' ? 'better-sqlite3' : answers.dbType, name: path_1.default.basename(root), isSQLite: answers.dbType === 'sqlite', requiresConnection: answers.dbType !== 'sqlite', cookieSecret: (0, crypto_1.randomBytes)(16).toString('base64url') });
|
|
158
200
|
async function createSourceFile(filename, noEscape = false) {
|
|
159
201
|
const template = await fs_extra_1.default.readFile(assetPath(filename), 'utf-8');
|
|
160
202
|
return handlebars_1.default.compile(template, { noEscape })(templateContext);
|
|
@@ -177,10 +219,6 @@ function defaultDBPort(dbType) {
|
|
|
177
219
|
return 3306;
|
|
178
220
|
case 'postgres':
|
|
179
221
|
return 5432;
|
|
180
|
-
case 'mssql':
|
|
181
|
-
return 1433;
|
|
182
|
-
case 'oracle':
|
|
183
|
-
return 1521;
|
|
184
222
|
default:
|
|
185
223
|
return 3306;
|
|
186
224
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gather-user-responses.js","sourceRoot":"","sources":["../src/gather-user-responses.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"gather-user-responses.js","sourceRoot":"","sources":["../src/gather-user-responses.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA8C;AAC9C,2EAA8G;AAC9G,mCAAqC;AACrC,wDAA0B;AAC1B,4DAAoC;AACpC,gDAAwB;AAExB,uCAA2D;AAiB3D,+BAA+B;AAExB,KAAK,UAAU,0BAA0B,CAC5C,IAAY,EACZ,cAA8B;IAE9B,oDAAoD;IACpD,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,IAAA,2BAAiB,GAAE,CAAC;IAC3D,IAAI,WAAoB,CAAC;IACzB,QAAQ,YAAY,EAAE,CAAC;QACnB,KAAK,SAAS;YACV,WAAW,GAAG,IAAI,CAAC;YACnB,MAAM;QACV,KAAK,WAAW;YACZ,WAAW,GAAG,KAAK,CAAC;YACpB,MAAM;QACV,KAAK,aAAa,CAAC,CAAC,CAAC;YACjB,IAAI,SAAS,GAAG,KAAK,CAAC;YACtB,IAAI,kBAAkB,GAAG,KAAK,CAAC;YAC/B,GAAG,CAAC;gBACA,MAAM,iBAAiB,GAAG,MAAM,IAAA,gBAAM,EAAC;oBACnC,OAAO,EAAE,iEAAiE;oBAC1E,OAAO,EAAE;wBACL,EAAE,KAAK,EAAE,kCAAkC,EAAE,KAAK,EAAE,IAAI,EAAE;wBAC1D,EAAE,KAAK,EAAE,gCAAgC,EAAE,KAAK,EAAE,KAAK,EAAE;qBAC5D;oBACD,YAAY,EAAE,IAAI;iBACrB,CAAC,CAAC;gBACH,IAAA,qBAAW,EAAC,SAAS,CAAC,CAAC;gBACvB,SAAS,GAAG,iBAA4B,CAAC;gBACzC,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;oBACtB,MAAM,EAAE,MAAM,EAAE,kBAAkB,EA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,EAAE,QAAQ,EAAE,CAAC,CAAC,eAAe,CAAC,CAAC;IACvE,CAAC;IAED,OAAO;QACH,WAAW,EAAE,MAAM,gBAAgB,CAAC,WAAW,CAAC;QAChD,iBAAiB,EAAE,MAAM,gBAAgB,CAAC,kBAAkB,CAAC;QAC7D,YAAY,EAAE,MAAM,gBAAgB,CAAC,oBAAoB,EAAE,IAAI,CAAC;QAChE,SAAS,EAAE,MAAM,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC;QACnD,YAAY,EAAE,MAAM,gBAAgB,CAAC,mBAAmB,EAAE,IAAI,CAAC;QAC/D,YAAY,EAAE,MAAM,gBAAgB,CAAC,YAAY,CAAC;QAClD,gBAAgB,EAAE,MAAM,gBAAgB,CAAC,gBAAgB,CAAC;QAC1D,mBAAmB,EAAE,MAAM,gBAAgB,CAAC,oBAAoB,CAAC;KACpE,CAAC;AACN,CAAC;AAED,SAAS,aAAa,CAAC,MAAc;IACjC,QAAQ,MAAM,EAAE,CAAC;QACb,KAAK,OAAO,CAAC;QACb,KAAK,SAAS;YACV,OAAO,IAAI,CAAC;QAChB,KAAK,UAAU;YACX,OAAO,IAAI,CAAC;QAChB;YACI,OAAO,IAAI,CAAC;IACpB,CAAC;AACL,CAAC"}
|
package/lib/helpers.d.ts
CHANGED
|
@@ -9,14 +9,17 @@ import { CliLogLevel, DbType } from './types';
|
|
|
9
9
|
export declare function isSafeToCreateProjectIn(root: string, name: string): boolean;
|
|
10
10
|
export declare function scaffoldAlreadyExists(root: string, name: string): boolean;
|
|
11
11
|
export declare function checkNodeVersion(requiredVersion: string): void;
|
|
12
|
-
export declare function yarnIsAvailable(): boolean;
|
|
13
12
|
export declare function bunIsAvailable(): boolean;
|
|
14
13
|
export declare function checkThatNpmCanReadCwd(): boolean;
|
|
15
14
|
/**
|
|
16
|
-
* Install packages via npm
|
|
15
|
+
* Install packages via npm.
|
|
17
16
|
* Based on the install function from https://github.com/facebook/create-react-app
|
|
18
17
|
*/
|
|
19
|
-
export declare function installPackages(
|
|
18
|
+
export declare function installPackages(options: {
|
|
19
|
+
dependencies: string[];
|
|
20
|
+
isDevDependencies?: boolean;
|
|
21
|
+
logLevel: CliLogLevel;
|
|
22
|
+
}): Promise<void>;
|
|
20
23
|
export declare function getDependencies(dbType: DbType, vendurePkgVersion?: string): {
|
|
21
24
|
dependencies: string[];
|
|
22
25
|
devDependencies: string[];
|
|
@@ -26,4 +29,22 @@ export declare function getDependencies(dbType: DbType, vendurePkgVersion?: stri
|
|
|
26
29
|
* established) and that the named database exists.
|
|
27
30
|
*/
|
|
28
31
|
export declare function checkDbConnection(options: any, root: string): Promise<true>;
|
|
32
|
+
/**
|
|
33
|
+
* Check to see if Docker is installed and running.
|
|
34
|
+
* If not, attempt to start it.
|
|
35
|
+
* If that is not possible, return false.
|
|
36
|
+
*
|
|
37
|
+
* Refs:
|
|
38
|
+
* - https://stackoverflow.com/a/48843074/772859
|
|
39
|
+
*/
|
|
40
|
+
export declare function isDockerAvailable(): Promise<{
|
|
41
|
+
result: 'not-found' | 'not-running' | 'running';
|
|
42
|
+
}>;
|
|
43
|
+
export declare function startPostgresDatabase(root: string): Promise<boolean>;
|
|
29
44
|
export declare function isServerPortInUse(port: number): Promise<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Checks if the response from a Clack prompt was a cancellation symbol, and if so,
|
|
47
|
+
* ends the interactive process.
|
|
48
|
+
*/
|
|
49
|
+
export declare function checkCancel<T>(value: T | symbol): value is T;
|
|
50
|
+
export declare function cleanUpDockerResources(name: string): void;
|
package/lib/helpers.js
CHANGED
|
@@ -26,15 +26,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.isServerPortInUse = exports.checkDbConnection = exports.getDependencies = exports.installPackages = exports.checkThatNpmCanReadCwd = exports.bunIsAvailable = exports.
|
|
30
|
-
|
|
31
|
-
const child_process_1 = require("child_process");
|
|
29
|
+
exports.cleanUpDockerResources = exports.checkCancel = exports.isServerPortInUse = exports.startPostgresDatabase = exports.isDockerAvailable = exports.checkDbConnection = exports.getDependencies = exports.installPackages = exports.checkThatNpmCanReadCwd = exports.bunIsAvailable = exports.checkNodeVersion = exports.scaffoldAlreadyExists = exports.isSafeToCreateProjectIn = void 0;
|
|
30
|
+
const prompts_1 = require("@clack/prompts");
|
|
32
31
|
const cross_spawn_1 = __importDefault(require("cross-spawn"));
|
|
33
32
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
33
|
+
const node_child_process_1 = require("node:child_process");
|
|
34
|
+
const node_os_1 = require("node:os");
|
|
35
|
+
const node_util_1 = require("node:util");
|
|
34
36
|
const path_1 = __importDefault(require("path"));
|
|
35
37
|
const picocolors_1 = __importDefault(require("picocolors"));
|
|
36
38
|
const semver_1 = __importDefault(require("semver"));
|
|
37
39
|
const constants_1 = require("./constants");
|
|
40
|
+
const logger_1 = require("./logger");
|
|
38
41
|
/**
|
|
39
42
|
* If project only contains files generated by GH, it’s safe.
|
|
40
43
|
* Also, if project contains remnant error logs from a previous
|
|
@@ -72,7 +75,6 @@ function isSafeToCreateProjectIn(root, name) {
|
|
|
72
75
|
'tsconfig.json',
|
|
73
76
|
'yarn.lock',
|
|
74
77
|
];
|
|
75
|
-
console.log();
|
|
76
78
|
const conflicts = fs_extra_1.default
|
|
77
79
|
.readdirSync(root)
|
|
78
80
|
.filter(file => !validFiles.includes(file))
|
|
@@ -81,13 +83,13 @@ function isSafeToCreateProjectIn(root, name) {
|
|
|
81
83
|
// Don't treat log files from previous installation as conflicts
|
|
82
84
|
.filter(file => !errorLogFilePatterns.some(pattern => file.indexOf(pattern) === 0));
|
|
83
85
|
if (conflicts.length > 0) {
|
|
84
|
-
|
|
85
|
-
console.log();
|
|
86
|
+
(0, logger_1.log)(`The directory ${picocolors_1.default.green(name)} contains files that could conflict:`, { newline: 'after' });
|
|
86
87
|
for (const file of conflicts) {
|
|
87
|
-
|
|
88
|
+
(0, logger_1.log)(` ${file}`);
|
|
88
89
|
}
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
(0, logger_1.log)('Either try using a new directory name, or remove the files listed above.', {
|
|
91
|
+
newline: 'before',
|
|
92
|
+
});
|
|
91
93
|
return false;
|
|
92
94
|
}
|
|
93
95
|
// Remove any remnant files from a previous installation
|
|
@@ -111,34 +113,19 @@ function scaffoldAlreadyExists(root, name) {
|
|
|
111
113
|
exports.scaffoldAlreadyExists = scaffoldAlreadyExists;
|
|
112
114
|
function checkNodeVersion(requiredVersion) {
|
|
113
115
|
if (!semver_1.default.satisfies(process.version, requiredVersion)) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
'Please update your version of Node.')
|
|
116
|
+
(0, logger_1.log)(picocolors_1.default.red(`You are running Node ${process.version}.` +
|
|
117
|
+
`Vendure requires Node ${requiredVersion} or higher.` +
|
|
118
|
+
'Please update your version of Node.'));
|
|
117
119
|
process.exit(1);
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
122
|
exports.checkNodeVersion = checkNodeVersion;
|
|
121
|
-
function yarnIsAvailable() {
|
|
122
|
-
try {
|
|
123
|
-
const yarnVersion = (0, child_process_1.execSync)('yarnpkg --version');
|
|
124
|
-
if (semver_1.default.major(yarnVersion.toString()) > 1) {
|
|
125
|
-
return true;
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
catch (e) {
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
exports.yarnIsAvailable = yarnIsAvailable;
|
|
136
123
|
// Bun support should not be exposed yet, see
|
|
137
124
|
// https://github.com/oven-sh/bun/issues/4947
|
|
138
125
|
// https://github.com/lovell/sharp/issues/3511
|
|
139
126
|
function bunIsAvailable() {
|
|
140
127
|
try {
|
|
141
|
-
(0,
|
|
128
|
+
(0, node_child_process_1.execFileSync)('bun', ['--version'], { stdio: 'ignore' });
|
|
142
129
|
return true;
|
|
143
130
|
}
|
|
144
131
|
catch (e) {
|
|
@@ -180,12 +167,12 @@ function checkThatNpmCanReadCwd() {
|
|
|
180
167
|
if (npmCWD === cwd) {
|
|
181
168
|
return true;
|
|
182
169
|
}
|
|
183
|
-
|
|
170
|
+
(0, logger_1.log)(picocolors_1.default.red('Could not start an npm process in the right directory.\n\n' +
|
|
184
171
|
`The current directory is: ${picocolors_1.default.bold(cwd)}\n` +
|
|
185
172
|
`However, a newly started npm process runs in: ${picocolors_1.default.bold(npmCWD)}\n\n` +
|
|
186
173
|
'This is probably caused by a misconfigured system terminal shell.'));
|
|
187
174
|
if (process.platform === 'win32') {
|
|
188
|
-
|
|
175
|
+
(0, logger_1.log)(picocolors_1.default.red('On Windows, this can usually be fixed by running:\n\n') +
|
|
189
176
|
` ${picocolors_1.default.cyan('reg')} delete "HKCU\\Software\\Microsoft\\Command Processor" /v AutoRun /f\n` +
|
|
190
177
|
` ${picocolors_1.default.cyan('reg')} delete "HKLM\\Software\\Microsoft\\Command Processor" /v AutoRun /f\n\n` +
|
|
191
178
|
picocolors_1.default.red('Try to run the above two lines in the terminal.\n') +
|
|
@@ -195,52 +182,26 @@ function checkThatNpmCanReadCwd() {
|
|
|
195
182
|
}
|
|
196
183
|
exports.checkThatNpmCanReadCwd = checkThatNpmCanReadCwd;
|
|
197
184
|
/**
|
|
198
|
-
* Install packages via npm
|
|
185
|
+
* Install packages via npm.
|
|
199
186
|
* Based on the install function from https://github.com/facebook/create-react-app
|
|
200
187
|
*/
|
|
201
|
-
function installPackages(
|
|
188
|
+
function installPackages(options) {
|
|
189
|
+
const { dependencies, isDevDependencies = false, logLevel } = options;
|
|
202
190
|
return new Promise((resolve, reject) => {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (
|
|
206
|
-
|
|
207
|
-
args = ['add', '--exact', '--ignore-engines'];
|
|
208
|
-
if (isDev) {
|
|
209
|
-
args.push('--dev');
|
|
210
|
-
}
|
|
211
|
-
if (isCi) {
|
|
212
|
-
// In CI, publish to Verdaccio
|
|
213
|
-
// See https://github.com/yarnpkg/yarn/issues/6029
|
|
214
|
-
args.push('--registry http://localhost:4873/');
|
|
215
|
-
// Increase network timeout
|
|
216
|
-
// See https://github.com/yarnpkg/yarn/issues/4890#issuecomment-358179301
|
|
217
|
-
args.push('--network-timeout 300000');
|
|
218
|
-
}
|
|
219
|
-
args = args.concat(dependencies);
|
|
220
|
-
// Explicitly set cwd() to work around issues like
|
|
221
|
-
// https://github.com/facebook/create-react-app/issues/3326.
|
|
222
|
-
// Unfortunately we can only do this for Yarn because npm support for
|
|
223
|
-
// equivalent --prefix flag doesn't help with this issue.
|
|
224
|
-
// This is why for npm, we run checkThatNpmCanReadCwd() early instead.
|
|
225
|
-
args.push('--cwd');
|
|
226
|
-
args.push(root);
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
command = 'npm';
|
|
230
|
-
args = ['install', '--save', '--save-exact', '--loglevel', 'error'].concat(dependencies);
|
|
231
|
-
if (isDev) {
|
|
232
|
-
args.push('--save-dev');
|
|
233
|
-
}
|
|
191
|
+
const command = 'npm';
|
|
192
|
+
const args = ['install', '--save', '--save-exact', '--loglevel', 'error'].concat(dependencies);
|
|
193
|
+
if (isDevDependencies) {
|
|
194
|
+
args.push('--save-dev');
|
|
234
195
|
}
|
|
235
196
|
if (logLevel === 'verbose') {
|
|
236
197
|
args.push('--verbose');
|
|
237
198
|
}
|
|
238
|
-
const child = (0, cross_spawn_1.default)(command, args, { stdio: logLevel === '
|
|
199
|
+
const child = (0, cross_spawn_1.default)(command, args, { stdio: logLevel === 'verbose' ? 'inherit' : 'ignore' });
|
|
239
200
|
child.on('close', code => {
|
|
240
201
|
if (code !== 0) {
|
|
241
202
|
let message = 'An error occurred when installing dependencies.';
|
|
242
203
|
if (logLevel === 'silent') {
|
|
243
|
-
message += ' Try running with `--log-level
|
|
204
|
+
message += ' Try running with `--log-level verbose` to diagnose.';
|
|
244
205
|
}
|
|
245
206
|
reject({
|
|
246
207
|
message,
|
|
@@ -283,15 +244,9 @@ function dbDriverPackage(dbType) {
|
|
|
283
244
|
return 'pg';
|
|
284
245
|
case 'sqlite':
|
|
285
246
|
return 'better-sqlite3';
|
|
286
|
-
case 'sqljs':
|
|
287
|
-
return 'sql.js';
|
|
288
|
-
case 'mssql':
|
|
289
|
-
return 'mssql';
|
|
290
|
-
case 'oracle':
|
|
291
|
-
return 'oracledb';
|
|
292
247
|
default:
|
|
293
248
|
const n = dbType;
|
|
294
|
-
|
|
249
|
+
(0, logger_1.log)(picocolors_1.default.red(`No driver package configured for type "${dbType}"`));
|
|
295
250
|
return '';
|
|
296
251
|
}
|
|
297
252
|
}
|
|
@@ -374,6 +329,138 @@ async function checkPostgresDbExists(options, root) {
|
|
|
374
329
|
await client.end();
|
|
375
330
|
return true;
|
|
376
331
|
}
|
|
332
|
+
/**
|
|
333
|
+
* Check to see if Docker is installed and running.
|
|
334
|
+
* If not, attempt to start it.
|
|
335
|
+
* If that is not possible, return false.
|
|
336
|
+
*
|
|
337
|
+
* Refs:
|
|
338
|
+
* - https://stackoverflow.com/a/48843074/772859
|
|
339
|
+
*/
|
|
340
|
+
async function isDockerAvailable() {
|
|
341
|
+
const dockerSpinner = (0, prompts_1.spinner)();
|
|
342
|
+
function isDaemonRunning() {
|
|
343
|
+
try {
|
|
344
|
+
(0, node_child_process_1.execFileSync)('docker', ['stats', '--no-stream'], { stdio: 'ignore' });
|
|
345
|
+
return true;
|
|
346
|
+
}
|
|
347
|
+
catch (e) {
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
dockerSpinner.start('Checking for Docker');
|
|
352
|
+
try {
|
|
353
|
+
(0, node_child_process_1.execFileSync)('docker', ['-v'], { stdio: 'ignore' });
|
|
354
|
+
dockerSpinner.message('Docker was found!');
|
|
355
|
+
}
|
|
356
|
+
catch (e) {
|
|
357
|
+
dockerSpinner.stop('Docker was not found on this machine. We will use SQLite for the database.');
|
|
358
|
+
return { result: 'not-found' };
|
|
359
|
+
}
|
|
360
|
+
// Now we need to check if the docker daemon is running
|
|
361
|
+
const isRunning = isDaemonRunning();
|
|
362
|
+
if (isRunning) {
|
|
363
|
+
dockerSpinner.stop('Docker is running');
|
|
364
|
+
return { result: 'running' };
|
|
365
|
+
}
|
|
366
|
+
dockerSpinner.message('Docker daemon is not running. Attempting to start');
|
|
367
|
+
// detect the current OS
|
|
368
|
+
const currentPlatform = (0, node_os_1.platform)();
|
|
369
|
+
try {
|
|
370
|
+
if (currentPlatform === 'win32') {
|
|
371
|
+
// https://stackoverflow.com/a/44182489/772859
|
|
372
|
+
(0, node_child_process_1.execSync)('"C:\\Program Files\\Docker\\Docker\\Docker Desktop.exe"', { stdio: 'ignore' });
|
|
373
|
+
}
|
|
374
|
+
else if (currentPlatform === 'darwin') {
|
|
375
|
+
(0, node_child_process_1.execSync)('open -a Docker', { stdio: 'ignore' });
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
(0, node_child_process_1.execSync)('systemctl start docker', { stdio: 'ignore' });
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
catch (e) {
|
|
382
|
+
dockerSpinner.stop('Could not start Docker.');
|
|
383
|
+
(0, logger_1.log)(e.message, { level: 'verbose' });
|
|
384
|
+
return { result: 'not-running' };
|
|
385
|
+
}
|
|
386
|
+
// Verify that the daemon is now running
|
|
387
|
+
let attempts = 1;
|
|
388
|
+
do {
|
|
389
|
+
(0, logger_1.log)(`Checking for Docker daemon... (attempt ${attempts})`, { level: 'verbose' });
|
|
390
|
+
if (isDaemonRunning()) {
|
|
391
|
+
(0, logger_1.log)(`Docker daemon is now running (after ${attempts} attempts).`, { level: 'verbose' });
|
|
392
|
+
dockerSpinner.stop('Docker is running');
|
|
393
|
+
return { result: 'running' };
|
|
394
|
+
}
|
|
395
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
396
|
+
attempts++;
|
|
397
|
+
} while (attempts < 100);
|
|
398
|
+
dockerSpinner.stop('Docker daemon could not be started');
|
|
399
|
+
return { result: 'not-running' };
|
|
400
|
+
}
|
|
401
|
+
exports.isDockerAvailable = isDockerAvailable;
|
|
402
|
+
async function startPostgresDatabase(root) {
|
|
403
|
+
var _a;
|
|
404
|
+
// Now we need to run the postgres database via Docker
|
|
405
|
+
let containerName;
|
|
406
|
+
const postgresContainerSpinner = (0, prompts_1.spinner)();
|
|
407
|
+
postgresContainerSpinner.start('Starting PostgreSQL database');
|
|
408
|
+
try {
|
|
409
|
+
const result = await (0, node_util_1.promisify)(node_child_process_1.execFile)(`docker`, [
|
|
410
|
+
`compose`,
|
|
411
|
+
`-f`,
|
|
412
|
+
path_1.default.join(root, 'docker-compose.yml'),
|
|
413
|
+
`up`,
|
|
414
|
+
`-d`,
|
|
415
|
+
`postgres_db`,
|
|
416
|
+
]);
|
|
417
|
+
containerName = (_a = result.stderr.match(/Container\s+(.+-postgres_db[^ ]*)/)) === null || _a === void 0 ? void 0 : _a[1];
|
|
418
|
+
if (!containerName) {
|
|
419
|
+
// guess the container name based on the directory name
|
|
420
|
+
containerName = path_1.default.basename(root).replace(/[^a-z0-9]/gi, '') + '-postgres_db-1';
|
|
421
|
+
postgresContainerSpinner.message('Could not find container name. Guessing it is: ' + containerName);
|
|
422
|
+
(0, logger_1.log)(picocolors_1.default.red('Could not find container name. Guessing it is: ' + containerName), {
|
|
423
|
+
newline: 'before',
|
|
424
|
+
level: 'verbose',
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
(0, logger_1.log)(picocolors_1.default.green(`Started PostgreSQL database in container "${containerName}"`), {
|
|
429
|
+
newline: 'before',
|
|
430
|
+
level: 'verbose',
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
catch (e) {
|
|
435
|
+
(0, logger_1.log)(picocolors_1.default.red(`Failed to start PostgreSQL database: ${e.message}`));
|
|
436
|
+
postgresContainerSpinner.stop('Failed to start PostgreSQL database');
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
postgresContainerSpinner.message(`Waiting for PostgreSQL database to be ready...`);
|
|
440
|
+
let attempts = 1;
|
|
441
|
+
let isReady = false;
|
|
442
|
+
do {
|
|
443
|
+
// We now need to ensure that the database is ready to accept connections
|
|
444
|
+
try {
|
|
445
|
+
const result = (0, node_child_process_1.execFileSync)(`docker`, [`exec`, `-i`, containerName, `pg_isready`]);
|
|
446
|
+
isReady = result === null || result === void 0 ? void 0 : result.toString().includes('accepting connections');
|
|
447
|
+
if (!isReady) {
|
|
448
|
+
(0, logger_1.log)(picocolors_1.default.yellow(`PostgreSQL database not yet ready. Attempt ${attempts}...`), {
|
|
449
|
+
level: 'verbose',
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
catch (e) {
|
|
454
|
+
// ignore
|
|
455
|
+
(0, logger_1.log)('is_ready error:' + e.message, { level: 'verbose', newline: 'before' });
|
|
456
|
+
}
|
|
457
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
458
|
+
attempts++;
|
|
459
|
+
} while (!isReady && attempts < 100);
|
|
460
|
+
postgresContainerSpinner.stop('PostgreSQL database is ready');
|
|
461
|
+
return true;
|
|
462
|
+
}
|
|
463
|
+
exports.startPostgresDatabase = startPostgresDatabase;
|
|
377
464
|
function throwConnectionError(err) {
|
|
378
465
|
throw new Error('Could not connect to the database. ' +
|
|
379
466
|
`Please check the connection settings in your Vendure config.\n[${(err.message || err.toString())}]`);
|
|
@@ -398,9 +485,38 @@ function isServerPortInUse(port) {
|
|
|
398
485
|
return tcpPortUsed.check(port);
|
|
399
486
|
}
|
|
400
487
|
catch (e) {
|
|
401
|
-
|
|
488
|
+
(0, logger_1.log)(picocolors_1.default.yellow(`Warning: could not determine whether port ${port} is available`));
|
|
402
489
|
return Promise.resolve(false);
|
|
403
490
|
}
|
|
404
491
|
}
|
|
405
492
|
exports.isServerPortInUse = isServerPortInUse;
|
|
493
|
+
/**
|
|
494
|
+
* Checks if the response from a Clack prompt was a cancellation symbol, and if so,
|
|
495
|
+
* ends the interactive process.
|
|
496
|
+
*/
|
|
497
|
+
function checkCancel(value) {
|
|
498
|
+
if ((0, prompts_1.isCancel)(value)) {
|
|
499
|
+
(0, prompts_1.cancel)('Setup cancelled.');
|
|
500
|
+
process.exit(0);
|
|
501
|
+
}
|
|
502
|
+
return true;
|
|
503
|
+
}
|
|
504
|
+
exports.checkCancel = checkCancel;
|
|
505
|
+
function cleanUpDockerResources(name) {
|
|
506
|
+
try {
|
|
507
|
+
(0, node_child_process_1.execSync)(`docker stop $(docker ps -a -q --filter "label=io.vendure.create.name=${name}")`, {
|
|
508
|
+
stdio: 'ignore',
|
|
509
|
+
});
|
|
510
|
+
(0, node_child_process_1.execSync)(`docker rm $(docker ps -a -q --filter "label=io.vendure.create.name=${name}")`, {
|
|
511
|
+
stdio: 'ignore',
|
|
512
|
+
});
|
|
513
|
+
(0, node_child_process_1.execSync)(`docker volume rm $(docker volume ls --filter "label=io.vendure.create.name=${name}" -q)`, {
|
|
514
|
+
stdio: 'ignore',
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
catch (e) {
|
|
518
|
+
(0, logger_1.log)(picocolors_1.default.yellow(`Could not clean up Docker resources`), { level: 'verbose' });
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
exports.cleanUpDockerResources = cleanUpDockerResources;
|
|
406
522
|
//# sourceMappingURL=helpers.js.map
|