Skip to content

Commit

Permalink
feat: js文件改ts
Browse files Browse the repository at this point in the history
  • Loading branch information
kongjing committed Apr 13, 2023
1 parent 030e0e1 commit b251f60
Show file tree
Hide file tree
Showing 29 changed files with 302 additions and 310 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
.rn_temp
.DS_Store

antm.config.js
pullRequest.js
package-lock.json

.**_temp.js
**_build
node_modules
packages/**/coverage
packages/**/dist
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
node ./packages/warning/dist/index.js webhooks
npx ts-node ./packages/warning/src/index.ts webhooks
11 changes: 0 additions & 11 deletions _antm.config.js

This file was deleted.

38 changes: 38 additions & 0 deletions antm.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { join } from 'path'
import { defineConfig, IDocMenuNavs } from '@antmjs/types'

const CWD = process.cwd()

export default defineConfig({
warning: {
monitorFiles: [
'./packages/[!node_modules]**/package.json',
'./package.json',
],
webhooks: {
url: 'https://oapi.dingtalk.com/robot/send?access_token=c2ca61d59a4e22f5d60b8d841494ab5ab570ec190accb16bbee10562092c8fe8',
},
},
docs: {
title: 'antmjs',
src: join(CWD, './packages'),
route: {
exclude: [join(CWD, './packages/doc/*'), join(CWD, './packages/types/*')],
},
menu: getMenus(),
},
})

function getMenus(): IDocMenuNavs {
return [
{
name: '使用指南',
items: [
{
path: 'introduce',
title: '介绍',
},
],
},
]
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
"release:lerna": "lerna version --exact --no-git-tag-version --force-publish",
"release:beta": "lerna publish --force-publish=* --exact --skip-temp-tag --preid=beta --npm-tag=beta",
"release": "npm run release:lerna && npm run changelog && node ./pullRequest.js",
"test": "npx lerna run test",
"prepare": "husky install"
"prepare": "husky install",
"docs:start": "npx antm-doc-start",
"docs:build": "npx antm-doc-build",
"release": "npx gh-pages -d doc_build -e ./antm"
},
"workspaces": [
"packages/*"
Expand Down
57 changes: 9 additions & 48 deletions packages/api/src/config/getConfig.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,24 @@
import { join } from 'path'
import fs from 'fs'
import { IApiConfig } from '@antmjs/types'
import log from '../log.js'

type Iconfig = {
/** 请求ts的文件路径 */
path?: string
title?: string
buildPath?: string
buildPort?: number
mock?: {
/** 统一设置接口的延时返回 */
timeout?: number
port?: number
baseIntercept?: (params: {
url: string
fieldName: string
type: 'string' | 'number' | 'boolean'
originValue?: any
}) => any
arrayRule?: (params: {
url: string
fieldName: string
originRule?: any
}) => string
}
/** 生成请求方法配置 */
action?: {
dirPath?: string
requestImport?: string
requestFnName?: string
requestSuffix?: string
/** 自定义请求方法 */
createDefaultModel?: (params: {
data: any
fileName: string
requestImport?: string
requestFnName?: string
}) => string
}
/** swagger生成请求字段类型 */
swagger?: {
url?: string
/** 使用到的模块 */
modules?: string[]
}
} & Record<string, any>

let ifWarned = false

export default function getConfig(): Iconfig {
const configPath = join(process.cwd(), 'antm.config.js')
export default function getConfig(): IApiConfig {
let configPath = join(process.cwd(), 'antm.config.ts')

if (!fs.existsSync(configPath)) {
configPath = join(process.cwd(), 'antm.config.js')
}

if (fs.existsSync(configPath)) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const apiConfig = require(configPath).api || {}
return apiConfig as Iconfig
return apiConfig as IApiConfig
} else {
if (!ifWarned) {
log.warning('根目录找不到antm.config.js文件')
log.warning('根目录找不到antm.config.js(ts)文件')
ifWarned = true
}
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ function workUnit(paths: string[], action: boolean, writeActionTarget: string) {
content = apiConfig?.action?.createDefaultModel({
data: def,
fileName: fileName,
requestImport,
requestFnName,
requestImport: requestImport || '',
requestFnName: requestFnName || '',
})
}

Expand Down
5 changes: 5 additions & 0 deletions packages/api/src/mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default function main() {
if (baseIntercept) {
value__ =
baseIntercept({
// @ts-ignore
url: url || '',
fieldName: key,
type: 'number',
Expand All @@ -123,6 +124,7 @@ export default function main() {
if (baseIntercept) {
value__ =
baseIntercept({
// @ts-ignore
url: url || '',
fieldName: key,
type: 'boolean',
Expand All @@ -138,6 +140,7 @@ export default function main() {
if (baseIntercept) {
value__ =
baseIntercept({
// @ts-ignore
url: url || '',
fieldName: key,
type: 'string',
Expand All @@ -156,6 +159,7 @@ export default function main() {
if (baseIntercept) {
value__ =
baseIntercept({
// @ts-ignore
url: url || '',
fieldName: key,
type: 'string',
Expand All @@ -176,6 +180,7 @@ export default function main() {
if (arrayRule) {
rule__ =
arrayRule({
// @ts-ignore
url: url || '',
fieldName: key,
originRule: item.rule,
Expand Down
90 changes: 46 additions & 44 deletions packages/doc/antm.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,6 @@ import { join } from 'path'
import { defineConfig, IDocMenuNavs } from '@antmjs/types'
import pkg from './package.json'

export const menu: IDocMenuNavs = [
{
name: '使用指南',
items: [
{
title: '介绍',
path: 'introduce',
},
{
title: '快速开始',
path: 'quick',
},
],
},
{
name: '基础功能',
items: [
{
title: '基本配置',
path: 'base',
},
{
title: '约定式路由',
path: 'route',
},
{
title: '全局样式',
path: 'style',
},
],
},
{
name: '高级功能',
items: [
{
title: 'markdown语法扩展',
path: 'markdown-expand',
},
],
},
]

export default defineConfig({
docs: {
title: 'antm.js Doc',
Expand All @@ -56,7 +14,7 @@ export default defineConfig({
headerLinks: [
{
title: 'https://b.yzcdn.cn/vant/logo/github.svg',
url: 'https://github.com/antmjs/vantui',
url: 'https://github.com/AntmJS/antm/tree/main/packages/doc',
type: 'img',
},
{
Expand All @@ -65,6 +23,50 @@ export default defineConfig({
type: 'text',
},
],
menu: menu,
menu: createMenu(),
},
})

function createMenu(): IDocMenuNavs {
return [
{
name: '使用指南',
items: [
{
title: '介绍',
path: 'introduce',
},
{
title: '快速开始',
path: 'quick',
},
],
},
{
name: '基础功能',
items: [
{
title: '基本配置',
path: 'base',
},
{
title: '约定式路由',
path: 'route',
},
{
title: '全局样式',
path: 'style',
},
],
},
{
name: '高级功能',
items: [
{
title: 'markdown语法扩展',
path: 'markdown-expand',
},
],
},
]
}
2 changes: 1 addition & 1 deletion packages/doc/config/utils/create-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function createBase(config: IDocsConfig) {
const { src, route } = config
const { exclude, level = 3 } = route || {}
_level = level
_src = Array.isArray(src) ? src : [src]
_src = Array.isArray(src) && src ? src : [src]
_config = config
let MD_PATHS: string[] = []
for (let i = 0; i < _src.length; i++) {
Expand Down
7 changes: 4 additions & 3 deletions packages/doc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
},
"scripts": {
"start": "npx ts-node ./scripts/run",
"build": "npx ts-node ./scripts/build"
"build": "npx ts-node ./scripts/build",
"release": "npx gh-pages -d ./doc_build -e ./antm-doc"
},
"keywords": [
"document",
Expand All @@ -21,10 +22,10 @@
"author": "",
"repository": {
"type": "https",
"url": "https://github.com/AntmJS/packages/antm/doc"
"url": "https://github.com/AntmJS/antm/tree/main/packages/doc"
},
"bugs": {
"url": "https://github.com/AntmJS/antm/packages/issues/new"
"url": "https://github.com/AntmJS/antm/issues/new"
},
"engines": {
"node": ">=16.4",
Expand Down
31 changes: 0 additions & 31 deletions packages/doc/tsconfig.base.json

This file was deleted.

7 changes: 5 additions & 2 deletions packages/doc/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"extends": "./tsconfig.base.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"baseUrl": "./",
"noEmit": true,
"skipLibCheck": false
"skipLibCheck": false,
"resolveJsonModule": true
},
"include": ["*.js", "*.ts", "*.tsx"]
}
Loading

0 comments on commit b251f60

Please sign in to comment.