Compare commits
2 Commits
1.0.0-alph
...
1.0.0-alph
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dcc379607b | ||
|
|
ea39e4bad6 |
@@ -1,3 +1,3 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
require('../build/src/index.js');
|
require('../build/index.js');
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mep-agency/local-dev-db",
|
"name": "@mep-agency/local-dev-db",
|
||||||
"version": "1.0.0-alpha10",
|
"version": "1.0.0-alpha12",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "A zero-config local MariaDB instance for local development (using Docker)",
|
"description": "A zero-config local MariaDB instance for local development (using Docker)",
|
||||||
"author": "Marco Lipparini <developer@liarco.net>",
|
"author": "Marco Lipparini <developer@liarco.net>",
|
||||||
@@ -31,10 +31,8 @@
|
|||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"bin",
|
"bin",
|
||||||
"build",
|
"build/**/*.js",
|
||||||
"docker",
|
"docker"
|
||||||
"LICENCE",
|
|
||||||
"README.md"
|
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/mysql": "^2.15.21",
|
"@types/mysql": "^2.15.21",
|
||||||
|
|||||||
@@ -2,19 +2,26 @@ import fs from 'fs';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
const JSON_CONFIG_FILE_NAME = 'ldd.json';
|
const JSON_CONFIG_FILE_NAME = 'ldd.json';
|
||||||
|
const PACKAGE_JSON_PATH = `${__dirname}/../package.json`;
|
||||||
|
|
||||||
const DEFAULT_CONFIG: JsonConfiguration = {
|
const DEFAULT_CONFIG: Partial<JsonConfiguration> = {
|
||||||
dbName: undefined,
|
dbName: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
interface JsonConfiguration {
|
interface JsonConfiguration {
|
||||||
dbName?: string;
|
dbName?: string;
|
||||||
|
packageInfo: {
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
version: string;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const findAndReadConfig = () => {
|
const findAndReadConfig = () => {
|
||||||
|
let userConfig = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let startdir = process.cwd();
|
let startdir = process.cwd();
|
||||||
let userConfigData = '{}';
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
var list = fs.readdirSync(startdir);
|
var list = fs.readdirSync(startdir);
|
||||||
@@ -23,7 +30,7 @@ const findAndReadConfig = () => {
|
|||||||
// Found
|
// Found
|
||||||
console.info(`Loading configuration from: ${path.join(startdir, JSON_CONFIG_FILE_NAME)}`);
|
console.info(`Loading configuration from: ${path.join(startdir, JSON_CONFIG_FILE_NAME)}`);
|
||||||
|
|
||||||
userConfigData = fs.readFileSync(path.join(startdir, JSON_CONFIG_FILE_NAME)).toString();
|
userConfig = JSON.parse(fs.readFileSync(path.join(startdir, JSON_CONFIG_FILE_NAME)).toString());
|
||||||
break;
|
break;
|
||||||
} else if (startdir == '/') {
|
} else if (startdir == '/') {
|
||||||
// Root dir, file not found
|
// Root dir, file not found
|
||||||
@@ -32,13 +39,20 @@ const findAndReadConfig = () => {
|
|||||||
startdir = path.normalize(path.join(startdir, '..'));
|
startdir = path.normalize(path.join(startdir, '..'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('ERROR: Failed loading LDD configuration file...');
|
||||||
|
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
return {
|
return {
|
||||||
...DEFAULT_CONFIG,
|
...DEFAULT_CONFIG,
|
||||||
...JSON.parse(userConfigData),
|
...userConfig,
|
||||||
|
packageInfo: JSON.parse(fs.readFileSync(PACKAGE_JSON_PATH).toString()),
|
||||||
} as JsonConfiguration;
|
} as JsonConfiguration;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('ERROR: Failed reading LDD configuration file...');
|
console.error('ERROR: Failed loading LDD package.json...');
|
||||||
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|||||||
36
src/index.ts
36
src/index.ts
@@ -4,10 +4,9 @@ import { confirm } from '@inquirer/prompts';
|
|||||||
import { dockerCommand } from 'docker-cli-js';
|
import { dockerCommand } from 'docker-cli-js';
|
||||||
import mysql from 'mysql';
|
import mysql from 'mysql';
|
||||||
|
|
||||||
import packageInfo from '../package.json';
|
|
||||||
import config from './config';
|
import config from './config';
|
||||||
|
|
||||||
const PACKAGE_INSTALLATION_PATH = `${__dirname}/../..`;
|
const LDD_ROOT_PATH = `${__dirname}/..`;
|
||||||
|
|
||||||
interface DockerImagesCommandResult {
|
interface DockerImagesCommandResult {
|
||||||
images: {
|
images: {
|
||||||
@@ -22,7 +21,7 @@ interface DockerImagesCommandResult {
|
|||||||
const dockerCompose: typeof dockerCommand = async (command, options) => {
|
const dockerCompose: typeof dockerCommand = async (command, options) => {
|
||||||
try {
|
try {
|
||||||
return await dockerCommand(
|
return await dockerCommand(
|
||||||
`compose --file "${PACKAGE_INSTALLATION_PATH}/docker/docker-compose.yml" --project-name "ldd" ${command}`,
|
`compose --file "${LDD_ROOT_PATH}/docker/docker-compose.yml" --project-name "ldd" ${command}`,
|
||||||
{ echo: false, ...(options ?? {}) },
|
{ echo: false, ...(options ?? {}) },
|
||||||
);
|
);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
@@ -71,7 +70,7 @@ const execQuery = (query: string, database: string = 'defaultdb') => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
program.name('ldd').description(packageInfo.description).version(packageInfo.version);
|
program.name('ldd').description(config.packageInfo.description).version(config.packageInfo.version);
|
||||||
|
|
||||||
program
|
program
|
||||||
.command('start')
|
.command('start')
|
||||||
@@ -84,18 +83,27 @@ program
|
|||||||
`phpmyadmin:${process.env.LDD_PMA_IMAGE_TAG ?? 'latest'}`,
|
`phpmyadmin:${process.env.LDD_PMA_IMAGE_TAG ?? 'latest'}`,
|
||||||
];
|
];
|
||||||
|
|
||||||
const availableImagesImages = ((await dockerCommand('images', { echo: false })) as DockerImagesCommandResult).images
|
try {
|
||||||
.map((imageData) => `${imageData.repository}:${imageData.tag}`)
|
const availableImagesImages = ((await dockerCommand('images', { echo: false })) as DockerImagesCommandResult).images
|
||||||
.filter((imageName) => requiredImages.includes(imageName));
|
.map((imageData) => `${imageData.repository}:${imageData.tag}`)
|
||||||
|
.filter((imageName) => requiredImages.includes(imageName));
|
||||||
|
|
||||||
const missingImages = requiredImages.filter((requiredImage) => !availableImagesImages.includes(requiredImage));
|
const missingImages = requiredImages.filter((requiredImage) => !availableImagesImages.includes(requiredImage));
|
||||||
|
|
||||||
if (missingImages.length > 0) {
|
if (missingImages.length > 0) {
|
||||||
console.info('');
|
console.info('');
|
||||||
console.info('The following images will be downloaded as they are required but not available:');
|
console.info('The following images will be downloaded as they are required but not available:');
|
||||||
missingImages.map((image) => console.info(` - ${image}`));
|
missingImages.map((image) => console.info(` - ${image}`));
|
||||||
console.info('');
|
console.info('');
|
||||||
console.info('This may take some time, please wait...');
|
console.info('This may take some time, please wait...');
|
||||||
|
}
|
||||||
|
} catch (e: any) {
|
||||||
|
if (e.stderr === undefined) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.error(`ERROR: ${e.stderr}`);
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
await dockerCompose('up -d');
|
await dockerCompose('up -d');
|
||||||
|
|||||||
Reference in New Issue
Block a user