-
Notifications
You must be signed in to change notification settings - Fork 0
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
32 changed files
with
1,827 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
module.exports = { | ||
extends: '@osdoc-dev/eslint-config-preset-ts', | ||
rules: { | ||
'@typescript-eslint/no-var-requires': 0, | ||
'brace-style': 0, | ||
'comma-dangle': 0, | ||
'arrow-parens': 0, | ||
'unicorn/prevent-abbreviations': 0, | ||
'space-before-function-paren': 0, | ||
'global-require': 0, | ||
'import/no-dynamic-require': 0, | ||
}, | ||
} |
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
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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
#!/usr/bin/env node | ||
const updater = require('update-notifier') | ||
const { checkNodeVersion, registerCommand } = require('../lib') | ||
const package = require('../package.json') | ||
|
||
const { checkNodeVersion } = require('../lib') | ||
const pkg = require('../package.json') | ||
// 检查 node 版本 | ||
checkNodeVersion(package.engines.node, package.name) | ||
|
||
// check node version | ||
checkNodeVersion(pkg.engines.node, pkg.name) | ||
// 检查更新 | ||
updater({ pkg: package }).notify({ defer: true }) | ||
|
||
console.log('avenger', pkg.engines.node, pkg.name) | ||
// 注册命令 | ||
registerCommand() |
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,55 @@ | ||
/* | ||
* @Author: ahwgs | ||
* @Date: 2021-04-02 00:22:55 | ||
* @Last Modified by: ahwgs | ||
* @Last Modified time: 2021-04-08 21:26:22 | ||
*/ | ||
|
||
import path from 'path' | ||
import program from 'commander' | ||
import { getPackageJson, chalk } from '@avenger/utils' | ||
import { build } from '@avenger/core' | ||
import envinfo from 'envinfo' | ||
import { getBuildArguments } from './common' | ||
// 注册命令 | ||
export const registerCommand = () => { | ||
const packageJson = getPackageJson(path.join(__dirname, '..')) | ||
// version | ||
program.version(`${packageJson.name} v${packageJson.version}`) | ||
|
||
program | ||
.command('build') | ||
.description('打包') | ||
.option('--file', '打包输出文件名') | ||
.option('--entry', '打包主入口') | ||
.option('-w, --watch', 'watch 模式') | ||
|
||
.allowUnknownOption() | ||
.action(() => build(getBuildArguments())) | ||
|
||
// debug info | ||
program | ||
.command('info') | ||
.description('环境信息') | ||
.action(() => { | ||
console.log(chalk.bold('\nEnvironment Info:')) | ||
envinfo | ||
.run( | ||
{ | ||
System: ['OS', 'CPU'], | ||
Binaries: ['Node', 'Yarn', 'npm'], | ||
Browsers: ['Chrome', 'Edge', 'Firefox', 'Safari'], | ||
npmPackages: '/**/{typescript,*@avenger*,@avenger/*/}', | ||
npmGlobalPackages: [packageJson.name], | ||
}, | ||
{ | ||
showNotFound: true, | ||
duplicates: true, | ||
fullTree: true, | ||
} | ||
) | ||
.then(console.log) | ||
}) | ||
|
||
program.parse(process.argv) | ||
} |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './common' | ||
export * from './command' |
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 |
---|---|---|
@@ -1,7 +1,47 @@ | ||
/* | ||
* babel 配置 | ||
* 获取babel 配置 | ||
* @Author: ahwgs | ||
* @Date: 2021-04-01 00:29:48 | ||
* @Date: 2021-04-08 22:02:11 | ||
* @Last Modified by: ahwgs | ||
* @Last Modified time: 2021-04-01 00:31:28 | ||
* @Last Modified time: 2021-04-09 15:02:28 | ||
*/ | ||
import { IGetBabelConfigProps } from '@avenger/shared' | ||
|
||
export const getBabelConfig = (opt: IGetBabelConfigProps) => { | ||
const { target, nodeVersion = 6, type, typescript } = opt || {} | ||
|
||
const isBrowser = target === 'browser' | ||
|
||
// 默认兼容node 6 | ||
const targets = isBrowser ? { browsers: ['last 2 versions', 'IE 10'] } : { node: nodeVersion } | ||
|
||
const presets = [ | ||
...(typescript ? [require.resolve('@babel/preset-typescript')] : []), | ||
[ | ||
require.resolve('@babel/preset-env'), | ||
{ | ||
targets, | ||
modules: type === 'esm' ? false : 'auto', | ||
}, | ||
], | ||
] | ||
|
||
const plugins = [ | ||
require.resolve('babel-plugin-react-require'), | ||
require.resolve('@babel/plugin-syntax-dynamic-import'), | ||
require.resolve('@babel/plugin-proposal-export-default-from'), | ||
require.resolve('@babel/plugin-proposal-export-namespace-from'), | ||
require.resolve('@babel/plugin-proposal-do-expressions'), | ||
require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'), | ||
require.resolve('@babel/plugin-proposal-optional-chaining'), | ||
[require.resolve('@babel/plugin-proposal-decorators'), { legacy: true }], | ||
[require.resolve('@babel/plugin-proposal-class-properties'), { loose: true }], | ||
] | ||
|
||
return { | ||
config: { | ||
presets, | ||
plugins, | ||
}, | ||
} | ||
} |
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,3 @@ | ||
export * from './rollup' | ||
export * from './cli' | ||
export * from './babel' |
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,7 @@ | ||
/* | ||
* @Author: ahwgs | ||
* @Date: 2021-04-02 21:35:08 | ||
* @Last Modified by: ahwgs | ||
* @Last Modified time: 2021-04-02 21:35:08 | ||
*/ | ||
export const getRollupConfig = () => {} |
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,20 @@ | ||
/* | ||
* build fils | ||
* @Author: ahwgs | ||
* @Date: 2021-04-02 09:45:43 | ||
* @Last Modified by: ahwgs | ||
* @Last Modified time: 2021-04-09 15:08:55 | ||
*/ | ||
import { ICliOpt, CLI_CONFIG_FILES } from '@avenger/shared' | ||
import { getBundleOpts } from '@avenger/config' | ||
import registerBabel from './register-babel' | ||
|
||
export const build = (opt?: ICliOpt) => { | ||
const { cwd } = opt | ||
|
||
// 配置文件 babel 转一下,不然export default 报错 | ||
registerBabel({ cwd, only: CLI_CONFIG_FILES }) | ||
|
||
// 获取打包配置 | ||
getBundleOpts(opt) | ||
} |
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,5 @@ | ||
import rollup from 'rollup' | ||
|
||
export * from './build' | ||
|
||
export { rollup } |
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 @@ | ||
/* | ||
* @Author: ahwgs | ||
* @Date: 2021-04-08 20:11:52 | ||
* @Last Modified by: ahwgs | ||
* @Last Modified time: 2021-04-09 15:04:02 | ||
*/ | ||
import path from 'path' | ||
import { slash } from '@avenger/utils' | ||
import { getBabelConfig } from '@avenger/config' | ||
|
||
interface IRegisterBabelProps { | ||
cwd: string | ||
only: string[] | ||
} | ||
|
||
export default ({ cwd, only }: IRegisterBabelProps) => { | ||
const { config } = getBabelConfig({ | ||
target: 'node', | ||
typescript: true, | ||
}) | ||
require('@babel/register')({ | ||
...config, | ||
extensions: ['.es6', '.es', '.jsx', '.js', '.mjs', '.ts', '.tsx'], | ||
only: only.map(file => slash(path.join(cwd, file))), | ||
babelrc: false, | ||
cache: false, | ||
}) | ||
} |
Oops, something went wrong.