-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c17e3ca
Showing
5 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/ec2/ | ||
/sites/ | ||
node_modules | ||
/sites.json/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"host": "ec2-11-111-11-11.ap-northeast-3.compute.amazonaws.com", | ||
"kusanagi": { | ||
"password": "somepassword" | ||
}, | ||
"rootsite": { | ||
"host": "my.site.com", | ||
"dbname": "mydbname", | ||
"dbuser": "mydbuser", | ||
"dbpass": "mydbpass", | ||
"wpuser": "mywpuser" | ||
}, | ||
"subsites": [ | ||
{ | ||
"host": "my.site.com/subsite", | ||
"dbname": "mysubdbname", | ||
"dbuser": "mysubdbuser", | ||
"dbpass": "mysubdbpass", | ||
"wpuser": "mysubwpuser" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "@aivec/wp-migrate-to-ec2-kusanagi9", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env node | ||
import { existsSync, readFileSync } from 'fs'; | ||
import { validateConfig } from './validate.mjs'; | ||
|
||
const args = process.argv.slice(2); | ||
const rawconfigf = args[0] ? args[0] : null; | ||
|
||
if (rawconfigf === null) { | ||
console.log('A path to a valid JSON file is required as the first argument.'); | ||
process.exit(1); | ||
} | ||
|
||
if (!existsSync(rawconfigf)) { | ||
console.log(`${rawconfigf} doesnt exist`); | ||
process.exit(1); | ||
} | ||
|
||
const rawconfig = JSON.parse(readFileSync(rawconfigf, 'utf8')); | ||
console.log(rawconfig); | ||
|
||
validateConfig({ host: 'mysite.com'}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export const validateHost = (host) => { | ||
if (/^(http|https):\/\//.test(host)) { | ||
console.log('Scheme (http:// or https://) for host must be omitted.'); | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
export const validateConfig = (config) => { | ||
if ( | ||
!config || | ||
config === true || | ||
Array.isArray(config) || | ||
config.length !== undefined || | ||
typeof config === "number" | ||
) { | ||
console.log("Configuration file is not valid."); | ||
process.exit(1); | ||
} | ||
|
||
if (!config.host) { | ||
console.log("'host' is required."); | ||
process.exit(1); | ||
} | ||
|
||
validateHost(config.host); | ||
}; |