Skip to content

Commit

Permalink
feat: first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanShaw committed Jul 6, 2022
0 parents commit c17e3ca
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/ec2/
/sites/
node_modules
/sites.json/
22 changes: 22 additions & 0 deletions examples/sites.json
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"
}
]
}
11 changes: 11 additions & 0 deletions package.json
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"
}
21 changes: 21 additions & 0 deletions run.mjs
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'});
26 changes: 26 additions & 0 deletions validate.mjs
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);
};

0 comments on commit c17e3ca

Please sign in to comment.