-
Notifications
You must be signed in to change notification settings - Fork 13
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
Showing
8 changed files
with
135 additions
and
73 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 @@ | ||
/* eslint-disable no-console */ | ||
|
||
require('../../typedef'); | ||
|
||
const logError = require('./libs/log-error'); | ||
const __ = require('../../utils/translate'); | ||
const getAppType = require('../../utils/get-app-type'); | ||
const getAppTypeString = require('../../utils/get-app-type-string'); | ||
const envUpdateAppType = require('../env/update-app-type'); | ||
|
||
/** | ||
* Safeguard: App Type | ||
* - Ensure environment variables updated: `WEBPACK_BUILD_TYPE` `KOOT_PROJECT_TYPE` `KOOT_BUILD_TARGET` | ||
* - If cannot get a valid app type, throw an error | ||
* @async | ||
* @param {AppConfig} appConfig | ||
* @void | ||
*/ | ||
module.exports = async (appConfig = {}) => { | ||
const appType = await getAppType(); | ||
if (!appType) envUpdateAppType(getAppTypeString(appConfig.type)); | ||
if (!(await getAppType())) { | ||
logError(__('safeguard.INVALID_CONFIG', { key: 'type' })); | ||
throw new Error('INVALID_CONFIG:type'); | ||
} | ||
}; |
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,36 @@ | ||
/* eslint-disable no-console */ | ||
|
||
require('../../typedef'); | ||
|
||
const resolve = require('resolve'); | ||
|
||
const logError = require('./libs/log-error'); | ||
const __ = require('../../utils/translate'); | ||
const getCwd = require('../../utils/get-cwd'); | ||
|
||
/** | ||
* Safeguard: Electron | ||
* - If module `koot-electron` not found, throw an error | ||
* @async | ||
* @param {AppConfig} appConfig | ||
* @void | ||
*/ | ||
module.exports = async (appConfig = {}) => { | ||
const isElectronApp = | ||
appConfig.target === 'electron' || | ||
process.env.KOOT_BUILD_TARGET === 'electron'; | ||
if (isElectronApp) { | ||
await new Promise((r, reject) => { | ||
resolve('koot-electron', { basedir: getCwd() }, (err, res) => { | ||
if (err) reject(err); | ||
else r(res); | ||
}); | ||
}).catch((err) => { | ||
if (err.code === 'MODULE_NOT_FOUND') { | ||
err.message = 'NEED_PACKAGE_KOOT_ELECTRON'; | ||
logError(__('safeguard.NEED_PACKAGE_KOOT_ELECTRON')); | ||
} | ||
throw err; | ||
}); | ||
} | ||
}; |
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,28 @@ | ||
/* eslint-disable no-console */ | ||
|
||
/** | ||
* @module | ||
* Safeguard mechanism for koot commands | ||
*/ | ||
|
||
require('../../typedef'); | ||
|
||
const safeNodejs = require('./nodejs'); | ||
const safeAppType = require('./app-type'); | ||
const safeElectron = require('./electron'); | ||
|
||
// ============================================================================ | ||
|
||
/** | ||
* Safeguard mechanism for koot commands. If error occurs, throw Error | ||
* @async | ||
* @param {AppConfig} appConfig | ||
* @void | ||
*/ | ||
const safeguard = async (appConfig = {}) => { | ||
await safeNodejs(appConfig); | ||
await safeAppType(appConfig); | ||
await safeElectron(appConfig); | ||
}; | ||
|
||
module.exports = safeguard; |
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,10 @@ | ||
/* eslint-disable no-console */ | ||
|
||
const log = require('../../log'); | ||
|
||
module.exports = (msg) => { | ||
console.log(' '); | ||
log('error', msg); | ||
console.log(' '); | ||
console.log(' '); | ||
}; |
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,31 @@ | ||
/* eslint-disable no-console */ | ||
|
||
require('../../typedef'); | ||
|
||
const semver = require('semver'); | ||
|
||
const logError = require('./libs/log-error'); | ||
const __ = require('../../utils/translate'); | ||
|
||
const kootPackage = require('../../package.json'); | ||
|
||
/** | ||
* Safeguard: Node.js | ||
* - If _Node.js_ installed version dosenot meet requirement, throw an error | ||
* @async | ||
* @param {AppConfig} appConfig | ||
* @void | ||
*/ | ||
module.exports = async (appConfig = {}) => { | ||
const { engines: { node: nodeRequired } = {} } = kootPackage; | ||
const nodeLocal = semver.valid(semver.coerce(process.version)); | ||
if (!semver.satisfies(nodeLocal, nodeRequired)) { | ||
logError( | ||
__('safeguard.NODE_LOCAL_VERSION_NOT_SATISFIED', { | ||
require: nodeRequired, | ||
local: nodeLocal, | ||
}) | ||
); | ||
throw new Error('NODE_LOCAL_VERSION_NOT_SATISFIED'); | ||
} | ||
}; |
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
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