|
1 | 1 | import { Arguments, Argv } from 'yargs'
|
2 |
| -import querystring from 'query-string' |
3 | 2 |
|
4 |
| -import { |
5 |
| - resolveProviderConf, |
6 |
| - loadProvider, |
7 |
| - loadProviderConf, |
8 |
| - DEFUALT_CONF, |
9 |
| - getLocaleMessages |
10 |
| -} from '../utils' |
11 |
| - |
12 |
| -import { PushableOptions } from '../../types' |
13 |
| - |
14 |
| -type PushOptions = { |
15 |
| - provider: string |
16 |
| - conf?: string |
17 |
| - normalize?: string |
18 |
| - dryRun: boolean |
19 |
| - providerArgs?: string |
20 |
| -} & PushableOptions |
| 3 | +import { pushFunc } from '../utils' |
| 4 | +import { PushOptions } from '../../types' |
21 | 5 |
|
22 | 6 | export const command = 'push'
|
23 | 7 | export const aliases = 'ph'
|
@@ -75,36 +59,14 @@ export const builder = (args: Argv): Argv<PushOptions> => {
|
75 | 59 | }
|
76 | 60 |
|
77 | 61 | export const handler = async (args: Arguments<PushOptions>): Promise<unknown> => {
|
78 |
| - const { dryRun, normalize, providerArgs } = args |
79 |
| - const ProviderFactory = loadProvider(args.provider) |
80 |
| - |
81 |
| - if (ProviderFactory === null) { |
82 |
| - // TODO: should refactor console message |
83 |
| - console.log(`Not found ${args.provider} provider`) |
84 |
| - return |
85 |
| - } |
86 |
| - |
87 |
| - if (!args.target && !args.targetPaths) { |
88 |
| - // TODO: should refactor console message |
89 |
| - console.log('You need to specify either --target or --target-paths') |
90 |
| - return |
91 |
| - } |
92 |
| - |
93 |
| - const confPath = resolveProviderConf(args.provider, args.conf) |
94 |
| - const conf = loadProviderConf(confPath) || DEFUALT_CONF |
| 62 | + const { provider, conf, normalize, dryRun, providerArgs, target, locale, targetPaths, filenameMatch } = args |
95 | 63 |
|
96 | 64 | try {
|
97 |
| - const messages = getLocaleMessages(args) |
98 |
| - const provider = ProviderFactory(conf) |
99 |
| - await provider.push({ |
100 |
| - messages, dryRun, normalize, |
101 |
| - providerArgs: providerArgs !== undefined ? querystring.parse(providerArgs) : undefined |
102 |
| - }) |
| 65 | + await pushFunc({ provider, conf, normalize, dryRun, providerArgs, target, locale, targetPaths, filenameMatch }) |
103 | 66 | // TODO: should refactor console message
|
104 | 67 | console.log('push success')
|
105 |
| - } catch (e) { |
106 |
| - // TODO: should refactor console message |
107 |
| - console.error('push fail:', e.message) |
| 68 | + } catch { |
| 69 | + return |
108 | 70 | }
|
109 | 71 | }
|
110 | 72 |
|
|
0 commit comments