Skip to content

Commit 6bf82f9

Browse files
committed
fix: i18n initilize errors
1 parent f102d1a commit 6bf82f9

File tree

3 files changed

+125
-126
lines changed

3 files changed

+125
-126
lines changed

src/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { compile, annotate } from './commands'
1010
yargs(hideBin(process.argv))
1111
.scriptName('intlify')
1212
.usage(t('Usage: $0 <command> [options]'))
13-
.command(compile)
14-
.command(annotate)
13+
.command(compile())
14+
.command(annotate())
1515
.demandCommand()
1616
.help()
1717
.version().argv

src/commands/annotate.ts

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,47 @@ type AnnocateMode = 'custom-block'
1212
type AnnotateOptions = {
1313
target: string
1414
mode: string
15-
attrs: string
15+
attrs: Record<string, any>
1616
}
1717

18-
export const command = 'annotate'
19-
export const aliases = 'at'
20-
export const describe = t('annotate the attributes')
21-
22-
export const builder = (args: Argv): Argv<AnnotateOptions> => {
23-
return args
24-
.option('target', {
25-
type: 'string',
26-
alias: 't',
27-
describe: t('the target path'),
28-
demandOption: true
29-
})
30-
.option('mode', {
31-
type: 'string',
32-
alias: 'm',
33-
default: 'custom-block',
34-
describe: t('the annotation mode')
35-
})
36-
.option('attrs', {
37-
type: 'string',
38-
alias: 'a',
39-
default: '{}',
40-
describe: t('the attributes to annotate')
41-
})
42-
}
43-
44-
export const handler = async (
45-
args: Arguments<AnnotateOptions>
46-
): Promise<void> => {
47-
const ret = false
48-
const { target, mode, attrs } = args
49-
console.log('anntate args', target, mode, attrs)
50-
debug('annotate: ', ret)
51-
}
52-
53-
export default {
54-
command,
55-
aliases,
56-
describe,
57-
builder,
58-
handler
18+
export default function deineCommand() {
19+
const command = 'annotate'
20+
const aliases = 'at'
21+
const describe = t('annotate the attributes')
22+
23+
const builder = (args: Argv): Argv<AnnotateOptions> => {
24+
return args
25+
.option('target', {
26+
type: 'string',
27+
alias: 't',
28+
describe: t('the target path'),
29+
demandOption: true
30+
})
31+
.option('mode', {
32+
type: 'string',
33+
alias: 'm',
34+
default: 'custom-block',
35+
describe: t('the annotation mode')
36+
})
37+
.option('attrs', {
38+
alias: 'a',
39+
default: {},
40+
describe: t('the attributes to annotate')
41+
})
42+
}
43+
44+
const handler = async (args: Arguments<AnnotateOptions>): Promise<void> => {
45+
const ret = false
46+
const { target, mode, attrs } = args
47+
console.log('anntate args', target, mode, attrs)
48+
debug('annotate: ', ret)
49+
}
50+
51+
return {
52+
command,
53+
aliases,
54+
describe,
55+
builder,
56+
handler
57+
}
5958
}

src/commands/compile.ts

Lines changed: 82 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -16,94 +16,94 @@ type CompileOptions = {
1616
mode?: string
1717
}
1818

19-
export const command = 'compile'
20-
export const aliases = 'cp'
21-
export const describe = t('compile the i18n resources')
19+
export default function defineCommand() {
20+
const command = 'compile'
21+
const aliases = 'cp'
22+
const describe = t('compile the i18n resources')
2223

23-
export const builder = (args: Argv): Argv<CompileOptions> => {
24-
return args
25-
.option('source', {
26-
type: 'string',
27-
alias: 's',
28-
describe: t('the i18n resource source path'),
29-
demandOption: true
30-
})
31-
.option('output', {
32-
type: 'string',
33-
alias: 'o',
34-
describe: t('the compiled i18n resource output path')
35-
})
36-
.option('mode', {
37-
type: 'string',
38-
alias: 'm',
39-
default: 'production',
40-
describe: t(
41-
"the compiled i18n resource mode, 'production' or 'development' (default: 'production')"
42-
)
43-
})
44-
}
24+
const builder = (args: Argv): Argv<CompileOptions> => {
25+
return args
26+
.option('source', {
27+
type: 'string',
28+
alias: 's',
29+
describe: t('the i18n resource source path'),
30+
demandOption: true
31+
})
32+
.option('output', {
33+
type: 'string',
34+
alias: 'o',
35+
describe: t('the compiled i18n resource output path')
36+
})
37+
.option('mode', {
38+
type: 'string',
39+
alias: 'm',
40+
default: 'production',
41+
describe: t(
42+
"the compiled i18n resource mode, 'production' or 'development' (default: 'production')"
43+
)
44+
})
45+
}
4546

46-
export const handler = async (
47-
args: Arguments<CompileOptions>
48-
): Promise<void> => {
49-
const output =
50-
args.output != null ? path.resolve(dirname, args.output) : process.cwd()
51-
const ret = await compile(args.source, output, {
52-
mode: args.mode as DevEnv,
53-
onCompile: (source: string, output: string): void => {
54-
console.log(
55-
chalk.green(
56-
t('Success compilation: {source} -> {output}', { source, output })
47+
const handler = async (args: Arguments<CompileOptions>): Promise<void> => {
48+
const output =
49+
args.output != null ? path.resolve(dirname, args.output) : process.cwd()
50+
const ret = await compile(args.source, output, {
51+
mode: args.mode as DevEnv,
52+
onCompile: (source: string, output: string): void => {
53+
console.log(
54+
chalk.green(
55+
t('Success compilation: {source} -> {output}', { source, output })
56+
)
5757
)
58-
)
59-
},
60-
onError: (
61-
code: number,
62-
source: string,
63-
output: string,
64-
msg?: string
65-
): void => {
66-
switch (code) {
67-
case CompileErrorCodes.NOT_SUPPORTED_FORMAT:
68-
const parsed = path.parse(source)
69-
console.warn(
70-
chalk.yellow(
71-
t("{source}: Ignore compilation due to not supported '{ext}'", {
72-
named: { ext: parsed.ext }
73-
})
58+
},
59+
onError: (
60+
code: number,
61+
source: string,
62+
output: string,
63+
msg?: string
64+
): void => {
65+
switch (code) {
66+
case CompileErrorCodes.NOT_SUPPORTED_FORMAT:
67+
const parsed = path.parse(source)
68+
console.warn(
69+
chalk.yellow(
70+
t("{source}: Ignore compilation due to not supported '{ext}'", {
71+
named: { ext: parsed.ext }
72+
})
73+
)
7474
)
75-
)
76-
break
77-
case CompileErrorCodes.INTERNAL_COMPILE_WARNING:
78-
console.log(
79-
chalk.yellow(
80-
t('Warning compilation: {source} -> {output}, {msg}', {
81-
named: { source, output, msg }
82-
})
75+
break
76+
case CompileErrorCodes.INTERNAL_COMPILE_WARNING:
77+
console.log(
78+
chalk.yellow(
79+
t('Warning compilation: {source} -> {output}, {msg}', {
80+
named: { source, output, msg }
81+
})
82+
)
8383
)
84-
)
85-
break
86-
case CompileErrorCodes.INTERNAL_COMPILE_ERROR:
87-
console.log(
88-
chalk.green(
89-
t('Error compilation: {source} -> {output}, {msg}', {
90-
named: { source, output, msg }
91-
})
84+
break
85+
case CompileErrorCodes.INTERNAL_COMPILE_ERROR:
86+
console.log(
87+
chalk.green(
88+
t('Error compilation: {source} -> {output}, {msg}', {
89+
named: { source, output, msg }
90+
})
91+
)
9292
)
93-
)
94-
break
95-
default:
96-
break
93+
break
94+
default:
95+
break
96+
}
9797
}
98-
}
99-
})
100-
debug('compile: ', ret)
101-
}
98+
})
99+
debug('compile: ', ret)
100+
}
102101

103-
export default {
104-
command,
105-
aliases,
106-
describe,
107-
builder,
108-
handler
102+
return {
103+
command,
104+
aliases,
105+
describe,
106+
builder,
107+
handler
108+
}
109109
}

0 commit comments

Comments
 (0)