Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 15 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
node_modules/*
packages/**/node_modules/*
packages/**/dist/*
packages/**/build/*
packages/**/lib/*

packages/devui-vue/devui/accordion/src/accordion-open-icon.tsx
packages/devui-vue/devui/auto-complete/src/auto-complete.tsx
packages/devui-vue/devui/editable-select/src/editable-select.tsx
packages/devui-vue/devui/gantt/src/gantt-milestone/milestone-icon.tsx
packages/devui-vue/devui/modal/src/modal.tsx
packages/devui-vue/devui/pagination/src/components/jump-page.tsx
packages/devui-vue/devui/search/src/search.tsx
packages/devui-vue/devui/table/src/header/filter/filter.tsx
packages/devui-vue/devui/table/src/header/sort/sort.tsx
6 changes: 3 additions & 3 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Pull Request

on:
push:
branches: [ dev, main ]
branches: [ dev, main, 1.0.0 ]
pull_request:
branches: [ dev, main ]
branches: [ dev, main, 1.0.0 ]

jobs:
build:
Expand Down Expand Up @@ -38,4 +38,4 @@ jobs:
run: pnpm build

# - name: Test vue-devui
# run: yarn test
# run: pnpm test
26 changes: 13 additions & 13 deletions packages/devui-cli/src/bin.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/usr/bin/env node
import { Command } from 'commander'
import type { CliConfig } from '../types/config'
import baseAction from './commands/base'
import createAction, { validateCreateType } from './commands/create'
import { detectCliConfig } from './shared/config'
import { VERSION } from './shared/constant'
import { Command } from 'commander';
import type { CliConfig } from '../types/config';
import baseAction from './commands/base';
import createAction, { validateCreateType } from './commands/create';
import { detectCliConfig } from './shared/config';
import { VERSION } from './shared/constant';
import {
DEFAULT_CLI_CONFIG_FILE_NAME
} from './shared/generate-config'
} from './shared/generate-config';

// detect cli config
detectCliConfig()
detectCliConfig();

const program = new Command()
const program = new Command();

program
.command('create [name...]')
Expand All @@ -26,7 +26,7 @@ program
.option('--directive', 'Include service when creating a component.')
.option('-f --force', 'For force overwriting.')
.description('Create a component structure, library entry file or other...')
.action(createAction)
.action(createAction);

program
.option('--init', 'Initialize the cli configuration file in the current working directory.')
Expand All @@ -37,10 +37,10 @@ program
.usage('[command] [options]')
.version(VERSION, '-v --version')
.description('Cli of devui.')
.action(baseAction)
.action(baseAction);

program.parse(process.argv)
program.parse(process.argv);

export function defineCliConfig(config: Partial<CliConfig> = {}) {
return config
return config;
}
8 changes: 4 additions & 4 deletions packages/devui-cli/src/commands/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import buildAction from './build';
import createAction from './create';

function getActions() {
const actionMap = new Map<string, prompts.Choice & { action: Function; }>();
const actionMap = new Map<string, prompts.Choice & { action: Function }>();
actionMap.set('create', {
title: 'create',
value: 'create',
Expand All @@ -23,8 +23,8 @@ function getActions() {
}

export type BaseCmd = {
init?: boolean
config?: string
init?: boolean;
config?: string;
};

export default async function baseAction(cmd: BaseCmd) {
Expand All @@ -38,7 +38,7 @@ export default async function baseAction(cmd: BaseCmd) {
}

export function loadCliConfig(cmd: Pick<BaseCmd, 'config'>) {
if (!cmd.config) return;
if (!cmd.config) {return;}

const configPath = resolve(CWD, cmd.config);

Expand Down
2 changes: 1 addition & 1 deletion packages/devui-cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ function buildAction() {

}

export default buildAction
export default buildAction;
62 changes: 31 additions & 31 deletions packages/devui-cli/src/commands/create-component.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import prompts from 'prompts'
import { cliConfig } from '../shared/config'
import genComponent from '../shared/generate-component'
import logger from '../shared/logger'
import { canSafelyOverwrite, onPromptsCancel, resolveComponentDir } from '../shared/utils'
import { CreateCMD } from './create'
import prompts from 'prompts';
import { cliConfig } from '../shared/config';
import genComponent from '../shared/generate-component';
import logger from '../shared/logger';
import { canSafelyOverwrite, onPromptsCancel, resolveComponentDir } from '../shared/utils';
import { CreateCMD } from './create';

export function isValidComponentName(name: string) {
if (!name) return false
if (!name) {return false;}

const flag = /^[a-zA-Z]([\w-\d]*)$/.test(name)
const flag = /^[a-zA-Z]([\w-\d]*)$/.test(name);

if (!flag) {
logger.warn(`The component name "${name}" is invalid.`)
logger.info(`The component name rule: letters, numbers, "-", and must start with a letter.`)
logger.warn(`The component name "${name}" is invalid.`);
logger.info(`The component name rule: letters, numbers, "-", and must start with a letter.`);
}

return flag
return flag;
}

export default async function createComponentAction(names: string[] = [], cmd: CreateCMD = {}) {
let [name = '', title = '', category = ''] = names
const parts = []
let targetDir = resolveComponentDir(name)
let [name = '', title = '', category = ''] = names;
const parts = [];
let targetDir = resolveComponentDir(name);

cmd.core && parts.push('core')
cmd.service && parts.push('service')
cmd.directive && parts.push('directive')
cmd.core && parts.push('core');
cmd.service && parts.push('service');
cmd.directive && parts.push('directive');

if (!isValidComponentName(name)) {
name = ''
targetDir = ''
name = '';
targetDir = '';
}

try {
Expand All @@ -40,31 +40,31 @@ export default async function createComponentAction(names: string[] = [], cmd: C
type: () => (name ? null : 'text'),
message: 'Component name:',
validate: () => {
console.log('') // 防止错误输出于同一行
console.log(''); // 防止错误输出于同一行

const isValid = isValidComponentName(name)
const isValid = isValidComponentName(name);

return isValid
return isValid;
},
onState: (state) => {
name = String(state.value).trim()
targetDir = resolveComponentDir(name)
name = String(state.value).trim();
targetDir = resolveComponentDir(name);
}
},
{
name: 'shouldOverwrite',
type: () => (canSafelyOverwrite(targetDir) || cmd.force ? null : 'confirm'),
message: () => {
return `Target directory "${targetDir}" is not empty. Remove existing files and continue?`
return `Target directory "${targetDir}" is not empty. Remove existing files and continue?`;
}
},
{
name: 'overwriteChecker',
type: (prev, values: any = {}) => {
if (values.shouldOverwrite === false) {
throw new Error('Operation cancelled')
throw new Error('Operation cancelled');
}
return null
return null;
}
},
{
Expand Down Expand Up @@ -112,17 +112,17 @@ export default async function createComponentAction(names: string[] = [], cmd: C
}
],
{ onCancel: onPromptsCancel }
)
);

genComponent({
name,
title,
category: meta.category ?? category,
parts: meta.parts ?? parts,
dir: targetDir
})
});
} catch (e: any) {
logger.error(e.message)
process.exit(1)
logger.error(e.message);
process.exit(1);
}
}
16 changes: 8 additions & 8 deletions packages/devui-cli/src/commands/create-lib-entry.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { cliConfig } from '../shared/config'
import genLibEntry from '../shared/generate-lib-entry'
import logger from '../shared/logger'
import { resolveLibEntryDir } from '../shared/utils'
import { CreateCMD } from './create'
import { cliConfig } from '../shared/config';
import genLibEntry from '../shared/generate-lib-entry';
import logger from '../shared/logger';
import { resolveLibEntryDir } from '../shared/utils';
import { CreateCMD } from './create';

export default async function createLibEntryAction(names: string[] = [], cmd: CreateCMD) {
try {
const [name = cliConfig.libEntryFileName] = names
genLibEntry(resolveLibEntryDir(name))
const [name = cliConfig.libEntryFileName] = names;
genLibEntry(resolveLibEntryDir(name));
} catch (e: any) {
logger.error(e.message)
logger.error(e.message);
}
}
58 changes: 29 additions & 29 deletions packages/devui-cli/src/commands/create.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
import prompts from 'prompts'
import logger from '../shared/logger'
import { onPromptsCancel } from '../shared/utils'
import { loadCliConfig } from './base'
import createComponentAction from './create-component'
import createLibEntryAction from './create-lib-entry'
import prompts from 'prompts';
import logger from '../shared/logger';
import { onPromptsCancel } from '../shared/utils';
import { loadCliConfig } from './base';
import createComponentAction from './create-component';
import createLibEntryAction from './create-lib-entry';

export type CreateCMD = {
config?: string
type?: keyof typeof CREATE_TYPE_ACTION
core?: boolean
service?: boolean
directive?: boolean
force?: boolean
}
config?: string;
type?: keyof typeof CREATE_TYPE_ACTION;
core?: boolean;
service?: boolean;
directive?: boolean;
force?: boolean;
};

const CREATE_TYPES = ['component', 'component-test', 'component-doc', 'lib-entry', 'doc-nav']
const UNFINISHED_CREATE_TYPES = ['component-test', 'component-doc', 'doc-nav']
const CREATE_TYPES = ['component', 'component-test', 'component-doc', 'lib-entry', 'doc-nav'];
const UNFINISHED_CREATE_TYPES = ['component-test', 'component-doc', 'doc-nav'];
const CREATE_TYPE_ACTION = {
component: createComponentAction,
'lib-entry': createLibEntryAction
}
};

export function validateCreateType(type: string) {
const valid = CREATE_TYPES.includes(type)
const valid = CREATE_TYPES.includes(type);

if (!valid) {
logger.error(`Create type error!.`)
logger.error(`Create type error!.`);
logger.info(
`Optional type list: ${CREATE_TYPES.map((type) =>
UNFINISHED_CREATE_TYPES.includes(type) ? `${type}(Unfinished)` : type
).join(', ')}`
)
);
}

return valid ? type : ''
return valid ? type : '';
}

export default async function createAction(names: string[] = [], cmd: CreateCMD = {}) {
loadCliConfig(cmd)
loadCliConfig(cmd);

let { type } = cmd
let { type } = cmd;

if (!type) {
try {
Expand All @@ -59,19 +59,19 @@ export default async function createAction(names: string[] = [], cmd: CreateCMD
{
onCancel: onPromptsCancel
}
)
);

type = result.type
type = result.type;
} catch (e: any) {
logger.error(e.message)
process.exit(1)
logger.error(e.message);
process.exit(1);
}
}

const action = CREATE_TYPE_ACTION[type!]
const action = CREATE_TYPE_ACTION[type!];
if (action) {
action(names, cmd)
action(names, cmd);
} else {
logger.warn('Sorry! The type is not completed.')
logger.warn('Sorry! The type is not completed.');
}
}
26 changes: 13 additions & 13 deletions packages/devui-cli/src/shared/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { readdirSync, statSync } from 'fs-extra'
import { merge } from 'lodash-es'
import { resolve } from 'path'
import type { CliConfig } from '../../types/config'
import { loadCliConfig } from '../commands/base'
import { CWD } from './constant'
import { DEFAULT_CLI_CONFIG_NAME } from './generate-config'
import { readdirSync, statSync } from 'fs-extra';
import { merge } from 'lodash-es';
import { resolve } from 'path';
import type { CliConfig } from '../../types/config';
import { loadCliConfig } from '../commands/base';
import { CWD } from './constant';
import { DEFAULT_CLI_CONFIG_NAME } from './generate-config';

export const cliConfig: CliConfig = {
cwd: CWD,
Expand All @@ -16,17 +16,17 @@ export const cliConfig: CliConfig = {
libEntryRootDir: '.',
libEntryFileName: 'index',
version: '0.0.0'
}
};

export function mergeCliConfig(config: Partial<CliConfig> = {}) {
return merge(cliConfig, config)
return merge(cliConfig, config);
}

export function detectCliConfig() {
const re = new RegExp(`^${DEFAULT_CLI_CONFIG_NAME}\.(js|ts)$`)
const file = readdirSync(CWD).find((f) => statSync(resolve(CWD, f)).isFile() && re.test(f))
const re = new RegExp(`^${DEFAULT_CLI_CONFIG_NAME}\.(js|ts)$`);
const file = readdirSync(CWD).find((f) => statSync(resolve(CWD, f)).isFile() && re.test(f));

if (!file) return
if (!file) {return;}

loadCliConfig({ config: resolve(CWD, file) })
loadCliConfig({ config: resolve(CWD, file) });
}
Loading