generator-razor 13.4.134 → 14.0.1

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 (2) hide show
  1. package/app/index.js +921 -515
  2. package/package.json +15 -16
package/app/index.js CHANGED
@@ -1,607 +1,1013 @@
1
- 'use strict'
2
- const Generator = require('yeoman-generator')
3
- const chalk = require('chalk')
4
- const yosay = require('yosay')
5
- const link = require('fs-symlink')
6
- const mysql = require('mysql')
7
- const fs = require('fs-extra')
8
- const pathExists = require('path-exists')
9
- const request = require('request')
10
- const argon2 = require('argon2')
11
- const copydir = require('copy-dir')
12
- const crypto = require('crypto')
13
- const remote = require('yeoman-remote')
14
- const path = require('path')
15
-
16
- let rzr
17
-
18
- module.exports = class extends Generator {
19
- prompting () {
20
- const t = this
21
- const done = this.async()
22
-
23
- this.log(yosay(
24
- 'Welcome to the official TYPO3 ' + chalk.red('razor') + ' generator!'
25
- ))
26
-
27
- this._getSrc(this, 'https://get.typo3.org/json', (response) => {
28
- const prompts = [{
29
- type: 'input',
30
- name: 'ProjectName',
31
- message: 'Choose your project name',
32
- default: 'Project'
33
- }, {
34
- type: 'input',
35
- name: 'SrcPath',
36
- message: 'What is the path to the TYPO3 source files?',
37
- default: '../typo3_src',
38
- store: true
39
- }, {
40
- type: 'list',
41
- name: 'Version',
42
- message: 'Choose your TYPO3 version',
43
- choices: response,
44
- store: true
45
- }, {
46
- type: 'input',
47
- name: 'DbUsername',
48
- message: 'Database username?',
49
- default: 'root',
50
- store: true
51
- }, {
52
- type: 'input',
53
- name: 'DbPassword',
54
- message: 'Database password?',
55
- default: 'root',
56
- store: true
57
- }, {
58
- type: 'input',
59
- name: 'DbHostname',
60
- message: 'Database hostname?',
61
- default: 'localhost',
62
- store: true
63
- }, {
64
- type: 'list',
65
- name: 'DbSocket',
66
- message: 'Database socket path?',
67
- choices: [{
68
- name: 'None',
69
- value: ''
70
- }, {
71
- name: 'MAMP',
72
- value: '/Applications/MAMP/tmp/mysql/mysql.sock'
73
- }],
74
- store: true
75
- }, {
76
- type: 'input',
77
- name: 'DbNew',
78
- message: 'New database name? A new database, username and password will be created.',
79
- default: 'newproject'
80
- }, {
81
- type: 'input',
82
- name: 'User',
83
- message: 'TYPO3 admin username?',
84
- default: 'admin',
85
- store: true
86
- }, {
87
- type: 'input',
88
- name: 'Pass',
89
- message: 'TYPO3 install tool & admin user password?',
90
- default: 'joh316'
91
- }, {
92
- type: 'input',
93
- name: 'AdminEmail',
94
- message: 'TYPO3 admin email?',
95
- default: 'john@doe.com',
96
- store: true
97
- }, {
98
- type: 'list',
99
- name: 'Transport',
100
- message: 'How to send emails?',
101
- choices: [{
102
- name: 'smtp',
103
- value: 'smtp'
104
- }, {
105
- name: 'sendmail',
106
- value: 'sendmail'
107
- }],
108
- store: true
109
- }, {
110
- when: answers => answers.Transport === 'smtp',
111
- type: 'input',
112
- name: 'SmtpServer',
113
- message: 'SMTP server?',
114
- default: 'localhost:25',
115
- store: true
116
- }, {
117
- when: answers => answers.Transport === 'smtp',
118
- type: 'list',
119
- name: 'Encrypt',
120
- message: 'SMTP encrypt?',
121
- default: true,
122
- choices: [{
123
- name: 'true (TYPO3 >= 10 - if port 465 or other)',
124
- value: true
125
- }, {
126
- name: 'false (TYPO3 >= 10 - if port 587)',
127
- value: false
128
- }, {
129
- name: 'ssl (TYPO3 9.5.x)',
130
- value: 'ssl'
131
- }, {
132
- name: 'tls (TYPO3 9.5.x)',
133
- value: 'tls'
134
- }],
135
- store: true
136
- }, {
137
- when: answers => answers.Transport === 'smtp',
138
- type: 'input',
139
- name: 'SmtpUser',
140
- message: 'SMTP username?',
141
- default: '',
142
- store: true
143
- }, {
144
- when: answers => answers.Transport === 'smtp',
145
- type: 'input',
146
- name: 'SmtpPass',
147
- message: 'SMTP password?',
148
- default: '',
149
- store: true
1
+ import Generator from 'yeoman-generator'
2
+ import chalk from 'chalk'
3
+ import mysql from 'mysql2/promise'
4
+ import fs from 'fs-extra'
5
+ import argon2 from 'argon2'
6
+ import * as tar from 'tar'
7
+
8
+ import crypto from 'node:crypto'
9
+ import path from 'node:path'
10
+ import os from 'node:os'
11
+ import process from 'node:process'
12
+ import { spawn } from 'node:child_process'
13
+ import { Readable } from 'node:stream'
14
+ import { pipeline } from 'node:stream/promises'
15
+
16
+ export default class extends Generator {
17
+ constructor (args, options) {
18
+ super(args, options)
19
+
20
+ this.props = {}
21
+ }
22
+
23
+ async prompting () {
24
+ const orange = chalk.hex('#ff8700').bold
25
+ const petrol = chalk.hex('#006792')
26
+
27
+ this.log(orange(`
28
+ ██████╗ █████╗ ███████╗ ██████╗ ██████╗
29
+ ██╔══██╗██╔══██╗╚══███╔╝██╔═══██╗██╔══██╗
30
+ ██████╔╝███████║ ███╔╝ ██║ ██║██████╔╝
31
+ ██╔══██╗██╔══██║ ███╔╝ ██║ ██║██╔══██╗
32
+ ██║ ██║██║ ██║███████╗╚██████╔╝██║ ██║
33
+ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝
34
+ `))
35
+
36
+ this.log(petrol(`
37
+ ________ ______ ____ _____ __
38
+ /_ __/\\ \\/ / __ \\/ __ \\__ / ____ ____ ____ ___ _________ _/ /_____ _____
39
+ / / \\ / /_/ / / / //_ < / __ \`/ _ \\/ __ \\/ _ \\/ ___/ __ \`/ __/ __ \\/ ___/
40
+ / / / / ____/ /_/ /__/ / / /_/ / __/ / / / __/ / / /_/ / /_/ /_/ / /
41
+ /_/ /_/_/ \\____/____/ \\__, /\\___/_/ /_/\\___/_/ \\__,_/\\__/\\____/_/
42
+ /____/
43
+ `))
44
+
45
+ const releases = await this._getTypo3Releases()
46
+
47
+ const prompts = [{
48
+ type: 'input',
49
+ name: 'ProjectName',
50
+ message: 'Choose your project name',
51
+ default: 'Project'
52
+ }, {
53
+ type: 'input',
54
+ name: 'SrcPath',
55
+ message: 'What is the path to the TYPO3 source files?',
56
+ default: '../typo3_src',
57
+ store: true
58
+ }, {
59
+ type: 'select',
60
+ name: 'Version',
61
+ message: 'Choose your TYPO3 version',
62
+ choices: releases,
63
+ store: true
64
+ }, {
65
+ type: 'input',
66
+ name: 'DbUsername',
67
+ message: 'Database username?',
68
+ default: 'root',
69
+ store: true
70
+ }, {
71
+ type: 'input',
72
+ name: 'DbPassword',
73
+ message: 'Database password?',
74
+ default: 'root',
75
+ store: true
76
+ }, {
77
+ type: 'input',
78
+ name: 'DbHostname',
79
+ message: 'Database hostname?',
80
+ default: 'localhost',
81
+ store: true
82
+ }, {
83
+ type: 'input',
84
+ name: 'DbPort',
85
+ message: 'Database port?',
86
+ default: 3306,
87
+ store: true,
88
+ validate: value => {
89
+ const port = Number(value)
90
+
91
+ if (Number.isInteger(port) && port >= 1 && port <= 65535) {
92
+ return true
93
+ }
94
+
95
+ return 'Enter a valid TCP port.'
96
+ }
97
+ }, {
98
+ type: 'select',
99
+ name: 'DbSocket',
100
+ message: 'Database socket path?',
101
+ choices: [{
102
+ name: 'None',
103
+ value: ''
150
104
  }, {
151
- when: answers => answers.Transport === 'smtp',
152
- type: 'input',
153
- name: 'SmtpEmail',
154
- message: 'Sender email?',
155
- default: '',
156
- store: true
105
+ name: 'MAMP',
106
+ value: '/Applications/MAMP/tmp/mysql/mysql.sock'
107
+ }],
108
+ store: true
109
+ }, {
110
+ type: 'input',
111
+ name: 'DbNew',
112
+ message: 'New database name? A new database, username and password will be created.',
113
+ default: 'newproject',
114
+ validate: value => {
115
+ if (/^[a-zA-Z0-9_]+$/.test(value)) {
116
+ return true
117
+ }
118
+
119
+ return 'Use only letters, numbers and underscores.'
120
+ }
121
+ }, {
122
+ type: 'input',
123
+ name: 'User',
124
+ message: 'TYPO3 admin username?',
125
+ default: 'admin',
126
+ store: true
127
+ }, {
128
+ type: 'input',
129
+ name: 'Pass',
130
+ message: 'TYPO3 install tool & admin user password?',
131
+ default: 'joh316'
132
+ }, {
133
+ type: 'input',
134
+ name: 'AdminEmail',
135
+ message: 'TYPO3 admin email?',
136
+ default: 'john@doe.com',
137
+ store: true
138
+ }, {
139
+ type: 'select',
140
+ name: 'Transport',
141
+ message: 'How to send emails?',
142
+ choices: [{
143
+ name: 'smtp',
144
+ value: 'smtp'
157
145
  }, {
158
- when: answers => answers.Transport === 'smtp',
159
- type: 'input',
160
- name: 'SmtpName',
161
- message: 'Sender name?',
162
- default: '',
163
- store: true
146
+ name: 'sendmail',
147
+ value: 'sendmail'
148
+ }],
149
+ store: true
150
+ }, {
151
+ when: answers => answers.Transport === 'smtp',
152
+ type: 'input',
153
+ name: 'SmtpServer',
154
+ message: 'SMTP server?',
155
+ default: 'localhost:25',
156
+ store: true
157
+ }, {
158
+ when: answers => answers.Transport === 'smtp',
159
+ type: 'select',
160
+ name: 'Encrypt',
161
+ message: 'SMTP encrypt?',
162
+ default: true,
163
+ choices: [{
164
+ name: 'true (TYPO3 >= 10 - if port 465 or other)',
165
+ value: true
164
166
  }, {
165
- type: 'list',
166
- name: 'English',
167
- message: 'Activate English language in TYPO3?',
168
- choices: [{
169
- name: 'No',
170
- value: false
171
- }, {
172
- name: 'Yes',
173
- value: true
174
- }],
175
- store: true
167
+ name: 'false (TYPO3 >= 10 - if port 587)',
168
+ value: false
176
169
  }, {
177
- type: 'list',
178
- name: 'EnglishDefault',
179
- message: 'Set English as default language?',
180
- choices: [{
181
- name: 'No',
182
- value: false
183
- }, {
184
- name: 'Yes',
185
- value: true
186
- }],
187
- store: true
170
+ name: 'ssl (TYPO3 9.5.x)',
171
+ value: 'ssl'
188
172
  }, {
189
- type: 'input',
190
- name: 'Author',
191
- message: 'Author name',
192
- default: 'John Doe',
193
- store: true
173
+ name: 'tls (TYPO3 9.5.x)',
174
+ value: 'tls'
175
+ }],
176
+ store: true
177
+ }, {
178
+ when: answers => answers.Transport === 'smtp',
179
+ type: 'input',
180
+ name: 'SmtpUser',
181
+ message: 'SMTP username?',
182
+ default: '',
183
+ store: true
184
+ }, {
185
+ when: answers => answers.Transport === 'smtp',
186
+ type: 'input',
187
+ name: 'SmtpPass',
188
+ message: 'SMTP password?',
189
+ default: '',
190
+ store: true
191
+ }, {
192
+ when: answers => answers.Transport === 'smtp',
193
+ type: 'input',
194
+ name: 'SmtpEmail',
195
+ message: 'Sender email?',
196
+ default: '',
197
+ store: true
198
+ }, {
199
+ when: answers => answers.Transport === 'smtp',
200
+ type: 'input',
201
+ name: 'SmtpName',
202
+ message: 'Sender name?',
203
+ default: '',
204
+ store: true
205
+ }, {
206
+ type: 'select',
207
+ name: 'English',
208
+ message: 'Activate English language in TYPO3?',
209
+ choices: [{
210
+ name: 'No',
211
+ value: false
194
212
  }, {
195
- type: 'input',
196
- name: 'Email',
197
- message: 'Author eMail',
198
- default: 'john@doe.com',
199
- store: true
213
+ name: 'Yes',
214
+ value: true
215
+ }],
216
+ store: true
217
+ }, {
218
+ type: 'select',
219
+ name: 'EnglishDefault',
220
+ message: 'Set English as default language?',
221
+ choices: [{
222
+ name: 'No',
223
+ value: false
200
224
  }, {
201
- type: 'input',
202
- name: 'Website',
203
- message: 'Author website',
204
- default: 'www.johndoe.com',
205
- store: true
225
+ name: 'Yes',
226
+ value: true
227
+ }],
228
+ store: true
229
+ }, {
230
+ type: 'input',
231
+ name: 'Author',
232
+ message: 'Author name',
233
+ default: 'John Doe',
234
+ store: true
235
+ }, {
236
+ type: 'input',
237
+ name: 'Email',
238
+ message: 'Author eMail',
239
+ default: 'john@doe.com',
240
+ store: true
241
+ }, {
242
+ type: 'input',
243
+ name: 'Website',
244
+ message: 'Author website',
245
+ default: 'www.johndoe.com',
246
+ store: true
247
+ }, {
248
+ type: 'select',
249
+ name: 'Copyright',
250
+ message: 'Add copyright?',
251
+ choices: [{
252
+ name: 'No',
253
+ value: false
206
254
  }, {
207
- type: 'list',
208
- name: 'Copyright',
209
- message: 'Add copyright?',
210
- choices: [{
211
- name: 'No',
212
- value: false
213
- }, {
214
- name: 'Gandayo',
215
- value: true
216
- }],
217
- store: true
255
+ name: 'Gandayo',
256
+ value: true
257
+ }],
258
+ store: true
259
+ }, {
260
+ type: 'select',
261
+ name: 'Htaccess',
262
+ message: 'Add .htaccess-dev file for development?',
263
+ choices: [{
264
+ name: 'Yes',
265
+ value: true
218
266
  }, {
219
- type: 'list',
220
- name: 'Htaccess',
221
- message: 'Add .htaccess-dev file for development?',
222
- choices: [{
223
- name: 'Yes',
224
- value: true
225
- }, {
226
- name: 'No',
227
- value: false
228
- }],
229
- store: true
267
+ name: 'No',
268
+ value: false
269
+ }],
270
+ store: true
271
+ }, {
272
+ type: 'select',
273
+ name: 'FontAwesome',
274
+ message: 'FontAwesome Pro?',
275
+ choices: [{
276
+ name: 'Yes',
277
+ value: true
230
278
  }, {
231
- type: 'list',
232
- name: 'FontAwesome',
233
- message: 'FontAwesome Pro?',
234
- choices: [{
235
- name: 'Yes',
236
- value: true
237
- }, {
238
- name: 'No',
239
- value: false
240
- }],
241
- store: true
279
+ name: 'No',
280
+ value: false
281
+ }],
282
+ store: true
283
+ }, {
284
+ type: 'select',
285
+ name: 'Search',
286
+ message: 'Activate search?',
287
+ choices: [{
288
+ name: 'No',
289
+ value: false
242
290
  }, {
243
- type: 'list',
244
- name: 'Search',
245
- message: 'Activate search?',
246
- choices: [{
247
- name: 'No',
248
- value: false
249
- }, {
250
- name: 'Yes',
251
- value: true
252
- }]
291
+ name: 'Yes',
292
+ value: true
293
+ }]
294
+ }, {
295
+ type: 'select',
296
+ name: 'SSL',
297
+ message: 'Activate SSL/https for dev?',
298
+ choices: [{
299
+ name: 'Yes',
300
+ value: true
253
301
  }, {
254
- type: 'list',
255
- name: 'SSL',
256
- message: 'Activate SSL/https for dev?',
257
- choices: [{
258
- name: 'Yes',
259
- value: true
260
- }, {
261
- name: 'No',
262
- value: false
263
- }],
264
- store: true
302
+ name: 'No',
303
+ value: false
304
+ }],
305
+ store: true
306
+ }, {
307
+ type: 'select',
308
+ name: 'Cols',
309
+ message: 'Bootstrap columns?',
310
+ choices: [{
311
+ name: '24',
312
+ value: 24
265
313
  }, {
266
- type: 'list',
267
- name: 'Cols',
268
- message: 'Bootstrap columns?',
269
- choices: [{
270
- name: '24',
271
- value: 24
272
- }, {
273
- name: '12',
274
- value: 12
275
- }],
276
- store: true
277
- }]
314
+ name: '12',
315
+ value: 12
316
+ }],
317
+ store: true
318
+ }]
278
319
 
279
- return t.prompt(prompts).then(answers => {
280
- t.props = answers
281
- done()
282
- })
283
- })
320
+ this.props = await this.prompt(prompts)
284
321
  }
285
322
 
286
- writing () {
287
- const t = this
288
- rzr = this.props
289
- const srcPath = rzr.SrcPath + '/typo3_src-' + rzr.Version
290
-
291
- // Version
292
- let version = '124'
293
- if (rzr.Version.indexOf('13.4') !== -1) {
294
- version = '134'
295
- } else if (rzr.Version.indexOf('14.3') !== -1) {
296
- version = '143'
297
- }
323
+ async writing () {
324
+ const templateVersion = this._getTemplateVersion()
298
325
 
299
- this._createSymlinks(this, srcPath, () => {
300
- const destination = t.destinationPath('./')
326
+ const sourcePath = path.resolve(
327
+ this.destinationRoot(),
328
+ this.props.SrcPath,
329
+ `typo3_src-${this.props.Version}`
330
+ )
301
331
 
302
- copydir(t.templatePath(version), destination, () => {
303
- t._localconf(t)
304
- t._localSettings(t)
332
+ await this._ensureTypo3Source(sourcePath)
333
+ await this._createSymlinks(sourcePath)
305
334
 
306
- const writableDirectories = [
307
- 'fileadmin',
308
- 'typo3temp',
309
- 'typo3conf'
310
- ]
311
-
312
- writableDirectories.forEach((directory) => {
313
- t.chmodDirectoriesRecursive(
314
- path.join(destination, directory)
315
- )
316
- })
335
+ await fs.copy(
336
+ this.templatePath(templateVersion),
337
+ this.destinationPath(),
338
+ {
339
+ overwrite: true,
340
+ errorOnExist: false
341
+ }
342
+ )
317
343
 
318
- t._createDb((response) => {
319
- t._processSqlFile(t, response, () => {
320
- t._setRazorConfig()
321
- })
322
- })
323
- })
324
- })
344
+ await this._writeSystemSettings()
345
+ await this._writeLocalSettings()
346
+ await this._chmodWritableDirectories()
347
+ await this._createDatabaseAndImportSql()
348
+ await this._setRazorConfig()
325
349
  }
326
350
 
327
- chmodDirectoriesRecursive (directory) {
328
- if (!fs.existsSync(directory)) {
329
- return
330
- }
331
-
332
- fs.chmodSync(directory, 0o2775)
351
+ async install () {
352
+ const branch = this._getRazorBranch()
353
+ const packageName = `ssh://git@github.com/rafu1987/razor.git#${branch}`
354
+
355
+ await this._runCommand('yarn', [
356
+ 'add',
357
+ '--dev',
358
+ '--no-lockfile',
359
+ '--modules-folder',
360
+ 'typo3conf/ext/',
361
+ packageName
362
+ ])
363
+ }
333
364
 
334
- fs.readdirSync(directory, { withFileTypes: true }).forEach((entry) => {
335
- if (entry.isDirectory()) {
336
- this.chmodDirectoriesRecursive(
337
- path.join(directory, entry.name)
365
+ async end () {
366
+ await fs.remove(
367
+ this.destinationPath('package.json')
368
+ )
369
+
370
+ await fs.remove(
371
+ this.destinationPath('typo3conf/ext/.yarn-integrity')
372
+ )
373
+
374
+ if (this._usesModernTypo3Structure()) {
375
+ const extensionsSource = this.destinationPath(
376
+ 'typo3conf/ext/razor/Initialisation/Extensions'
377
+ )
378
+
379
+ if (await fs.pathExists(extensionsSource)) {
380
+ await fs.copy(
381
+ extensionsSource,
382
+ this.destinationPath('typo3conf/ext'),
383
+ {
384
+ overwrite: true,
385
+ errorOnExist: false
386
+ }
338
387
  )
339
388
  }
340
- })
389
+ }
341
390
  }
342
391
 
343
- install () {
344
- rzr = this.props
392
+ async _getTypo3Releases () {
393
+ const url = 'https://get.typo3.org/json'
394
+
395
+ let response
345
396
 
346
- // Branch
347
- let branch = 'razor12-dev'
348
- if (rzr.Version.indexOf('13.4') !== -1) {
349
- branch = 'razor13-dev'
350
- } else if (rzr.Version.indexOf('14.3') !== -1) {
351
- branch = 'razor14-dev'
397
+ try {
398
+ response = await fetch(url, {
399
+ headers: {
400
+ accept: 'application/json',
401
+ 'user-agent': 'generator-razor'
402
+ },
403
+ redirect: 'follow',
404
+ signal: AbortSignal.timeout(30000)
405
+ })
406
+ } catch (error) {
407
+ const cause = error.cause
408
+ ? ` ${error.cause.code ?? ''}: ${error.cause.message ?? error.cause}`
409
+ : ''
410
+
411
+ throw new Error(
412
+ `Could not connect to ${url}.${cause}`,
413
+ {
414
+ cause: error
415
+ }
416
+ )
352
417
  }
353
418
 
354
- // yarn settings
355
- const yarnSettings = { dev: true, 'no-lockfile': true, 'modules-folder': 'typo3conf/ext/' }
419
+ if (!response.ok) {
420
+ throw new Error(
421
+ 'Could not retrieve TYPO3 releases: ' +
422
+ `${response.status} ${response.statusText}`
423
+ )
424
+ }
356
425
 
357
- // Install
358
- this.yarnInstall([
359
- 'ssh://git@github.com/rafu1987/razor.git#' + branch
360
- ], yarnSettings)
361
- }
426
+ let data
427
+
428
+ try {
429
+ data = await response.json()
430
+ } catch (error) {
431
+ throw new Error(
432
+ `The TYPO3 release API returned invalid JSON from ${response.url}.`,
433
+ {
434
+ cause: error
435
+ }
436
+ )
437
+ }
362
438
 
363
- end () {
364
- // Delete package.json and .yarn-integrity files when finished
365
- fs.unlink('package.json', () => {})
366
- fs.unlink('typo3conf/ext/.yarn-integrity', () => {})
439
+ const releases = [
440
+ ...Object.keys(data['14']?.releases ?? {}),
441
+ ...Object.keys(data['13']?.releases ?? {}),
442
+ ...Object.keys(data['12']?.releases ?? {})
443
+ ]
444
+
445
+ const supportedVersions = [...new Set(releases)]
446
+ .filter(version => {
447
+ return version.startsWith('12.4.') ||
448
+ version.startsWith('13.4.') ||
449
+ version.startsWith('14.3.')
450
+ })
451
+ .sort((a, b) => {
452
+ return b.localeCompare(a, undefined, {
453
+ numeric: true,
454
+ sensitivity: 'base'
455
+ })
456
+ })
367
457
 
368
- // Copy razor extensions after install to typo3conf/ext/, starting with TYPO3 >= 12.4.x
369
- if (rzr.Version.indexOf('12.4') !== -1 || rzr.Version.indexOf('13.4') !== -1 || rzr.Version.indexOf('14.3') !== -1) {
370
- fs.copy('typo3conf/ext/razor/Initialisation/Extensions', 'typo3conf/ext')
458
+ if (supportedVersions.length === 0) {
459
+ throw new Error(
460
+ 'The TYPO3 release API returned no supported releases.'
461
+ )
371
462
  }
463
+
464
+ return supportedVersions.map(version => ({
465
+ name: version,
466
+ value: version
467
+ }))
372
468
  }
373
469
 
374
- _getSrc (t, url, callback) {
375
- // Get TYPO3 source from JSON
376
- request({
377
- url: url,
378
- json: true
379
- }, (error, response, body) => {
380
- if (!error && response.statusCode === 200) {
381
- const releases12 = body['12']['releases']
382
- const releases13 = body['13']['releases']
383
- const releases14 = body['14']['releases']
384
-
385
- const releasesObj = t._mergeOptions(releases14, releases13, releases12)
386
-
387
- const keys = Object.keys(releasesObj)
388
- const len = keys.length
389
- const arr = []
390
-
391
- // Filter out only 12.4.x 13.4.x, 14.3.x
392
- for (let i = 0; i < len; i++) {
393
- if (keys[i].indexOf('12.4.') !== -1 || keys[i].indexOf('13.4.') !== -1 || keys[i].indexOf('14.3.') !== -1) {
394
- arr.push({
395
- name: keys[i],
396
- value: keys[i]
397
- })
398
- }
399
- }
470
+ _getTemplateVersion () {
471
+ if (this.props.Version.startsWith('14.3.')) {
472
+ return '143'
473
+ }
400
474
 
401
- return callback(arr)
402
- }
403
- })
475
+ if (this.props.Version.startsWith('13.4.')) {
476
+ return '134'
477
+ }
478
+
479
+ if (this.props.Version.startsWith('12.4.')) {
480
+ return '124'
481
+ }
482
+
483
+ throw new Error(
484
+ `Unsupported TYPO3 version: ${this.props.Version}`
485
+ )
404
486
  }
405
487
 
406
- _mergeOptions (obj1, obj2, obj3) {
407
- const obj4 = {}
488
+ _getRazorBranch () {
489
+ if (this.props.Version.startsWith('14.3.')) {
490
+ return 'razor14-dev'
491
+ }
408
492
 
409
- for (let attrname in obj1) { obj4[attrname] = obj1[attrname] }
410
- for (let attrname in obj2) { obj4[attrname] = obj2[attrname] }
411
- for (let attrname in obj3) { obj4[attrname] = obj3[attrname] }
493
+ if (this.props.Version.startsWith('13.4.')) {
494
+ return 'razor13-dev'
495
+ }
412
496
 
413
- return obj4
497
+ if (this.props.Version.startsWith('12.4.')) {
498
+ return 'razor12-dev'
499
+ }
500
+
501
+ throw new Error(
502
+ `No Razor branch configured for TYPO3 ${this.props.Version}`
503
+ )
414
504
  }
415
505
 
416
- _createSymlinks (t, path, callback) {
417
- // Check if TYPO3 source is available
418
- if (pathExists.sync(path) === false) {
419
- remote.extract('https://get.typo3.org/' + rzr.Version, rzr.SrcPath, () => {})
506
+ _usesModernTypo3Structure () {
507
+ return this.props.Version.startsWith('12.4.') ||
508
+ this.props.Version.startsWith('13.4.') ||
509
+ this.props.Version.startsWith('14.3.')
510
+ }
511
+
512
+ async _ensureTypo3Source (sourcePath) {
513
+ if (await fs.pathExists(sourcePath)) {
514
+ this.log(
515
+ `Using existing TYPO3 source: ${sourcePath}`
516
+ )
517
+
518
+ return
420
519
  }
421
520
 
422
- // Symlinks
423
- link(path, 'typo3_src')
424
- link('typo3_src/typo3', 'typo3')
425
- link('typo3_src/index.php', 'index.php')
521
+ const sourceDirectory = path.dirname(sourcePath)
426
522
 
427
- return callback()
428
- }
523
+ await fs.ensureDir(sourceDirectory)
524
+
525
+ this.log(
526
+ `Downloading TYPO3 ${this.props.Version} to ` +
527
+ `${sourceDirectory}...`
528
+ )
429
529
 
430
- _localconf (t) {
431
- fs.readFile('typo3conf/system/settings.php', 'utf8', (err, content) => {
432
- let newContent = t._substituteMarker(content, '###DBNEW###', rzr.DbNew.toLowerCase(), true)
433
- newContent = t._substituteMarker(newContent, '###HOST###', rzr.DbHostname, true)
434
- newContent = t._substituteMarker(newContent, '###PROJECTNAME###', rzr.ProjectName, true)
530
+ const temporaryDirectory = await fs.mkdtemp(
531
+ path.join(os.tmpdir(), 'generator-razor-')
532
+ )
435
533
 
436
- const encryptionKey = crypto.randomBytes((96 + 1) / 2).toString('hex')
437
- newContent = t._substituteMarker(newContent, '###ENCRYPTION_KEY###', encryptionKey, true)
534
+ const archivePath = path.join(
535
+ temporaryDirectory,
536
+ `typo3_src-${this.props.Version}.tar.gz`
537
+ )
438
538
 
439
- const hash = argon2.hash(rzr.Pass)
440
- hash.then(function (res) {
441
- newContent = t._substituteMarker(newContent, '###PASS###', res, true)
539
+ try {
540
+ await this._downloadFile(
541
+ `https://get.typo3.org/${this.props.Version}`,
542
+ archivePath
543
+ )
442
544
 
443
- t._localconfWrite(newContent)
545
+ await tar.x({
546
+ file: archivePath,
547
+ cwd: sourceDirectory,
548
+ strict: true
444
549
  })
550
+ } finally {
551
+ await fs.remove(temporaryDirectory)
552
+ }
445
553
 
446
- if (err) {
447
- console.error('error setting settings.php')
448
- }
449
- })
554
+ if (!await fs.pathExists(sourcePath)) {
555
+ throw new Error(
556
+ 'TYPO3 archive was extracted, but the expected directory ' +
557
+ `was not found: ${sourcePath}`
558
+ )
559
+ }
450
560
  }
451
561
 
452
- _localconfWrite (content) {
453
- fs.writeFile('typo3conf/system/settings.php', content, 'utf8', () => {})
562
+ async _downloadFile (url, destination) {
563
+ let response
564
+
565
+ try {
566
+ response = await fetch(url, {
567
+ headers: {
568
+ accept: 'application/gzip, application/octet-stream',
569
+ 'user-agent': 'generator-razor'
570
+ },
571
+ redirect: 'follow',
572
+ signal: AbortSignal.timeout(120000)
573
+ })
574
+ } catch (error) {
575
+ const cause = error.cause
576
+ ? ` ${error.cause.code ?? ''}: ${error.cause.message ?? error.cause}`
577
+ : ''
578
+
579
+ throw new Error(
580
+ `Could not connect to ${url}.${cause}`,
581
+ {
582
+ cause: error
583
+ }
584
+ )
585
+ }
586
+
587
+ if (!response.ok) {
588
+ throw new Error(
589
+ `Could not download ${url}: ` +
590
+ `${response.status} ${response.statusText}`
591
+ )
592
+ }
593
+
594
+ if (!response.body) {
595
+ throw new Error(
596
+ `The download response for ${url} had no body.`
597
+ )
598
+ }
599
+
600
+ await fs.ensureDir(
601
+ path.dirname(destination)
602
+ )
603
+
604
+ const fileStream = fs.createWriteStream(
605
+ destination
606
+ )
607
+
608
+ const responseStream = Readable.fromWeb(
609
+ response.body
610
+ )
611
+
612
+ await pipeline(
613
+ responseStream,
614
+ fileStream
615
+ )
454
616
  }
455
617
 
456
- _localSettings (t) {
457
- if (rzr.Transport === 'smtp') {
458
- let encryptVariable = '###SMTP_ENCRYPT###'
459
- if (rzr.Encrypt === true || rzr.Encrypt === false) {
460
- encryptVariable = "'###SMTP_ENCRYPT###'"
618
+ async _createSymlinks (sourcePath) {
619
+ const links = [{
620
+ source: sourcePath,
621
+ destination: this.destinationPath('typo3_src'),
622
+ type: 'dir'
623
+ }, {
624
+ source: path.join(sourcePath, 'typo3'),
625
+ destination: this.destinationPath('typo3'),
626
+ type: 'dir'
627
+ }, {
628
+ source: path.join(sourcePath, 'index.php'),
629
+ destination: this.destinationPath('index.php'),
630
+ type: 'file'
631
+ }]
632
+
633
+ for (const link of links) {
634
+ if (!await fs.pathExists(link.source)) {
635
+ throw new Error(
636
+ 'Cannot create symlink because the source does not exist: ' +
637
+ link.source
638
+ )
461
639
  }
462
640
 
463
- fs.readFile('typo3conf/system/local.php', 'utf8', (err, content) => {
464
- let newContent = t._substituteMarker(content, '###TRANSPORT###', rzr.Transport, true)
465
- newContent = t._substituteMarker(newContent, encryptVariable, rzr.Encrypt, true)
466
- newContent = t._substituteMarker(newContent, '###SMTP_PASS###', rzr.SmtpPass, true)
467
- newContent = t._substituteMarker(newContent, '###SMTP_SERVER###', rzr.SmtpServer, true)
468
- newContent = t._substituteMarker(newContent, '###SMTP_USER###', rzr.SmtpUser, true)
469
- newContent = t._substituteMarker(newContent, '###SMTP_EMAIL###', rzr.SmtpEmail, true)
470
- newContent = t._substituteMarker(newContent, '###SMTP_NAME###', rzr.SmtpName, true)
471
-
472
- fs.writeFile('typo3conf/system/local.php', newContent, 'utf8', () => {})
641
+ await fs.remove(link.destination)
473
642
 
474
- if (err) {
475
- console.error('error setting local settings')
476
- }
477
- })
478
- } else {
479
- fs.unlink('typo3conf/system/local.php', () => {})
643
+ await fs.ensureSymlink(
644
+ link.source,
645
+ link.destination,
646
+ link.type
647
+ )
480
648
  }
481
649
  }
482
650
 
483
- _createDb (callback) {
484
- const charset = 'utf8mb4'
485
- const collate = 'utf8mb4_unicode_ci'
651
+ async _writeSystemSettings () {
652
+ const settingsPath = this.destinationPath(
653
+ 'typo3conf/system/settings.php'
654
+ )
655
+
656
+ let content = await fs.readFile(
657
+ settingsPath,
658
+ 'utf8'
659
+ )
660
+
661
+ content = this._substituteMarker(
662
+ content,
663
+ '###DBNEW###',
664
+ this.props.DbNew.toLowerCase()
665
+ )
666
+
667
+ content = this._substituteMarker(
668
+ content,
669
+ '###HOST###',
670
+ this.props.DbHostname
671
+ )
672
+
673
+ content = this._substituteMarker(
674
+ content,
675
+ '###PROJECTNAME###',
676
+ this.props.ProjectName
677
+ )
678
+
679
+ const encryptionKey = crypto
680
+ .randomBytes(48)
681
+ .toString('hex')
682
+
683
+ content = this._substituteMarker(
684
+ content,
685
+ '###ENCRYPTION_KEY###',
686
+ encryptionKey
687
+ )
688
+
689
+ const passwordHash = await argon2.hash(
690
+ this.props.Pass
691
+ )
692
+
693
+ content = this._substituteMarker(
694
+ content,
695
+ '###PASS###',
696
+ passwordHash
697
+ )
698
+
699
+ await fs.writeFile(
700
+ settingsPath,
701
+ content,
702
+ 'utf8'
703
+ )
704
+ }
486
705
 
487
- // Connect to database
488
- const connection = mysql.createConnection({
489
- host: rzr.DbHostname,
490
- user: rzr.DbUsername,
491
- password: rzr.DbPassword,
492
- socketPath: rzr.DbSocket,
493
- multipleStatements: true
494
- })
706
+ async _writeLocalSettings () {
707
+ const localSettingsPath = this.destinationPath(
708
+ 'typo3conf/system/local.php'
709
+ )
495
710
 
496
- connection.connect((err) => {
497
- if (err) {
498
- console.error('error connecting')
499
- }
500
- })
711
+ if (this.props.Transport !== 'smtp') {
712
+ await fs.remove(localSettingsPath)
713
+ return
714
+ }
501
715
 
502
- const dbNew = rzr.DbNew.toLowerCase()
716
+ let content = await fs.readFile(
717
+ localSettingsPath,
718
+ 'utf8'
719
+ )
503
720
 
504
- // Create database table and user
505
- connection.query('CREATE DATABASE `' + dbNew + '` CHARACTER SET ' + charset + ' COLLATE ' + collate + ';')
506
- connection.query('CREATE USER "' + dbNew + '"@"%" IDENTIFIED BY "' + dbNew + '";')
507
- connection.query('GRANT ALL PRIVILEGES ON `' + dbNew + '`.* TO "' + dbNew + '"@"%";')
721
+ let encryptionMarker = '###SMTP_ENCRYPT###'
722
+
723
+ if (
724
+ this.props.Encrypt === true ||
725
+ this.props.Encrypt === false
726
+ ) {
727
+ encryptionMarker = "'###SMTP_ENCRYPT###'"
728
+ }
508
729
 
509
- // Connect to new db
510
- connection.query('USE `' + dbNew + '`;')
730
+ const replacements = [
731
+ ['###TRANSPORT###', this.props.Transport],
732
+ [encryptionMarker, this.props.Encrypt],
733
+ ['###SMTP_PASS###', this.props.SmtpPass ?? ''],
734
+ ['###SMTP_SERVER###', this.props.SmtpServer ?? ''],
735
+ ['###SMTP_USER###', this.props.SmtpUser ?? ''],
736
+ ['###SMTP_EMAIL###', this.props.SmtpEmail ?? ''],
737
+ ['###SMTP_NAME###', this.props.SmtpName ?? '']
738
+ ]
739
+
740
+ for (const [marker, value] of replacements) {
741
+ content = this._substituteMarker(
742
+ content,
743
+ marker,
744
+ value
745
+ )
746
+ }
511
747
 
512
- return callback(connection)
748
+ await fs.writeFile(
749
+ localSettingsPath,
750
+ content,
751
+ 'utf8'
752
+ )
513
753
  }
514
754
 
515
- _processSqlFile (t, connection, callback) {
516
- // Read sql file
517
- fs.readFile('./db.sql', 'utf8', (err, data) => {
518
- if (err) {
519
- console.error(err)
520
- }
755
+ async _chmodWritableDirectories () {
756
+ const writableDirectories = [
757
+ 'fileadmin',
758
+ 'typo3temp',
759
+ 'typo3conf'
760
+ ]
761
+
762
+ for (const directory of writableDirectories) {
763
+ await this._chmodDirectoriesRecursive(
764
+ this.destinationPath(directory)
765
+ )
766
+ }
767
+ }
521
768
 
522
- let result = t._substituteMarker(data, '###ADMIN###', rzr.User, false)
523
- const hash = argon2.hash(rzr.Pass)
524
- hash.then(function (res) {
525
- result = t._substituteMarker(result, '###PASS###', res, false)
769
+ async _chmodDirectoriesRecursive (directory) {
770
+ if (!await fs.pathExists(directory)) {
771
+ return
772
+ }
526
773
 
527
- t._sqlWrite(t, result, connection, callback)
528
- })
529
- })
530
- }
774
+ await fs.chmod(
775
+ directory,
776
+ 0o2775
777
+ )
531
778
 
532
- _sqlWrite (t, result, connection, callback) {
533
- // Write file
534
- fs.writeFile('db.sql', result, 'utf8', (err) => {
535
- if (err) {
536
- console.error(err)
779
+ const entries = await fs.readdir(
780
+ directory,
781
+ {
782
+ withFileTypes: true
537
783
  }
784
+ )
538
785
 
539
- // Read file again with changes
540
- fs.readFile('./db.sql', 'utf8', (err, data) => {
541
- // Import sql file
542
- connection.query(data, () => {
543
- connection.end()
786
+ for (const entry of entries) {
787
+ if (entry.isDirectory()) {
788
+ await this._chmodDirectoriesRecursive(
789
+ path.join(directory, entry.name)
790
+ )
791
+ }
792
+ }
793
+ }
544
794
 
545
- // Delete db.sql file after import
546
- fs.unlink('db.sql', () => {})
795
+ async _createDatabaseAndImportSql () {
796
+ const databaseName = this.props.DbNew.toLowerCase()
547
797
 
548
- return callback()
549
- })
798
+ const connectionOptions = {
799
+ host: this.props.DbHostname,
800
+ user: this.props.DbUsername,
801
+ password: this.props.DbPassword,
802
+ multipleStatements: true
803
+ }
550
804
 
551
- if (err) {
552
- console.error(err)
553
- }
554
- })
555
- })
556
- }
805
+ if (this.props.DbPort) {
806
+ connectionOptions.port = Number(this.props.DbPort)
807
+ }
557
808
 
558
- _substituteMarker (content, marker, newContent, toString) {
559
- const regEx = new RegExp(marker, 'g')
809
+ if (this.props.DbSocket) {
810
+ connectionOptions.socketPath = this.props.DbSocket
811
+ }
560
812
 
561
- if (toString) {
562
- return content.toString().replace(regEx, newContent)
563
- } else {
564
- return content.replace(regEx, newContent)
813
+ const connection = await mysql.createConnection(
814
+ connectionOptions
815
+ )
816
+
817
+ try {
818
+ const escapedDatabase = connection.escapeId(
819
+ databaseName
820
+ )
821
+
822
+ const escapedUsername = connection.escape(
823
+ databaseName
824
+ )
825
+
826
+ const escapedPassword = connection.escape(
827
+ databaseName
828
+ )
829
+
830
+ await connection.query(
831
+ `CREATE DATABASE ${escapedDatabase} ` +
832
+ 'CHARACTER SET utf8mb4 ' +
833
+ 'COLLATE utf8mb4_unicode_ci'
834
+ )
835
+
836
+ await connection.query(
837
+ `CREATE USER ${escapedUsername}@'%' ` +
838
+ `IDENTIFIED BY ${escapedPassword}`
839
+ )
840
+
841
+ await connection.query(
842
+ `GRANT ALL PRIVILEGES ON ${escapedDatabase}.* ` +
843
+ `TO ${escapedUsername}@'%'`
844
+ )
845
+
846
+ await connection.query(
847
+ `USE ${escapedDatabase}`
848
+ )
849
+
850
+ const sqlPath = this.destinationPath(
851
+ 'db.sql'
852
+ )
853
+
854
+ let sql = await fs.readFile(
855
+ sqlPath,
856
+ 'utf8'
857
+ )
858
+
859
+ sql = this._substituteMarker(
860
+ sql,
861
+ '###ADMIN###',
862
+ this.props.User
863
+ )
864
+
865
+ const passwordHash = await argon2.hash(
866
+ this.props.Pass
867
+ )
868
+
869
+ sql = this._substituteMarker(
870
+ sql,
871
+ '###PASS###',
872
+ passwordHash
873
+ )
874
+
875
+ await connection.query(sql)
876
+
877
+ await fs.remove(sqlPath)
878
+ } finally {
879
+ await connection.end()
565
880
  }
566
881
  }
567
882
 
568
- _setRazorConfig () {
569
- const obj = {
570
- siteName: rzr.ProjectName,
571
- user: rzr.User,
572
- adminEmail: rzr.AdminEmail,
573
- english: rzr.English,
574
- englishDefault: rzr.EnglishDefault,
575
- author: rzr.Author,
576
- email: rzr.Email,
577
- website: rzr.Website,
578
- copyright: rzr.Copyright,
579
- fontawesome: rzr.FontAwesome,
580
- cols: rzr.Cols,
581
- htaccess: rzr.Htaccess,
582
- smtpemail: rzr.SmtpEmail,
583
- search: rzr.Search,
584
- ssl: rzr.SSL
883
+ _substituteMarker (content, marker, replacement) {
884
+ return String(content)
885
+ .split(marker)
886
+ .join(String(replacement))
887
+ }
888
+
889
+ async _setRazorConfig () {
890
+ const config = {
891
+ siteName: this.props.ProjectName,
892
+ user: this.props.User,
893
+ adminEmail: this.props.AdminEmail,
894
+ english: this.props.English,
895
+ englishDefault: this.props.EnglishDefault,
896
+ author: this.props.Author,
897
+ email: this.props.Email,
898
+ website: this.props.Website,
899
+ copyright: this.props.Copyright,
900
+ fontawesome: this.props.FontAwesome,
901
+ cols: this.props.Cols,
902
+ htaccess: this.props.Htaccess,
903
+ smtpemail: this.props.SmtpEmail ?? '',
904
+ search: this.props.Search,
905
+ ssl: this.props.SSL
585
906
  }
586
907
 
587
- // Rename or delete?
588
- if (rzr.Htaccess) {
589
- if (rzr.SSL) {
590
- fs.rename('_.htaccess-dev-ssl', '.htaccess-dev', () => {})
591
- fs.unlink('_.htaccess-dev', () => {})
592
- } else {
593
- fs.rename('_.htaccess-dev', '.htaccess-dev', () => {})
594
- fs.unlink('_.htaccess-dev-ssl', () => {})
595
- }
908
+ const plainHtaccess = this.destinationPath(
909
+ '_.htaccess-dev'
910
+ )
911
+
912
+ const sslHtaccess = this.destinationPath(
913
+ '_.htaccess-dev-ssl'
914
+ )
915
+
916
+ const targetHtaccess = this.destinationPath(
917
+ '.htaccess-dev'
918
+ )
919
+
920
+ if (!this.props.Htaccess) {
921
+ await fs.remove(plainHtaccess)
922
+ await fs.remove(sslHtaccess)
923
+ await fs.remove(targetHtaccess)
924
+ } else if (this.props.SSL) {
925
+ await fs.move(
926
+ sslHtaccess,
927
+ targetHtaccess,
928
+ {
929
+ overwrite: true
930
+ }
931
+ )
932
+
933
+ await fs.remove(plainHtaccess)
596
934
  } else {
597
- fs.unlink('_.htaccess-dev', () => {})
598
- fs.unlink('_.htaccess-dev-ssl', () => {})
935
+ await fs.move(
936
+ plainHtaccess,
937
+ targetHtaccess,
938
+ {
939
+ overwrite: true
940
+ }
941
+ )
942
+
943
+ await fs.remove(sslHtaccess)
599
944
  }
600
945
 
601
- fs.writeFile('razor.json', JSON.stringify(obj, null, 2), (err) => {
602
- if (err) {
603
- return console.error(err)
946
+ await fs.writeJson(
947
+ this.destinationPath('razor.json'),
948
+ config,
949
+ {
950
+ spaces: 2
604
951
  }
952
+ )
953
+ }
954
+
955
+ async _runCommand (command, argumentsList) {
956
+ await new Promise((resolve, reject) => {
957
+ const child = spawn(
958
+ command,
959
+ argumentsList,
960
+ {
961
+ cwd: this.destinationRoot(),
962
+ env: process.env,
963
+ stdio: 'inherit'
964
+ }
965
+ )
966
+
967
+ let settled = false
968
+
969
+ child.once('error', error => {
970
+ if (settled) {
971
+ return
972
+ }
973
+
974
+ settled = true
975
+
976
+ if (error.code === 'ENOENT') {
977
+ reject(
978
+ new Error(
979
+ `Could not execute "${command}". ` +
980
+ 'Make sure it is installed and available in PATH.',
981
+ {
982
+ cause: error
983
+ }
984
+ )
985
+ )
986
+
987
+ return
988
+ }
989
+
990
+ reject(error)
991
+ })
992
+
993
+ child.once('close', code => {
994
+ if (settled) {
995
+ return
996
+ }
997
+
998
+ settled = true
999
+
1000
+ if (code === 0) {
1001
+ resolve()
1002
+ return
1003
+ }
1004
+
1005
+ reject(
1006
+ new Error(
1007
+ `"${command}" exited with status code ${code}.`
1008
+ )
1009
+ )
1010
+ })
605
1011
  })
606
1012
  }
607
1013
  }