Skip to content

Commit 3a432f3

Browse files
committed
Replace all to single quota
1 parent b14f221 commit 3a432f3

9 files changed

Lines changed: 87 additions & 87 deletions

File tree

src/bin/app.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/usr/bin/env node
22

3-
import fs from "fs";
4-
import { Command } from "commander";
5-
import path from "path";
6-
import shell from "shelljs";
7-
import { Sequelize } from "sequelize";
8-
import setupBootstrap from "@/bootstraps/setup.bootstrap.js";
9-
import backupBootstrap from "@/bootstraps/backup.bootstrap.js";
10-
import templateBootstrap from "@/bootstraps/template.bootstrap.js";
11-
import repairBootstrap from "@/bootstraps/repair.bootstrap.js";
3+
import fs from 'fs';
4+
import { Command } from 'commander';
5+
import path from 'path';
6+
import shell from 'shelljs';
7+
import { Sequelize } from 'sequelize';
8+
import setupBootstrap from '@/bootstraps/setup.bootstrap.js';
9+
import backupBootstrap from '@/bootstraps/backup.bootstrap.js';
10+
import templateBootstrap from '@/bootstraps/template.bootstrap.js';
11+
import repairBootstrap from '@/bootstraps/repair.bootstrap.js';
1212

1313
const program = new Command();
1414

@@ -110,10 +110,10 @@ program
110110
.action(async (options) => {
111111
const { username, password, directory, accessKeyId, secretAccessKey } = options;
112112
if (!fs.existsSync(directory) || !fs.lstatSync(directory).isDirectory()) {
113-
throw new Error("Root directory not exists.");
113+
throw new Error('Root directory not exists.');
114114
}
115-
if (directory === "/") {
116-
throw new Error("Cannot archive the root directory.");
115+
if (directory === '/') {
116+
throw new Error('Cannot archive the root directory.');
117117
}
118118
await backupBootstrap.handler(directory, username, password, accessKeyId, secretAccessKey);
119119
});

src/bootstraps/backup.bootstrap.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import fs from "fs";
2-
import path from "path";
3-
import { spawn } from "child_process";
4-
import tmp from "tmp";
5-
import archiver from "archiver";
6-
import { format } from "date-fns";
7-
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
8-
import wpHelper from "@/helpers/wp.helper.js";
1+
import fs from 'fs';
2+
import path from 'path';
3+
import { spawn } from 'child_process';
4+
import tmp from 'tmp';
5+
import archiver from 'archiver';
6+
import { format } from 'date-fns';
7+
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3';
8+
import wpHelper from '@/helpers/wp.helper.js';
99

1010
async function backupDatabase(host: string, port: number, user: string, pass: string, database: string, fileStream: fs.WriteStream) {
1111
const mysqldump = spawn('mysqldump', [
@@ -28,7 +28,7 @@ async function backupDatabase(host: string, port: number, user: string, pass: st
2828

2929
export default {
3030
handler: async function(rootDir: string, dbUser: string, dbPass: string, s3accessKeyId: string, s3secretAccessKey: string) {
31-
const wpconfig = fs.readFileSync(path.join(rootDir, "wp-config.php"), 'utf8');
31+
const wpconfig = fs.readFileSync(path.join(rootDir, 'wp-config.php'), 'utf8');
3232
const { database, dbHost, dbPort } = wpHelper.parseWpConfig(wpconfig);
3333
const sqlFile = tmp.fileSync({
3434
mode: 0o600,
@@ -61,7 +61,7 @@ export default {
6161

6262
// archive entire website into archive
6363
archive.directory(rootDir, 'website');
64-
archive.file(archiveFile.name, { name: "dump.sql" });
64+
archive.file(archiveFile.name, { name: 'dump.sql' });
6565

6666
await archive.finalize();
6767

@@ -72,16 +72,16 @@ export default {
7272
},
7373
});
7474

75-
const name = rootDir.endsWith("/") ? rootDir.split("/").slice(-2)[0] : rootDir.split("/").pop();
75+
const name = rootDir.endsWith('/') ? rootDir.split('/').slice(-2)[0] : rootDir.split('/').pop();
7676

7777
const command = new PutObjectCommand({
78-
Bucket: "amus-dev-wp-backup",
79-
Key: `${name}/backup-${format(new Date(), "yyyyMMddHHmmss")}`,
78+
Bucket: 'amus-dev-wp-backup',
79+
Key: `${name}/backup-${format(new Date(), 'yyyyMMddHHmmss')}`,
8080
Body: fs.createReadStream(archiveFile.name),
8181
});
8282

8383
await client.send(command);
8484

85-
console.log("Finished to backup the website.");
85+
console.log('Finished to backup the website.');
8686
}
8787
}

src/bootstraps/repair.bootstrap.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import shell from 'shelljs';
2-
import installService from "@/services/install.service.js";
3-
import { MySQLCredential } from "@/types/common";
2+
import installService from '@/services/install.service.js';
3+
import { MySQLCredential } from '@/types/common';
44

55
export default {
66
handler: async function (directory: string, domain: string, database: MySQLCredential) {
77
const { php } = await installService.configSetup(
88
directory,
99
domain,
10-
domain.replaceAll(/\.|-/g, "_"),
10+
domain.replaceAll(/\.|-/g, '_'),
1111
database
1212
);
1313

src/bootstraps/setup.bootstrap.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
import fs from "fs";
2-
import path from "path";
3-
import { rimrafSync } from "rimraf";
4-
import shell from "shelljs";
5-
import downloadService from "@/services/download.service.js";
6-
import extractService from "@/services/extract.service.js";
7-
import installService from "@/services/install.service.js";
8-
import { MySQLCredential, WPTemplate } from "@/types/common";
1+
import fs from 'fs';
2+
import path from 'path';
3+
import { rimrafSync } from 'rimraf';
4+
import shell from 'shelljs';
5+
import downloadService from '@/services/download.service.js';
6+
import extractService from '@/services/extract.service.js';
7+
import installService from '@/services/install.service.js';
8+
import { MySQLCredential, WPTemplate } from '@/types/common';
99

1010
function getWpCoreUrl(code: string) {
11-
if (code === "latest") {
11+
if (code === 'latest') {
1212
return `https://wordpress.org/${code}.zip`;
1313
}
1414
return `https://wordpress.org/wordpress-${code}.zip`;
1515
}
1616

17-
function getWpThemeUrl(id: string, version = "latest") {
18-
if (version === "latest") {
17+
function getWpThemeUrl(id: string, version = 'latest') {
18+
if (version === 'latest') {
1919
return `https://downloads.wordpress.org/theme/${id}.zip`;
2020
}
2121
return `https://downloads.wordpress.org/theme/${id}.${version}.zip`;
2222
}
2323

24-
function getWpPluginUrl(id: string, version = "latest") {
25-
if (version === "latest") {
24+
function getWpPluginUrl(id: string, version = 'latest') {
25+
if (version === 'latest') {
2626
return `https://downloads.wordpress.org/plugin/${id}.zip`;
2727
}
2828
return `https://downloads.wordpress.org/plugin/${id}.${version}.zip`;
@@ -32,12 +32,12 @@ export default {
3232
handler: async function (directory: string, template: WPTemplate, isDev: boolean, database: MySQLCredential) {
3333
const distDir = `${directory}/${template.domain}`;
3434

35-
console.log("Downloading Wordpress core files...");
35+
console.log('Downloading Wordpress core files...');
3636
const tmpfile = await downloadService.download(getWpCoreUrl(template.version));
3737
await extractService.zip(tmpfile, directory);
3838
fs.renameSync(`${directory}/wordpress`, distDir);
3939

40-
const themeDir = path.join(distDir, "wp-content/themes");
40+
const themeDir = path.join(distDir, 'wp-content/themes');
4141
for (const id in template.themes) {
4242
console.log(`Downloading theme ${id} files...`);
4343
const theme = await downloadService.download(getWpThemeUrl(id, template.themes[id]));
@@ -48,7 +48,7 @@ export default {
4848
await extractService.zip(theme, themeDir);
4949
}
5050

51-
const pluginDir = path.join(distDir, "wp-content/plugins");
51+
const pluginDir = path.join(distDir, 'wp-content/plugins');
5252
for (const id in template.plugins) {
5353
console.log(`Downloading plugin ${id} files...`);
5454
const plugin = await downloadService.download(getWpPluginUrl(id, template.plugins[id]));
@@ -59,7 +59,7 @@ export default {
5959
await extractService.zip(plugin, pluginDir);
6060
}
6161

62-
console.log("Finished to download all files");
62+
console.log('Finished to download all files');
6363

6464
if (isDev) {
6565
// is development mode then skip to modify the os and database
@@ -69,7 +69,7 @@ export default {
6969
const { php } = await installService.configSetup(
7070
distDir,
7171
template.domain,
72-
template.domain.replaceAll(/\.|-/g, "_"),
72+
template.domain.replaceAll(/\.|-/g, '_'),
7373
database
7474
);
7575

src/bootstraps/template.bootstrap.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import inquirer from "inquirer";
2-
import psl from "psl";
1+
import inquirer from 'inquirer';
2+
import psl from 'psl';
33

44
export default {
55
handler: async function() {
6-
const { domain } = await inquirer.prompt({ name: "domain", message: "domain for the website?" });
6+
const { domain } = await inquirer.prompt({ name: 'domain', message: 'domain for the website?' });
77
if (!psl.isValid(domain)) {
8-
throw new Error("domain is not vaild TLD inside public suffix list");
8+
throw new Error('domain is not vaild TLD inside public suffix list');
99
}
10-
const { version } = await inquirer.prompt({ name: "version", message: "version of wordpress?", default: "latest" });
10+
const { version } = await inquirer.prompt({ name: 'version', message: 'version of wordpress?', default: 'latest' });
1111
console.log(JSON.stringify({
1212
domain,
1313
version,
1414
themes: {
15-
twentytwentythree: "latest",
15+
twentytwentythree: 'latest',
1616
},
1717
plugins: {
18-
akismet: "latest",
18+
akismet: 'latest',
1919
},
2020
}, undefined, 4));
2121
}

src/helpers/wp.helper.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { Engine } from "php-parser";
1+
import { Engine } from 'php-parser';
22

33
function parseWpConfig(content: string, options: any = {}) {
44
const engine = new Engine(options);
55
const { children } = engine.parseCode(content, '');
6-
let database, dbHost = "localhost", dbPort = 3306, dbUser;
6+
let database, dbHost = 'localhost', dbPort = 3306, dbUser;
77
for (const child of children as any[]) {
8-
if (child.expression?.what?.name === "define") {
8+
if (child.expression?.what?.name === 'define') {
99
const [ name, value ] = child.expression.arguments;
10-
if (name.kind === "string" && value.kind === "string") {
11-
if (name.value === "DB_NAME") {
10+
if (name.kind === 'string' && value.kind === 'string') {
11+
if (name.value === 'DB_NAME') {
1212
database = value.value as string;
1313
}
14-
if (name.value === "DB_HOST") {
15-
const [ host, port ] = value.value.split(":");
16-
dbHost = host ?? "localhost";
14+
if (name.value === 'DB_HOST') {
15+
const [ host, port ] = value.value.split(':');
16+
dbHost = host ?? 'localhost';
1717
if (port !== undefined) {
1818
dbPort = parseInt(port);
1919
}
2020
}
21-
if (name.value === "DB_USER") {
21+
if (name.value === 'DB_USER') {
2222
dbUser = value.value as string;
2323
}
2424
}

src/services/download.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import fs from "fs";
2-
import axios from "axios";
3-
import tmp from "tmp";
1+
import fs from 'fs';
2+
import axios from 'axios';
3+
import tmp from 'tmp';
44

55
export default {
66
download: async function (url: string) {
@@ -9,7 +9,7 @@ export default {
99
prefix: 'wp-setup-',
1010
});
1111

12-
const response = await axios.get(url, { responseType: "stream" });
12+
const response = await axios.get(url, { responseType: 'stream' });
1313

1414
if (response.status < 200 || response.status >= 300) {
1515
throw new Error(`Download file return unexcepted code (${response.status})`);

src/services/extract.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import extract from "extract-zip";
1+
import extract from 'extract-zip';
22

33
export default {
44
zip: async function (source: string, dist: string) {

src/services/install.service.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import fs from "node:fs";
2-
import path from "node:path";
1+
import fs from 'node:fs';
2+
import path from 'node:path';
33
import shell from 'shelljs';
4-
import inquirer from "inquirer";
5-
import { Sequelize, QueryTypes } from "sequelize";
6-
import wpHelper from "@/helpers/wp.helper.js";
7-
import { MySQLCredential } from "@/types/common.js";
4+
import inquirer from 'inquirer';
5+
import { Sequelize, QueryTypes } from 'sequelize';
6+
import wpHelper from '@/helpers/wp.helper.js';
7+
import { MySQLCredential } from '@/types/common.js';
88

99
function random(length: number, { lower = true, upper = true, numeric = true, symbol = false } = {}) {
1010
let mask = '';
@@ -56,30 +56,30 @@ async function configSetup(wpDir: string, domain: string, nickname: string, data
5656
shell.cp(path.join(wpDir, 'wp-config-sample.php'), wpConfig);
5757

5858
// setup user for php runtime
59-
if (shell.grep(nickname, "/etc/passwd").code !== 0) {
59+
if (shell.grep(nickname, '/etc/passwd').code !== 0) {
6060
if (shell.exec(`adduser --system --no-create-home --group --disabled-login ${nickname}`).code !== 0) {
6161
throw new Error(`Failed to create the user named ${nickname}`);
6262
}
6363
}
6464

6565
// setting wordpress config
66-
shell.sed("-i", "put your unique phrase here", random(32, { symbol: true }), wpConfig);
67-
shell.sed("-i", "database_name_here", wpDb, wpConfig);
68-
shell.sed("-i", "username_here", nickname, wpConfig);
69-
shell.sed("-i", "password_here", wpDbPassword, wpConfig);
70-
shell.sed("-i", "localhost", port === 3306 ? host : `${host}:${port}`, wpConfig);
66+
shell.sed('-i', 'put your unique phrase here', random(32, { symbol: true }), wpConfig);
67+
shell.sed('-i', 'database_name_here', wpDb, wpConfig);
68+
shell.sed('-i', 'username_here', nickname, wpConfig);
69+
shell.sed('-i', 'password_here', wpDbPassword, wpConfig);
70+
shell.sed('-i', 'localhost', port === 3306 ? host : `${host}:${port}`, wpConfig);
7171

7272
const phpConfig = path.join(fpm, `pool.d/${domain}.conf`);
7373
shell.cp(path.join(fpm, 'pool.d/www.conf'), phpConfig);
7474

7575
// setting host php config
76-
shell.sed("-i", "[www]", `[${nickname}]`, phpConfig);
77-
shell.sed("-i", "user = www-data", `user = ${nickname}`, phpConfig);
78-
shell.sed("-i", "group = www-data", `group = ${nickname}`, phpConfig);
79-
shell.sed("-i", `listen = /run/php/php${php}-fpm.sock`, `listen = /run/php/php${php}-fpm-$pool.sock`, phpConfig);
80-
shell.sed("-i", `;slowlog = log/$pool.log.slow`, `slowlog = /var/log/php${php}-fpm-$pool.log.slow`, phpConfig);
81-
shell.sed("-i", `;php_admin_value[error_log] = /var/log/fpm-php.www.log`, `php_admin_value[error_log] = /var/log/php${php}-fpm-$pool.log.error`, phpConfig);
82-
shell.sed("-i", ";php_admin_flag[log_errors] = on", "php_admin_flag[log_errors] = on");
76+
shell.sed('-i', '[www]', `[${nickname}]`, phpConfig);
77+
shell.sed('-i', 'user = www-data', `user = ${nickname}`, phpConfig);
78+
shell.sed('-i', 'group = www-data', `group = ${nickname}`, phpConfig);
79+
shell.sed('-i', `listen = /run/php/php${php}-fpm.sock`, `listen = /run/php/php${php}-fpm-$pool.sock`, phpConfig);
80+
shell.sed('-i', `;slowlog = log/$pool.log.slow`, `slowlog = /var/log/php${php}-fpm-$pool.log.slow`, phpConfig);
81+
shell.sed('-i', `;php_admin_value[error_log] = /var/log/fpm-php.www.log`, `php_admin_value[error_log] = /var/log/php${php}-fpm-$pool.log.error`, phpConfig);
82+
shell.sed('-i', ';php_admin_flag[log_errors] = on', 'php_admin_flag[log_errors] = on');
8383

8484
shell.touch(`/var/log/php${php}-fpm-${nickname}.log.error`);
8585
shell.exec(`chown ${nickname}:${nickname} /var/log/php${php}-fpm-${nickname}.log.error`);

0 commit comments

Comments
 (0)