-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support ant design mobile alll
- Loading branch information
Showing
12 changed files
with
357 additions
and
32 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 |
---|---|---|
|
@@ -25,6 +25,6 @@ | |
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@alitajs/alita-layout": "2.4.8" | ||
"@alitajs/alita-layout": "2.4.9" | ||
} | ||
} |
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,19 @@ | ||
# @alitajs/plugin-antd-mobile | ||
|
||
> @alitajs/plugin-antd-mobile. | ||
See our website [@umijs/plugin-antd](https://umijs.org/plugins/plugin-antd) for more information. | ||
|
||
## Install | ||
|
||
Using npm: | ||
|
||
```bash | ||
$ npm install --save-dev @alitajs/plugin-antd-mobile | ||
``` | ||
|
||
or using yarn: | ||
|
||
```bash | ||
$ yarn add @alitajs/plugin-antd-mobile --dev | ||
``` |
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,35 @@ | ||
{ | ||
"name": "@alitajs/plugin-mobile5", | ||
"version": "2.8.26-beta.2", | ||
"description": "@alitajs/plugin-mobile5", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"files": [ | ||
"lib", | ||
"src", | ||
"templates" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/alitajs/alita" | ||
}, | ||
"keywords": [ | ||
"umi" | ||
], | ||
"authors": [ | ||
"xiaohuoni <xiaohuoni@gmail.com> (https://github.com/xiaohuoni)" | ||
], | ||
"license": "MIT", | ||
"bugs": "http://github.com/alitajs/alita/issues", | ||
"homepage": "https://github.com/alitajs/alita/tree/master/packages/plugin-antd-mobile#readme", | ||
"peerDependencies": { | ||
"umi": "3.x" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"antd-mobile5": "npm:antd-mobile@next", | ||
"fs-extra": "10.0.0" | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
packages/plugin-mobile5/src/BaseGenerator/BaseGenerator.ts
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,58 @@ | ||
import { copyFileSync, statSync } from 'fs'; | ||
import { basename, dirname, join } from 'path'; | ||
import { prompts } from '@umijs/utils'; | ||
import fsExtra from 'fs-extra'; | ||
import Generator from '../Generator/Generator'; | ||
|
||
interface IOpts { | ||
path: string; | ||
target: string; | ||
data?: any; | ||
questions?: prompts.PromptObject[]; | ||
} | ||
|
||
export default class BaseGenerator extends Generator { | ||
path: string; | ||
target: string; | ||
data: any; | ||
questions: prompts.PromptObject[]; | ||
|
||
constructor({ path, target, data, questions }: IOpts) { | ||
super({ cwd: target, args: data }); | ||
this.path = path; | ||
this.target = target; | ||
this.data = data; | ||
this.questions = questions || []; | ||
} | ||
|
||
prompting() { | ||
return this.questions; | ||
} | ||
|
||
async writing() { | ||
const context = { | ||
...this.data, | ||
...this.prompts, | ||
}; | ||
if (statSync(this.path).isDirectory()) { | ||
this.copyDirectory({ | ||
context, | ||
path: this.path, | ||
target: this.target, | ||
}); | ||
} else { | ||
const file = basename(this.path.replace(/\.tpl$/, '')); | ||
if (this.path.endsWith('.tpl')) { | ||
this.copyTpl({ | ||
templatePath: this.path, | ||
target: join(this.target, file), | ||
context, | ||
}); | ||
} else { | ||
const absTarget = join(this.target, file); | ||
fsExtra.mkdirpSync(dirname(absTarget)); | ||
copyFileSync(this.path, absTarget); | ||
} | ||
} | ||
} | ||
} |
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,67 @@ | ||
import { copyFileSync, readFileSync, statSync, writeFileSync } from 'fs'; | ||
import { dirname, join, relative } from 'path'; | ||
import { chalk, glob, Mustache, prompts, yParser } from '@umijs/utils'; | ||
import fsExtra from 'fs-extra'; | ||
|
||
interface IOpts { | ||
cwd: string; | ||
args: yParser.Arguments; | ||
} | ||
|
||
class Generator { | ||
cwd: string; | ||
args: yParser.Arguments; | ||
prompts: any; | ||
|
||
constructor({ cwd, args }: IOpts) { | ||
this.cwd = cwd; | ||
this.args = args; | ||
this.prompts = {}; | ||
} | ||
|
||
async run() { | ||
const questions = this.prompting(); | ||
this.prompts = await prompts(questions); | ||
await this.writing(); | ||
} | ||
|
||
prompting() { | ||
return [] as any; | ||
} | ||
|
||
async writing() {} | ||
|
||
copyTpl(opts: { templatePath: string; target: string; context: object }) { | ||
const tpl = readFileSync(opts.templatePath, 'utf-8'); | ||
const content = Mustache.render(tpl, opts.context); | ||
fsExtra.mkdirpSync(dirname(opts.target)); | ||
console.log(`${chalk.green('Write:')} ${relative(this.cwd, opts.target)}`); | ||
writeFileSync(opts.target, content, 'utf-8'); | ||
} | ||
|
||
copyDirectory(opts: { path: string; context: object; target: string }) { | ||
const files = glob.sync('**/*', { | ||
cwd: opts.path, | ||
dot: true, | ||
ignore: ['**/node_modules/**'], | ||
}); | ||
files.forEach((file: any) => { | ||
const absFile = join(opts.path, file); | ||
if (statSync(absFile).isDirectory()) return; | ||
if (file.endsWith('.tpl')) { | ||
this.copyTpl({ | ||
templatePath: absFile, | ||
target: join(opts.target, file.replace(/\.tpl$/, '')), | ||
context: opts.context, | ||
}); | ||
} else { | ||
console.log(`${chalk.green('Copy: ')} ${file}`); | ||
const absTarget = join(opts.target, file); | ||
fsExtra.mkdirpSync(dirname(absTarget)); | ||
copyFileSync(absFile, absTarget); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
export default Generator; |
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,48 @@ | ||
import { dirname, join } from 'path'; | ||
import { IApi } from '@umijs/types'; | ||
import BaseGenerator from './BaseGenerator/BaseGenerator'; | ||
import { existsSync } from 'fs'; | ||
export default (api: IApi) => { | ||
api.describe({ | ||
key: 'mobile5', | ||
config: { | ||
schema(joi) { | ||
return joi.boolean(); | ||
}, | ||
}, | ||
}); | ||
// 忽略用户安装,强制指定 mobile@5 版本 | ||
api.chainWebpack((memo) => { | ||
if (!!api.config.mobile5) { | ||
memo.resolve.alias.set( | ||
'antd-mobile5', | ||
join(dirname(require.resolve('antd-mobile5/package.json')), '2x'), | ||
); | ||
} | ||
return memo; | ||
}); | ||
|
||
api.onStart(async () => { | ||
if (!!api.config.mobile5) { | ||
if ( | ||
!existsSync( | ||
`${api.paths.absNodeModulesPath}/@types/antd-mobile5/index.d.ts`, | ||
) | ||
) { | ||
// logger.event('Create @types/antd-mobile5 Package'); | ||
const generator = new BaseGenerator({ | ||
path: join(__dirname, '..', 'templates', 'alias'), | ||
target: `${api.paths.absNodeModulesPath}/@types/antd-mobile5`, | ||
data: { | ||
antdMobilePath: join( | ||
dirname(require.resolve('antd-mobile5/package.json')), | ||
), | ||
antdMobile: 'antd-mobile5', | ||
}, | ||
questions: [], | ||
}); | ||
await generator.run(); | ||
} | ||
} | ||
}); | ||
}; |
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 @@ | ||
export * from '{{{ antdMobilePath }}}' |
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,13 @@ | ||
{ | ||
"name": "{{{ antdMobile }}}", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "", | ||
"types": "index.d.ts", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
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
18 changes: 0 additions & 18 deletions
18
packages/umi-presets-alita/src/plugins/features/mobile5.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.