Skip to content

Commit

Permalink
- wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jellesiderius committed Jul 15, 2021
1 parent 4e3c8c3 commit 28427f8
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 31 deletions.
15 changes: 5 additions & 10 deletions dist/controllers/selfUpdateController.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/controllers/selfUpdateController.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions dist/mage-db-sync.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/mage-db-sync.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions dist/utils/versionCheck.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/utils/versionCheck.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mage-db-sync",
"version": "0.1.7",
"version": "0.1.6",
"description": "Database synchronizer for Magento, based on Magerun",
"author": {
"name": "Jelle Siderius"
Expand Down
18 changes: 8 additions & 10 deletions src/controllers/selfUpdateController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,26 @@ import {getInstalledPath} from 'get-installed-path'
import {success} from "../utils/console";
import {ExecException} from "child_process";
// @ts-ignore
import * as fetch from 'node-fetch'
// @ts-ignore
import packageFile from '../../package.json';
import VersionCheck from "../utils/versionCheck";

class SelfUpdateController {
private versionCheck = new VersionCheck();

executeStart = async (serviceName: string | undefined): Promise<boolean> => {
await this.versionCheck.getToolVersions();

let self = this;
let config = {
'npmPath': '',
'latestVersion': '',
'currentVersion': packageFile.version
}
'currentVersion': this.versionCheck.config.currentVersion,
'latestVersion': this.versionCheck.config.latestVersion
};

await getInstalledPath('mage-db-sync').then((path: string) => {
config.npmPath = path;
});

// @ts-ignore
await fetch('https://raw.githubusercontent.com/jellesiderius/mage-db-sync/master/package.json')
.then((res: { json: () => any; }) => res.json())
.then((json: { version: string; }) => config.latestVersion = json.version);

if (config.currentVersion < config.latestVersion) {
await download('jellesiderius/mage-db-sync#master', config.npmPath, async function (err: any) {
await self.execShellCommand(`cd ${config.npmPath}; npm install`);
Expand Down
15 changes: 11 additions & 4 deletions src/mage-db-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import commandLoader from './commands/index'
import fs from 'fs';
// @ts-ignore
import {getInstalledPath} from 'get-installed-path'
import {success, error} from "./utils/console";
import {error} from "./utils/console";
import VersionCheck from "./utils/versionCheck";

getInstalledPath('mage-db-sync').then((path: any) => {
getInstalledPath('mage-db-sync').then(async (path: any) => {
// Lets make sure all required files are in place before running the tool
let npmPath = path;
let missingFiles = false;
Expand All @@ -30,15 +31,21 @@ getInstalledPath('mage-db-sync').then((path: any) => {
return;
}

commandLoader(program)
commandLoader(program);

// eslint-disable-next-line @typescript-eslint/no-var-requires
const packageJson = require('../package.json')
let versionCheck = new VersionCheck();
await versionCheck.getToolVersions();
let description = `Magento Database Synchronizer, based on Magerun - ${packageJson.version}`;
if (versionCheck.config.currentVersion < versionCheck.config.latestVersion) {
description = `${description}\nRun 'mage-db-sync self-update' to download the newest version: ${versionCheck.config.latestVersion}`;
}

program
.version(packageJson.version)
.usage('<command> [options]')
.description(`Magento Database Synchronizer, based on Magerun - ${packageJson.version}`)
.description(description)

program.on('command:*', () => {
program.help()
Expand Down
20 changes: 20 additions & 0 deletions src/utils/versionCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @ts-ignore
import packageFile from "../../package.json";
// @ts-ignore
import * as fetch from 'node-fetch'

class VersionCheck {
public config = {
'latestVersion': '',
'currentVersion': packageFile.version
}

// versions
getToolVersions = async () => {
await fetch('https://raw.githubusercontent.com/jellesiderius/mage-db-sync/master/package.json')
.then((res: { json: () => any; }) => res.json())
.then((json: { version: string; }) => this.config.latestVersion = json.version);
}
}

export default VersionCheck;

0 comments on commit 28427f8

Please sign in to comment.