Skip to content

Commit

Permalink
perf: use walli
Browse files Browse the repository at this point in the history
  • Loading branch information
imcuttle committed Apr 10, 2018
1 parent a6f5e4f commit dc64a1e
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 14 deletions.
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"rimraf": "^2.6.2",
"ts-jest": "^22.4.2",
"typescript": "^2.7.2",
"typescript-eslint-parser": "^14.0.0"
"typescript-eslint-parser": "^14.0.0",
"walli": "0.0.3"
},
"engines": {
"node": ">=6"
Expand Down
16 changes: 15 additions & 1 deletion packages/edam/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions packages/edam/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"scripts": {
"dist": "rimraf dist && tsc",
"dev": "npm run dist -- -w",
"prepublish": "npm run dist",
"prepublishOnly": "npm run dist",
"changelog": "conventional-changelog -p angular -i ../../CHANGELOG.md -s -r 0 && git add ../../CHANGELOG.md"
},
"typings": "dist/index.d.ts",
"description": "💥 The multifunctional scaffold generator.",
"main": "dist/index.js",
"keywords": [
Expand Down Expand Up @@ -43,7 +44,8 @@
"tildify": "^1.2.0",
"untildify": "^3.0.2",
"update-notifier": "^2.4.0",
"url-join": "^4.0.0"
"url-join": "^4.0.0",
"walli": "0.0.4"
},
"devDependencies": {
"bdd-stdin": "^0.2.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/edam/src/__tests__/fixture/.edamrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "./loadConfig/a/.circlerc",
"source": "edam.rc",
"alias": {
"edam": "edam",
"edam": 'npm:edam',
"edam-github": {
type: "git",
url: "abc"
Expand Down
4 changes: 2 additions & 2 deletions packages/edam/src/core/normalizeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @date 2018/3/23
* @description
*/
import { EdamConfig } from '../types/Options'
import { edam as edamType, EdamConfig } from '../types/Options'
import { default as normalizeSource, Options } from './normalizeSource'
import { load } from '../lib/loadConfig'
import extendsMerge from './extendsMerge'
Expand All @@ -19,7 +19,7 @@ import toArray from '../lib/toArray'
import resolve from '../lib/resolve'
import fileSystem from '../lib/fileSystem'
import parseQueryString from '../lib/parseQueryString'
import {platform} from "os";
import { platform } from 'os'

const tildify = require('tildify')
const debug = require('debug')('edam:normalizeConfig')
Expand Down
19 changes: 12 additions & 7 deletions packages/edam/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @description:
*/
import normalizeConfig from './core/normalizeConfig'
import { EdamConfig, Source } from './types/Options'
import {edam as edamType, EdamConfig, Source} from './types/Options'
import { Track } from './core/extendsConfig'
import { Options } from './core/normalizeSource'
import { AwaitEventEmitter, Logger, PromptProcess } from './types/core'
Expand Down Expand Up @@ -245,12 +245,17 @@ export class Edam extends AwaitEventEmitter {
)
}

if (!['npm', 'yarn'].includes(normalized.pull.npmClient)) {
throw new EdamError(
`config.pull.npmClient allows the value which is one of 'npm' | 'yarn'. but ${
normalized.pull.npmClient
}`
)
// if (!['npm', 'yarn'].includes(normalized.pull.npmClient)) {
// throw new EdamError(
// `config.pull.npmClient allows the value which is one of 'npm' | 'yarn'. but ${
// normalized.pull.npmClient
// }`
// )
// }

const unlawfulString = edamType.toUnlawfulString(normalized)
if (unlawfulString) {
throw new EdamError(unlawfulString)
}
}

Expand Down
64 changes: 64 additions & 0 deletions packages/edam/src/types/Options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,69 @@
import { Plugin } from '../core/plugins'

import {
util,
leq,
oneOf,
string,
boolean,
object,
array,
eq,
function_,
any,
LooseEqual
} from 'walli'

const { createVerifiableClass } = util

// console.log(util)

const strictSource = createVerifiableClass({
_check(req: any) {
return leq({
type: oneOf(['file', 'git', 'npm']),
url: string(),
checkout: string().optional(),
version: string().optional()
})._check(req)
},
getDisplayName() {
return 'strictSource'
}
})

const source = createVerifiableClass({
_check(req: any) {
return oneOf([strictSource(), string()])._check(req)
},
getDisplayName() {
return 'source'
}
})

export const rc: LooseEqual = leq({
source: source().optional(),
cacheDir: oneOf([boolean(), string()]).optional(),
alias: object(source()).optional(),
extends: oneOf([string(), array(string())]).optional(),
output: string().optional(),
plugins: array(eq([function_(), any()])).optional(),
pull: leq({
npmClient: oneOf(['yarn', 'npm']).optional(),
git: oneOf(['clone', 'download']).optional()
}).optional(),
storePrompts: boolean().optional()
})

export const edam = rc.assign(
leq({
name: string().optional(),
updateNotify: boolean().optional(),
yes: boolean().optional(),
silent: boolean().optional()
})
)

export type Source = {
type: 'file' | 'git' | 'npm'
url: string
Expand Down

0 comments on commit dc64a1e

Please sign in to comment.