Skip to content

Commit

Permalink
refactor(shared): integrated rattail
Browse files Browse the repository at this point in the history
  • Loading branch information
haoziqaq committed Oct 29, 2024
1 parent 9eee407 commit 08a8003
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 400 deletions.
6 changes: 3 additions & 3 deletions packages/varlet-cli/site/mobile/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ import { computed, defineComponent, ref, watch, type Ref, type ComputedRef } fro
import { useRoute } from 'vue-router'
import { getBrowserTheme, watchLang, watchTheme, setTheme, getMobileIndex, type Theme } from '@varlet/cli/client'
import { removeEmpty, inIframe, isPhone } from '../utils'
import { bigCamelize } from '@varlet/shared'
import { pascalCase } from '@varlet/shared'
export default defineComponent({
setup() {
Expand Down Expand Up @@ -147,8 +147,8 @@ export default defineComponent({
watch(
() => route.path,
(to: string) => {
const componentName = bigCamelize(to.slice(1))
const redirectName = bigCamelize(redirect.slice(1))
const componentName = pascalCase(to.slice(1))
const redirectName = pascalCase(redirect.slice(1))
bigCamelizeComponentName.value = componentName === redirectName ? '' : componentName
showBackIcon.value = componentName !== redirectName
}
Expand Down
8 changes: 4 additions & 4 deletions packages/varlet-cli/src/node/commands/create.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ejs from 'ejs'
import fse from 'fs-extra'
import logger from '../shared/logger.js'
import { bigCamelize, camelize, kebabCase } from '@varlet/shared'
import { pascalCase, camelize, kebabCase } from '@varlet/shared'
import { input, confirm, select } from '@inquirer/prompts'
import { resolve } from 'path'
import { glob } from '../shared/fsUtils.js'
Expand Down Expand Up @@ -38,7 +38,7 @@ async function renderTemplates(componentFolder: string, componentFolderName: str
const code = ejs.render(templateCode, renderData)
const file = template
.replace('[componentName]', camelize(componentFolderName))
.replace('[ComponentName]', bigCamelize(componentFolderName))
.replace('[ComponentName]', pascalCase(componentFolderName))
.replace('.ejs', '')

writeFileSync(file, code)
Expand All @@ -52,7 +52,7 @@ export async function create(options: CreateCommandOptions) {
const { namespace } = await getVarletConfig()
const renderData: RenderData = {
namespace,
bigCamelizeNamespace: bigCamelize(namespace),
bigCamelizeNamespace: pascalCase(namespace),
kebabCaseName: 'component-name',
bigCamelizeName: 'ComponentName',
camelizeName: 'componentName',
Expand All @@ -68,7 +68,7 @@ export async function create(options: CreateCommandOptions) {

renderData.kebabCaseName = kebabCase(name)
renderData.camelizeName = camelize(name)
renderData.bigCamelizeName = bigCamelize(name)
renderData.bigCamelizeName = pascalCase(name)
const componentFolder = resolve(SRC_DIR, renderData.kebabCaseName)
const componentFolderName = renderData.kebabCaseName

Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-cli/src/node/compiler/compileScript.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ES_DIR } from '../shared/constant.js'
import { transformAsync } from '@babel/core'
import { bigCamelize } from '@varlet/shared'
import { pascalCase } from '@varlet/shared'
import { getVersion, isDir, isJsx, isTsx, replaceExt } from '../shared/fsUtils.js'
import { extractStyleDependencies, IMPORT_CSS_RE, IMPORT_LESS_RE, IMPORT_SCSS_RE } from './compileStyle.js'
import { resolve, relative, extname, dirname } from 'path'
Expand Down Expand Up @@ -202,7 +202,7 @@ export function generateEsEntryTemplate(options: GenerateEsEntryTemplateOptions)
const publicComponents: string[] = []

publicDirs.forEach((dirname: string) => {
const publicComponent = bigCamelize(dirname)
const publicComponent = pascalCase(dirname)
const module = `'${root}${dirname}/index${scriptExtname}'`

publicComponents.push(publicComponent)
Expand Down
6 changes: 3 additions & 3 deletions packages/varlet-cli/src/node/compiler/compileTypes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fse from 'fs-extra'
import { TYPES_DIR, UI_PACKAGE_JSON } from '../shared/constant.js'
import { bigCamelize } from '@varlet/shared'
import { pascalCase } from '@varlet/shared'
import { resolve, relative } from 'path'
import { getVarletConfig } from '../config/varlet.config.js'
import { compileStyleVars } from './compileStyleVars.js'
Expand Down Expand Up @@ -31,7 +31,7 @@ export async function compileTypes() {

includeFilenames.forEach((filename) => {
const folder = filename.replace('.d.ts', '')
const name = bigCamelize(folder)
const name = pascalCase(folder)

exports.push(`export * from './${folder}'`)

Expand All @@ -43,7 +43,7 @@ export async function compileTypes() {
if (directives.includes(folder)) {
directiveDeclares.push(`v${name}: typeof import('${libraryName}')['_${name}Component']`)
} else {
componentDeclares.push(`${bigCamelize(namespace)}${name}: typeof import('${libraryName}')['_${name}Component']`)
componentDeclares.push(`${pascalCase(namespace)}${name}: typeof import('${libraryName}')['_${name}Component']`)
}
})

Expand Down
3 changes: 3 additions & 0 deletions packages/varlet-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
"dev": "tsup src/index.ts --format esm --out-dir=lib --watch --dts",
"build": "tsup src/index.ts --format esm,cjs --out-dir=lib --dts --clean"
},
"dependencies": {
"rattail": "0.0.4"
},
"devDependencies": {
"@types/node": "^18.7.18",
"typescript": "^5.1.5",
Expand Down
55 changes: 0 additions & 55 deletions packages/varlet-shared/src/array.ts

This file was deleted.

106 changes: 0 additions & 106 deletions packages/varlet-shared/src/elements.ts

This file was deleted.

55 changes: 0 additions & 55 deletions packages/varlet-shared/src/function.ts

This file was deleted.

7 changes: 1 addition & 6 deletions packages/varlet-shared/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
export * from './array.js'
export * from './elements.js'
export * from './function.js'
export * from './is.js'
export * from './number.js'
export * from './string.js'
export * from './merge.js'
export * from 'rattail'
35 changes: 0 additions & 35 deletions packages/varlet-shared/src/is.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,7 @@
export const isString = (val: unknown): val is string => typeof val === 'string'

export const isBoolean = (val: unknown): val is boolean => typeof val === 'boolean'

export const isNumber = (val: unknown): val is number => typeof val === 'number'

export const isNumeric = (val: unknown): val is number | string =>
isNumber(val) || (isString(val) && /^[-+]?\d+$/.test(val))

export const isPlainObject = (val: unknown): val is Record<string, any> =>
Object.prototype.toString.call(val) === '[object Object]'

export const isObject = (val: unknown): val is Record<string, any> => typeof val === 'object' && val !== null

// eslint-disable-next-line
export const isFunction = (val: unknown): val is Function => typeof val === 'function'

export const isArray = (val: unknown): val is Array<any> => Array.isArray(val)

export const isURL = (val: string | undefined | null) => {
if (!val) {
return false
}

return /^(http)|(\.*\/)/.test(val)
}

export const isEmpty = (val: unknown) =>
val === undefined || val === null || val === '' || (isArray(val) && !val.length)

export const isWindow = (val: unknown): val is Window => val === window

export const supportTouch = () => inBrowser() && 'ontouchstart' in window

export const inBrowser = () => typeof window !== 'undefined'

export const inMobile = () =>
inBrowser() && /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)

const { hasOwnProperty } = Object.prototype

export const hasOwn = <T extends object>(val: T, key: PropertyKey): key is keyof T => hasOwnProperty.call(val, key)
Loading

0 comments on commit 08a8003

Please sign in to comment.