Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加对华为原子服务定义文件的规范检查 #3571

Merged
merged 2 commits into from
Jun 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/taro-cli/bin/taro-doctor
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ if (!fs.existsSync(PROJECT_CONF_PATH)) {
}

const { validators } = require('../dist/doctor').default
const abilityXMLValidator = require('../dist/doctor/abilityXMLValidator').default
const QUICKAPP_CONF_PATH = path.join(appPath, 'project.quickapp.json')
if (fs.existsSync(QUICKAPP_CONF_PATH)) {
validators.push(abilityXMLValidator)
}

const NOTE_ALL_RIGHT = chalk.green('[✓] ')
const NOTE_VALID = chalk.yellow('[!] ')
Expand Down
34 changes: 34 additions & 0 deletions packages/taro-cli/src/doctor/abilityXMLValidator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as _ from 'lodash/fp'
import * as fs from 'fs-extra'
import * as path from 'path'
import chalk from 'chalk'

import { IErrorLine } from './interface'

const ABILITYXML = ['ability.xml']

export default async function ({ appPath }) {
const PROJECT_PACKAGE_PATH = path.join(appPath, 'package.json')
const PROJECT_FOLDER_FILES = fs.readdirSync('./')
if (!fs.existsSync(PROJECT_PACKAGE_PATH)) {
console.log(chalk.red(`找不到${PROJECT_PACKAGE_PATH},请确定当前目录是Taro项目根目录!`))
process.exit(1)
}

const inProjectFolder = filenames => (_.intersectionBy(_.toLower, PROJECT_FOLDER_FILES, filenames)).length > 0
const hasAbilityXML = inProjectFolder(ABILITYXML)

const errorLines: IErrorLine[] = []

if (!hasAbilityXML) {
errorLines.push({
desc: '没有检查到 ability.xml, 编写 ability.xml可以让其他应用方便地叫起应用内服务',
valid: true
})
}

return {
desc: '检查原子化服务规范',
lines: errorLines
}
}