This repository has been archived by the owner on Mar 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add remax version check in project (#325)
* fix: add remax version check in project * fix: add symbol type * fix: add symbol type * fix: change remax path to node_modules * fix: change path.join to require.resolve * fix: semver.lt => semver.neq
- Loading branch information
Showing
3 changed files
with
73 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
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,70 @@ | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import semver from 'semver'; | ||
import chalk from 'chalk'; | ||
|
||
const generatorStar = (count: number, symbol = '*') => { | ||
let starStr = ''; | ||
for (let i = 0; i < count; i++) { | ||
starStr += symbol; | ||
} | ||
return starStr; | ||
}; | ||
|
||
const generatorPlace = ( | ||
origin: string, | ||
replace: string, | ||
longLength: number | ||
): string => { | ||
const index = Math.round(origin.length / 2) - Math.round(longLength / 2) - 1; | ||
const length = replace.length; | ||
const originArray = origin.split(''); | ||
const replaceArray = replace.split(''); | ||
for (let i = 0; i < length; i++) { | ||
originArray[i + index] = replaceArray[i]; | ||
} | ||
return originArray.join(''); | ||
}; | ||
|
||
export const checkRemaxVersion = () => { | ||
try { | ||
const cliPackagePath: string = require.resolve('../package.json'); | ||
const remaxPackagePath: string = path.join( | ||
process.cwd(), | ||
'node_modules', | ||
'remax', | ||
'package.json' | ||
); | ||
if (fs.existsSync(remaxPackagePath)) { | ||
const remaxPkgConfig = require(remaxPackagePath); | ||
const cliPkgConfig = require(cliPackagePath); | ||
const remaxVersion = remaxPkgConfig.version; | ||
|
||
if (semver.neq(remaxVersion, cliPkgConfig.version)) { | ||
const placeholder = | ||
'* *'; | ||
const origin = | ||
'* *'; | ||
const remax = 'remax: ' + chalk.red(remaxVersion); | ||
const remaxCLI = 'remax-cli: ' + chalk.green(cliPkgConfig.version); | ||
const longLength = | ||
remax.length > remaxCLI.length ? remax.length : remaxCLI.length; | ||
|
||
const warning = chalk.yellow(`remax-cli 版本与 remax 版本不匹配`); | ||
const upgrade = chalk.yellow(`请升级 remax 版本`); | ||
|
||
console.log(generatorStar(55)); | ||
console.log(placeholder); | ||
console.log('*', ` ${warning} `, '*'); | ||
console.log('*', ` ${upgrade} `, '*'); | ||
console.log(placeholder); | ||
console.log(generatorPlace(origin, remax, longLength)); | ||
console.log(generatorPlace(origin, remaxCLI, longLength)); | ||
console.log(placeholder); | ||
console.log(generatorStar(55)); | ||
} | ||
} | ||
} catch (err) { | ||
return false; | ||
} | ||
}; |
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
6ab19ce
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to following URLs: