@localheroai/cli 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README +1 -1
- package/dist/api/auth.d.ts +2 -0
- package/dist/api/auth.js +28 -0
- package/dist/api/auth.js.map +1 -0
- package/dist/api/client.d.ts +3 -0
- package/dist/api/client.js +80 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/imports.d.ts +5 -0
- package/dist/api/imports.js +43 -0
- package/dist/api/imports.js.map +1 -0
- package/dist/api/projects.d.ts +2 -0
- package/dist/api/projects.js +42 -0
- package/dist/api/projects.js.map +1 -0
- package/dist/api/translations.d.ts +15 -0
- package/dist/api/translations.js +71 -0
- package/dist/api/translations.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +79 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/_sync.js +22 -0
- package/dist/commands/_sync.js.map +1 -0
- package/dist/commands/_translate.js +3 -0
- package/dist/commands/_translate.js.map +1 -0
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.js +439 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/login.d.ts +16 -0
- package/dist/commands/login.js +58 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/pull.js +22 -0
- package/dist/commands/pull.js.map +1 -0
- package/dist/commands/push.js +56 -0
- package/dist/commands/push.js.map +1 -0
- package/dist/commands/sync.d.ts +20 -0
- package/dist/commands/sync.js +22 -0
- package/dist/commands/sync.js.map +1 -0
- package/dist/commands/translate.d.ts +14 -0
- package/dist/commands/translate.js +145 -0
- package/dist/commands/translate.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +75 -0
- package/dist/types/index.js +17 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/translate/index.js +2 -0
- package/dist/types/translate/index.js.map +1 -0
- package/dist/utils/auth.d.ts +2 -0
- package/dist/utils/auth.js +29 -0
- package/dist/utils/auth.js.map +1 -0
- package/dist/utils/common.js +9 -0
- package/dist/utils/common.js.map +1 -0
- package/dist/utils/config.d.ts +23 -0
- package/dist/utils/config.js +137 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/errors.js +37 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/files.d.ts +32 -0
- package/dist/utils/files.js +347 -0
- package/dist/utils/files.js.map +1 -0
- package/dist/utils/git.d.ts +21 -0
- package/dist/utils/git.js +87 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/github.d.ts +241 -0
- package/dist/utils/github.js +161 -0
- package/dist/utils/github.js.map +1 -0
- package/dist/utils/import-service.d.ts +4 -0
- package/dist/utils/import-service.js +218 -0
- package/dist/utils/import-service.js.map +1 -0
- package/dist/utils/prompt-service.d.ts +44 -0
- package/dist/utils/prompt-service.js +104 -0
- package/dist/utils/prompt-service.js.map +1 -0
- package/dist/utils/sync-service.d.ts +58 -0
- package/dist/utils/sync-service.js +159 -0
- package/dist/utils/sync-service.js.map +1 -0
- package/dist/utils/translation-processor.js +197 -0
- package/dist/utils/translation-processor.js.map +1 -0
- package/dist/utils/translation-updater/common.d.ts +6 -0
- package/{src → dist}/utils/translation-updater/common.js +16 -10
- package/dist/utils/translation-updater/common.js.map +1 -0
- package/dist/utils/translation-updater/index.d.ts +5 -0
- package/{src → dist}/utils/translation-updater/index.js +21 -9
- package/dist/utils/translation-updater/index.js.map +1 -0
- package/dist/utils/translation-updater/json-handler.d.ts +5 -0
- package/dist/utils/translation-updater/json-handler.js +123 -0
- package/dist/utils/translation-updater/json-handler.js.map +1 -0
- package/dist/utils/translation-updater/yaml-handler.d.ts +5 -0
- package/dist/utils/translation-updater/yaml-handler.js +180 -0
- package/dist/utils/translation-updater/yaml-handler.js.map +1 -0
- package/dist/utils/translation-utils.d.ts +30 -0
- package/dist/utils/translation-utils.js +324 -0
- package/dist/utils/translation-utils.js.map +1 -0
- package/dist/utils/updater.js +38 -0
- package/dist/utils/updater.js.map +1 -0
- package/package.json +26 -26
- package/src/api/auth.js +0 -24
- package/src/api/client.js +0 -83
- package/src/api/imports.js +0 -22
- package/src/api/projects.js +0 -24
- package/src/api/translations.js +0 -58
- package/src/cli.js +0 -78
- package/src/commands/init.js +0 -485
- package/src/commands/login.js +0 -80
- package/src/commands/sync.js +0 -28
- package/src/commands/translate.js +0 -267
- package/src/utils/auth.js +0 -23
- package/src/utils/config.js +0 -125
- package/src/utils/files.js +0 -381
- package/src/utils/git.js +0 -72
- package/src/utils/github.js +0 -128
- package/src/utils/import-service.js +0 -128
- package/src/utils/prompt-service.js +0 -67
- package/src/utils/sync-service.js +0 -147
- package/src/utils/translation-updater/json-handler.js +0 -111
- package/src/utils/translation-updater/yaml-handler.js +0 -207
- package/src/utils/translation-utils.js +0 -278
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
export function createGitHubActionFile(basePath: any, translationPaths: any): Promise<string>;
|
|
2
|
+
export function workflowExists(basePath: any): boolean;
|
|
3
|
+
export function autoCommitChanges(filesPath: any): void;
|
|
4
|
+
export namespace githubService {
|
|
5
|
+
namespace deps {
|
|
6
|
+
export function exec(cmd: any, options: any): string;
|
|
7
|
+
export let fs: {
|
|
8
|
+
existsSync: typeof existsSync;
|
|
9
|
+
access(path: import("fs").PathLike, mode?: number): Promise<void>;
|
|
10
|
+
copyFile(src: import("fs").PathLike, dest: import("fs").PathLike, mode?: number): Promise<void>;
|
|
11
|
+
open(path: import("fs").PathLike, flags?: string | number, mode?: import("fs").Mode): Promise<fs.FileHandle>;
|
|
12
|
+
rename(oldPath: import("fs").PathLike, newPath: import("fs").PathLike): Promise<void>;
|
|
13
|
+
truncate(path: import("fs").PathLike, len?: number): Promise<void>;
|
|
14
|
+
rmdir(path: import("fs").PathLike, options?: import("fs").RmDirOptions): Promise<void>;
|
|
15
|
+
rm(path: import("fs").PathLike, options?: import("fs").RmOptions): Promise<void>;
|
|
16
|
+
mkdir(path: import("fs").PathLike, options: import("fs").MakeDirectoryOptions & {
|
|
17
|
+
recursive: true;
|
|
18
|
+
}): Promise<string | undefined>;
|
|
19
|
+
mkdir(path: import("fs").PathLike, options?: import("fs").Mode | (import("fs").MakeDirectoryOptions & {
|
|
20
|
+
recursive?: false | undefined;
|
|
21
|
+
}) | null): Promise<void>;
|
|
22
|
+
mkdir(path: import("fs").PathLike, options?: import("fs").Mode | import("fs").MakeDirectoryOptions | null): Promise<string | undefined>;
|
|
23
|
+
readdir(path: import("fs").PathLike, options?: (import("fs").ObjectEncodingOptions & {
|
|
24
|
+
withFileTypes?: false | undefined;
|
|
25
|
+
recursive?: boolean | undefined;
|
|
26
|
+
}) | BufferEncoding | null): Promise<string[]>;
|
|
27
|
+
readdir(path: import("fs").PathLike, options: {
|
|
28
|
+
encoding: "buffer";
|
|
29
|
+
withFileTypes?: false | undefined;
|
|
30
|
+
recursive?: boolean | undefined;
|
|
31
|
+
} | "buffer"): Promise<Buffer[]>;
|
|
32
|
+
readdir(path: import("fs").PathLike, options?: (import("fs").ObjectEncodingOptions & {
|
|
33
|
+
withFileTypes?: false | undefined;
|
|
34
|
+
recursive?: boolean | undefined;
|
|
35
|
+
}) | BufferEncoding | null): Promise<string[] | Buffer[]>;
|
|
36
|
+
readdir(path: import("fs").PathLike, options: import("fs").ObjectEncodingOptions & {
|
|
37
|
+
withFileTypes: true;
|
|
38
|
+
recursive?: boolean | undefined;
|
|
39
|
+
}): Promise<import("fs").Dirent[]>;
|
|
40
|
+
readlink(path: import("fs").PathLike, options?: import("fs").ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
|
|
41
|
+
readlink(path: import("fs").PathLike, options: import("fs").BufferEncodingOption): Promise<Buffer>;
|
|
42
|
+
readlink(path: import("fs").PathLike, options?: import("fs").ObjectEncodingOptions | string | null): Promise<string | Buffer>;
|
|
43
|
+
symlink(target: import("fs").PathLike, path: import("fs").PathLike, type?: string | null): Promise<void>;
|
|
44
|
+
lstat(path: import("fs").PathLike, opts?: import("fs").StatOptions & {
|
|
45
|
+
bigint?: false | undefined;
|
|
46
|
+
}): Promise<import("fs").Stats>;
|
|
47
|
+
lstat(path: import("fs").PathLike, opts: import("fs").StatOptions & {
|
|
48
|
+
bigint: true;
|
|
49
|
+
}): Promise<import("fs").BigIntStats>;
|
|
50
|
+
lstat(path: import("fs").PathLike, opts?: import("fs").StatOptions): Promise<import("fs").Stats | import("fs").BigIntStats>;
|
|
51
|
+
stat(path: import("fs").PathLike, opts?: import("fs").StatOptions & {
|
|
52
|
+
bigint?: false | undefined;
|
|
53
|
+
}): Promise<import("fs").Stats>;
|
|
54
|
+
stat(path: import("fs").PathLike, opts: import("fs").StatOptions & {
|
|
55
|
+
bigint: true;
|
|
56
|
+
}): Promise<import("fs").BigIntStats>;
|
|
57
|
+
stat(path: import("fs").PathLike, opts?: import("fs").StatOptions): Promise<import("fs").Stats | import("fs").BigIntStats>;
|
|
58
|
+
statfs(path: import("fs").PathLike, opts?: import("fs").StatFsOptions & {
|
|
59
|
+
bigint?: false | undefined;
|
|
60
|
+
}): Promise<import("fs").StatsFs>;
|
|
61
|
+
statfs(path: import("fs").PathLike, opts: import("fs").StatFsOptions & {
|
|
62
|
+
bigint: true;
|
|
63
|
+
}): Promise<import("fs").BigIntStatsFs>;
|
|
64
|
+
statfs(path: import("fs").PathLike, opts?: import("fs").StatFsOptions): Promise<import("fs").StatsFs | import("fs").BigIntStatsFs>;
|
|
65
|
+
link(existingPath: import("fs").PathLike, newPath: import("fs").PathLike): Promise<void>;
|
|
66
|
+
unlink(path: import("fs").PathLike): Promise<void>;
|
|
67
|
+
chmod(path: import("fs").PathLike, mode: import("fs").Mode): Promise<void>;
|
|
68
|
+
lchmod(path: import("fs").PathLike, mode: import("fs").Mode): Promise<void>;
|
|
69
|
+
lchown(path: import("fs").PathLike, uid: number, gid: number): Promise<void>;
|
|
70
|
+
lutimes(path: import("fs").PathLike, atime: import("fs").TimeLike, mtime: import("fs").TimeLike): Promise<void>;
|
|
71
|
+
chown(path: import("fs").PathLike, uid: number, gid: number): Promise<void>;
|
|
72
|
+
utimes(path: import("fs").PathLike, atime: import("fs").TimeLike, mtime: import("fs").TimeLike): Promise<void>;
|
|
73
|
+
realpath(path: import("fs").PathLike, options?: import("fs").ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
|
|
74
|
+
realpath(path: import("fs").PathLike, options: import("fs").BufferEncodingOption): Promise<Buffer>;
|
|
75
|
+
realpath(path: import("fs").PathLike, options?: import("fs").ObjectEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
|
|
76
|
+
mkdtemp(prefix: string, options?: import("fs").ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
|
|
77
|
+
mkdtemp(prefix: string, options: import("fs").BufferEncodingOption): Promise<Buffer>;
|
|
78
|
+
mkdtemp(prefix: string, options?: import("fs").ObjectEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
|
|
79
|
+
writeFile(file: import("fs").PathLike | fs.FileHandle, data: string | NodeJS.ArrayBufferView | Iterable<string | NodeJS.ArrayBufferView> | AsyncIterable<string | NodeJS.ArrayBufferView> | import("stream"), options?: (import("fs").ObjectEncodingOptions & {
|
|
80
|
+
mode?: import("fs").Mode | undefined;
|
|
81
|
+
flag?: import("fs").OpenMode | undefined;
|
|
82
|
+
flush?: boolean | undefined;
|
|
83
|
+
} & import("events").Abortable) | BufferEncoding | null): Promise<void>;
|
|
84
|
+
appendFile(path: import("fs").PathLike | fs.FileHandle, data: string | Uint8Array, options?: (import("fs").ObjectEncodingOptions & fs.FlagAndOpenMode & {
|
|
85
|
+
flush?: boolean | undefined;
|
|
86
|
+
}) | BufferEncoding | null): Promise<void>;
|
|
87
|
+
readFile(path: import("fs").PathLike | fs.FileHandle, options?: ({
|
|
88
|
+
encoding?: null | undefined;
|
|
89
|
+
flag?: import("fs").OpenMode | undefined;
|
|
90
|
+
} & import("events").Abortable) | null): Promise<Buffer>;
|
|
91
|
+
readFile(path: import("fs").PathLike | fs.FileHandle, options: ({
|
|
92
|
+
encoding: BufferEncoding;
|
|
93
|
+
flag?: import("fs").OpenMode | undefined;
|
|
94
|
+
} & import("events").Abortable) | BufferEncoding): Promise<string>;
|
|
95
|
+
readFile(path: import("fs").PathLike | fs.FileHandle, options?: (import("fs").ObjectEncodingOptions & import("events").Abortable & {
|
|
96
|
+
flag?: import("fs").OpenMode | undefined;
|
|
97
|
+
}) | BufferEncoding | null): Promise<string | Buffer>;
|
|
98
|
+
opendir(path: import("fs").PathLike, options?: import("fs").OpenDirOptions): Promise<import("fs").Dir>;
|
|
99
|
+
watch(filename: import("fs").PathLike, options: (import("fs").WatchOptions & {
|
|
100
|
+
encoding: "buffer";
|
|
101
|
+
}) | "buffer"): AsyncIterable<fs.FileChangeInfo<Buffer>>;
|
|
102
|
+
watch(filename: import("fs").PathLike, options?: import("fs").WatchOptions | BufferEncoding): AsyncIterable<fs.FileChangeInfo<string>>;
|
|
103
|
+
watch(filename: import("fs").PathLike, options: import("fs").WatchOptions | string): AsyncIterable<fs.FileChangeInfo<string>> | AsyncIterable<fs.FileChangeInfo<Buffer>>;
|
|
104
|
+
cp(source: string | URL, destination: string | URL, opts?: import("fs").CopyOptions): Promise<void>;
|
|
105
|
+
glob(pattern: string | string[]): NodeJS.AsyncIterator<string>;
|
|
106
|
+
glob(pattern: string | string[], opt: import("fs").GlobOptionsWithFileTypes): NodeJS.AsyncIterator<import("fs").Dirent>;
|
|
107
|
+
glob(pattern: string | string[], opt: import("fs").GlobOptionsWithoutFileTypes): NodeJS.AsyncIterator<string>;
|
|
108
|
+
glob(pattern: string | string[], opt: import("fs").GlobOptions): NodeJS.AsyncIterator<import("fs").Dirent | string>;
|
|
109
|
+
constants: typeof import("fs").constants;
|
|
110
|
+
};
|
|
111
|
+
export { path };
|
|
112
|
+
export let env: NodeJS.ProcessEnv;
|
|
113
|
+
}
|
|
114
|
+
function setDependencies(customDeps?: {}): {
|
|
115
|
+
deps: {
|
|
116
|
+
exec: (cmd: any, options: any) => string;
|
|
117
|
+
fs: {
|
|
118
|
+
existsSync: typeof existsSync;
|
|
119
|
+
access(path: import("fs").PathLike, mode?: number): Promise<void>;
|
|
120
|
+
copyFile(src: import("fs").PathLike, dest: import("fs").PathLike, mode?: number): Promise<void>;
|
|
121
|
+
open(path: import("fs").PathLike, flags?: string | number, mode?: import("fs").Mode): Promise<fs.FileHandle>;
|
|
122
|
+
rename(oldPath: import("fs").PathLike, newPath: import("fs").PathLike): Promise<void>;
|
|
123
|
+
truncate(path: import("fs").PathLike, len?: number): Promise<void>;
|
|
124
|
+
rmdir(path: import("fs").PathLike, options?: import("fs").RmDirOptions): Promise<void>;
|
|
125
|
+
rm(path: import("fs").PathLike, options?: import("fs").RmOptions): Promise<void>;
|
|
126
|
+
mkdir(path: import("fs").PathLike, options: import("fs").MakeDirectoryOptions & {
|
|
127
|
+
recursive: true;
|
|
128
|
+
}): Promise<string | undefined>;
|
|
129
|
+
mkdir(path: import("fs").PathLike, options?: import("fs").Mode | (import("fs").MakeDirectoryOptions & {
|
|
130
|
+
recursive?: false | undefined;
|
|
131
|
+
}) | null): Promise<void>;
|
|
132
|
+
mkdir(path: import("fs").PathLike, options?: import("fs").Mode | import("fs").MakeDirectoryOptions | null): Promise<string | undefined>;
|
|
133
|
+
readdir(path: import("fs").PathLike, options?: (import("fs").ObjectEncodingOptions & {
|
|
134
|
+
withFileTypes?: false | undefined;
|
|
135
|
+
recursive?: boolean | undefined;
|
|
136
|
+
}) | BufferEncoding | null): Promise<string[]>;
|
|
137
|
+
readdir(path: import("fs").PathLike, options: {
|
|
138
|
+
encoding: "buffer";
|
|
139
|
+
withFileTypes?: false | undefined;
|
|
140
|
+
recursive?: boolean | undefined;
|
|
141
|
+
} | "buffer"): Promise<Buffer[]>;
|
|
142
|
+
readdir(path: import("fs").PathLike, options?: (import("fs").ObjectEncodingOptions & {
|
|
143
|
+
withFileTypes?: false | undefined;
|
|
144
|
+
recursive?: boolean | undefined;
|
|
145
|
+
}) | BufferEncoding | null): Promise<string[] | Buffer[]>;
|
|
146
|
+
readdir(path: import("fs").PathLike, options: import("fs").ObjectEncodingOptions & {
|
|
147
|
+
withFileTypes: true;
|
|
148
|
+
recursive?: boolean | undefined;
|
|
149
|
+
}): Promise<import("fs").Dirent[]>;
|
|
150
|
+
readlink(path: import("fs").PathLike, options?: import("fs").ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
|
|
151
|
+
readlink(path: import("fs").PathLike, options: import("fs").BufferEncodingOption): Promise<Buffer>;
|
|
152
|
+
readlink(path: import("fs").PathLike, options?: import("fs").ObjectEncodingOptions | string | null): Promise<string | Buffer>;
|
|
153
|
+
symlink(target: import("fs").PathLike, path: import("fs").PathLike, type?: string | null): Promise<void>;
|
|
154
|
+
lstat(path: import("fs").PathLike, opts?: import("fs").StatOptions & {
|
|
155
|
+
bigint?: false | undefined;
|
|
156
|
+
}): Promise<import("fs").Stats>;
|
|
157
|
+
lstat(path: import("fs").PathLike, opts: import("fs").StatOptions & {
|
|
158
|
+
bigint: true;
|
|
159
|
+
}): Promise<import("fs").BigIntStats>;
|
|
160
|
+
lstat(path: import("fs").PathLike, opts?: import("fs").StatOptions): Promise<import("fs").Stats | import("fs").BigIntStats>;
|
|
161
|
+
stat(path: import("fs").PathLike, opts?: import("fs").StatOptions & {
|
|
162
|
+
bigint?: false | undefined;
|
|
163
|
+
}): Promise<import("fs").Stats>;
|
|
164
|
+
stat(path: import("fs").PathLike, opts: import("fs").StatOptions & {
|
|
165
|
+
bigint: true;
|
|
166
|
+
}): Promise<import("fs").BigIntStats>;
|
|
167
|
+
stat(path: import("fs").PathLike, opts?: import("fs").StatOptions): Promise<import("fs").Stats | import("fs").BigIntStats>;
|
|
168
|
+
statfs(path: import("fs").PathLike, opts?: import("fs").StatFsOptions & {
|
|
169
|
+
bigint?: false | undefined;
|
|
170
|
+
}): Promise<import("fs").StatsFs>;
|
|
171
|
+
statfs(path: import("fs").PathLike, opts: import("fs").StatFsOptions & {
|
|
172
|
+
bigint: true;
|
|
173
|
+
}): Promise<import("fs").BigIntStatsFs>;
|
|
174
|
+
statfs(path: import("fs").PathLike, opts?: import("fs").StatFsOptions): Promise<import("fs").StatsFs | import("fs").BigIntStatsFs>;
|
|
175
|
+
link(existingPath: import("fs").PathLike, newPath: import("fs").PathLike): Promise<void>;
|
|
176
|
+
unlink(path: import("fs").PathLike): Promise<void>;
|
|
177
|
+
chmod(path: import("fs").PathLike, mode: import("fs").Mode): Promise<void>;
|
|
178
|
+
lchmod(path: import("fs").PathLike, mode: import("fs").Mode): Promise<void>;
|
|
179
|
+
lchown(path: import("fs").PathLike, uid: number, gid: number): Promise<void>;
|
|
180
|
+
lutimes(path: import("fs").PathLike, atime: import("fs").TimeLike, mtime: import("fs").TimeLike): Promise<void>;
|
|
181
|
+
chown(path: import("fs").PathLike, uid: number, gid: number): Promise<void>;
|
|
182
|
+
utimes(path: import("fs").PathLike, atime: import("fs").TimeLike, mtime: import("fs").TimeLike): Promise<void>;
|
|
183
|
+
realpath(path: import("fs").PathLike, options?: import("fs").ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
|
|
184
|
+
realpath(path: import("fs").PathLike, options: import("fs").BufferEncodingOption): Promise<Buffer>;
|
|
185
|
+
realpath(path: import("fs").PathLike, options?: import("fs").ObjectEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
|
|
186
|
+
mkdtemp(prefix: string, options?: import("fs").ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
|
|
187
|
+
mkdtemp(prefix: string, options: import("fs").BufferEncodingOption): Promise<Buffer>;
|
|
188
|
+
mkdtemp(prefix: string, options?: import("fs").ObjectEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
|
|
189
|
+
writeFile(file: import("fs").PathLike | fs.FileHandle, data: string | NodeJS.ArrayBufferView | Iterable<string | NodeJS.ArrayBufferView> | AsyncIterable<string | NodeJS.ArrayBufferView> | import("stream"), options?: (import("fs").ObjectEncodingOptions & {
|
|
190
|
+
mode?: import("fs").Mode | undefined;
|
|
191
|
+
flag?: import("fs").OpenMode | undefined;
|
|
192
|
+
flush?: boolean | undefined;
|
|
193
|
+
} & import("events").Abortable) | BufferEncoding | null): Promise<void>;
|
|
194
|
+
appendFile(path: import("fs").PathLike | fs.FileHandle, data: string | Uint8Array, options?: (import("fs").ObjectEncodingOptions & fs.FlagAndOpenMode & {
|
|
195
|
+
flush?: boolean | undefined;
|
|
196
|
+
}) | BufferEncoding | null): Promise<void>;
|
|
197
|
+
readFile(path: import("fs").PathLike | fs.FileHandle, options?: ({
|
|
198
|
+
encoding?: null | undefined;
|
|
199
|
+
flag?: import("fs").OpenMode | undefined;
|
|
200
|
+
} & import("events").Abortable) | null): Promise<Buffer>;
|
|
201
|
+
readFile(path: import("fs").PathLike | fs.FileHandle, options: ({
|
|
202
|
+
encoding: BufferEncoding;
|
|
203
|
+
flag?: import("fs").OpenMode | undefined;
|
|
204
|
+
} & import("events").Abortable) | BufferEncoding): Promise<string>;
|
|
205
|
+
readFile(path: import("fs").PathLike | fs.FileHandle, options?: (import("fs").ObjectEncodingOptions & import("events").Abortable & {
|
|
206
|
+
flag?: import("fs").OpenMode | undefined;
|
|
207
|
+
}) | BufferEncoding | null): Promise<string | Buffer>;
|
|
208
|
+
opendir(path: import("fs").PathLike, options?: import("fs").OpenDirOptions): Promise<import("fs").Dir>;
|
|
209
|
+
watch(filename: import("fs").PathLike, options: (import("fs").WatchOptions & {
|
|
210
|
+
encoding: "buffer";
|
|
211
|
+
}) | "buffer"): AsyncIterable<fs.FileChangeInfo<Buffer>>;
|
|
212
|
+
watch(filename: import("fs").PathLike, options?: import("fs").WatchOptions | BufferEncoding): AsyncIterable<fs.FileChangeInfo<string>>;
|
|
213
|
+
watch(filename: import("fs").PathLike, options: import("fs").WatchOptions | string): AsyncIterable<fs.FileChangeInfo<string>> | AsyncIterable<fs.FileChangeInfo<Buffer>>;
|
|
214
|
+
cp(source: string | URL, destination: string | URL, opts?: import("fs").CopyOptions): Promise<void>;
|
|
215
|
+
glob(pattern: string | string[]): NodeJS.AsyncIterator<string>;
|
|
216
|
+
glob(pattern: string | string[], opt: import("fs").GlobOptionsWithFileTypes): NodeJS.AsyncIterator<import("fs").Dirent>;
|
|
217
|
+
glob(pattern: string | string[], opt: import("fs").GlobOptionsWithoutFileTypes): NodeJS.AsyncIterator<string>;
|
|
218
|
+
glob(pattern: string | string[], opt: import("fs").GlobOptions): NodeJS.AsyncIterator<import("fs").Dirent | string>;
|
|
219
|
+
constants: typeof import("fs").constants;
|
|
220
|
+
};
|
|
221
|
+
path: path.PlatformPath;
|
|
222
|
+
env: NodeJS.ProcessEnv;
|
|
223
|
+
};
|
|
224
|
+
setDependencies(customDeps?: {}): /*elided*/ any;
|
|
225
|
+
isGitHubAction(): boolean;
|
|
226
|
+
workflowExists(basePath: any): boolean;
|
|
227
|
+
getWorkflowDir(basePath: any): string;
|
|
228
|
+
getGithubActionWorkflowFilePath(basePath: any): string;
|
|
229
|
+
createGitHubActionFile(basePath: any, translationPaths: any): Promise<string>;
|
|
230
|
+
autoCommitChanges(filesPath: any): void;
|
|
231
|
+
};
|
|
232
|
+
function isGitHubAction(): boolean;
|
|
233
|
+
function workflowExists(basePath: any): boolean;
|
|
234
|
+
function getWorkflowDir(basePath: any): string;
|
|
235
|
+
function getGithubActionWorkflowFilePath(basePath: any): string;
|
|
236
|
+
function createGitHubActionFile(basePath: any, translationPaths: any): Promise<string>;
|
|
237
|
+
function autoCommitChanges(filesPath: any): void;
|
|
238
|
+
}
|
|
239
|
+
import { existsSync } from 'fs';
|
|
240
|
+
import { promises as fs_1 } from 'fs';
|
|
241
|
+
import path from 'path';
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import { promises as fs, existsSync } from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
const defaultDependencies = {
|
|
5
|
+
exec: (cmd, options) => execSync(cmd, options),
|
|
6
|
+
fs: { ...fs, existsSync },
|
|
7
|
+
path,
|
|
8
|
+
env: process.env
|
|
9
|
+
};
|
|
10
|
+
const workflowFileName = 'localhero-translate.yml';
|
|
11
|
+
export const githubService = {
|
|
12
|
+
deps: { ...defaultDependencies },
|
|
13
|
+
/**
|
|
14
|
+
* For testing - reset or inject custom dependencies
|
|
15
|
+
*/
|
|
16
|
+
setDependencies(customDeps = {}) {
|
|
17
|
+
this.deps = { ...defaultDependencies, ...customDeps };
|
|
18
|
+
return this;
|
|
19
|
+
},
|
|
20
|
+
/**
|
|
21
|
+
* Check if running in GitHub Actions
|
|
22
|
+
*/
|
|
23
|
+
isGitHubAction() {
|
|
24
|
+
return this.deps.env.GITHUB_ACTIONS === 'true';
|
|
25
|
+
},
|
|
26
|
+
/**
|
|
27
|
+
* Check if the GitHub workflow file exists
|
|
28
|
+
* @param basePath Base path of the project
|
|
29
|
+
*/
|
|
30
|
+
workflowExists(basePath) {
|
|
31
|
+
return this.deps.fs.existsSync(this.getGithubActionWorkflowFilePath(basePath));
|
|
32
|
+
},
|
|
33
|
+
/**
|
|
34
|
+
* Get the workflows directory path
|
|
35
|
+
* @param basePath Base path of the project
|
|
36
|
+
*/
|
|
37
|
+
getWorkflowDir(basePath) {
|
|
38
|
+
return this.deps.path.join(basePath, '.github', 'workflows');
|
|
39
|
+
},
|
|
40
|
+
/**
|
|
41
|
+
* Get the full path to the GitHub action workflow file
|
|
42
|
+
* @param basePath Base path of the project
|
|
43
|
+
*/
|
|
44
|
+
getGithubActionWorkflowFilePath(basePath) {
|
|
45
|
+
return this.deps.path.join(this.getWorkflowDir(basePath), workflowFileName);
|
|
46
|
+
},
|
|
47
|
+
/**
|
|
48
|
+
* Create a GitHub actions workflow file for translations
|
|
49
|
+
* @param basePath Base path of the project
|
|
50
|
+
* @param translationPaths Paths to translation files
|
|
51
|
+
*/
|
|
52
|
+
async createGitHubActionFile(basePath, translationPaths) {
|
|
53
|
+
const { fs } = this.deps;
|
|
54
|
+
const workflowDir = this.getWorkflowDir(basePath);
|
|
55
|
+
const workflowFile = this.getGithubActionWorkflowFilePath(basePath);
|
|
56
|
+
await fs.mkdir(workflowDir, { recursive: true });
|
|
57
|
+
const actionContent = `name: Localhero.ai - I18n translation
|
|
58
|
+
|
|
59
|
+
on:
|
|
60
|
+
pull_request:
|
|
61
|
+
paths:
|
|
62
|
+
${translationPaths.map(p => {
|
|
63
|
+
// Check if path already contains a file pattern (*, ?, or {})
|
|
64
|
+
const hasPattern = /[*?{}]/.test(p);
|
|
65
|
+
// If it has a pattern, use it as is; otherwise, append /**
|
|
66
|
+
const formattedPath = hasPattern ? p : `${p}${p.endsWith('/') ? '' : '/'}**`;
|
|
67
|
+
return `- "${formattedPath}"`;
|
|
68
|
+
}).join('\n ')}
|
|
69
|
+
|
|
70
|
+
jobs:
|
|
71
|
+
translate:
|
|
72
|
+
runs-on: ubuntu-latest
|
|
73
|
+
permissions:
|
|
74
|
+
contents: write
|
|
75
|
+
pull-requests: write
|
|
76
|
+
|
|
77
|
+
steps:
|
|
78
|
+
- name: Checkout code
|
|
79
|
+
uses: actions/checkout@v4
|
|
80
|
+
with:
|
|
81
|
+
ref: \${{ github.head_ref }}
|
|
82
|
+
fetch-depth: 0
|
|
83
|
+
|
|
84
|
+
- name: Set up Node.js
|
|
85
|
+
uses: actions/setup-node@v4
|
|
86
|
+
with:
|
|
87
|
+
node-version: 22
|
|
88
|
+
|
|
89
|
+
- name: Run LocalHero CLI
|
|
90
|
+
env:
|
|
91
|
+
LOCALHERO_API_KEY: \${{ secrets.LOCALHERO_API_KEY }}
|
|
92
|
+
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
|
|
93
|
+
run: npx -y @localheroai/cli translate`;
|
|
94
|
+
await fs.writeFile(workflowFile, actionContent);
|
|
95
|
+
return workflowFile;
|
|
96
|
+
},
|
|
97
|
+
/**
|
|
98
|
+
* Automatically commit and push changes when running in GitHub Actions
|
|
99
|
+
* @param filesPath Path pattern for files to commit
|
|
100
|
+
*/
|
|
101
|
+
autoCommitChanges(filesPath) {
|
|
102
|
+
const { exec, env } = this.deps;
|
|
103
|
+
if (!this.isGitHubAction())
|
|
104
|
+
return;
|
|
105
|
+
console.log('Running in GitHub Actions. Committing changes...');
|
|
106
|
+
try {
|
|
107
|
+
exec('git config --global user.name "LocalHero Bot"', { stdio: 'inherit' });
|
|
108
|
+
exec('git config --global user.email "hi@localhero.ai"', { stdio: 'inherit' });
|
|
109
|
+
const branchName = env.GITHUB_HEAD_REF;
|
|
110
|
+
if (!branchName) {
|
|
111
|
+
throw new Error('Could not determine branch name from GITHUB_HEAD_REF');
|
|
112
|
+
}
|
|
113
|
+
exec(`git add ${filesPath}`, { stdio: 'inherit' });
|
|
114
|
+
const status = exec('git status --porcelain').toString();
|
|
115
|
+
if (!status) {
|
|
116
|
+
console.log('No changes to commit.');
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
exec('git commit -m "Update translations"', { stdio: 'inherit' });
|
|
120
|
+
const token = env.GITHUB_TOKEN;
|
|
121
|
+
if (!token) {
|
|
122
|
+
throw new Error('GITHUB_TOKEN is not set');
|
|
123
|
+
}
|
|
124
|
+
const repository = env.GITHUB_REPOSITORY;
|
|
125
|
+
if (!repository) {
|
|
126
|
+
throw new Error('GITHUB_REPOSITORY is not set');
|
|
127
|
+
}
|
|
128
|
+
const remoteUrl = `https://x-access-token:${token}@github.com/${repository}.git`;
|
|
129
|
+
exec(`git remote set-url origin ${remoteUrl}`, { stdio: 'inherit' });
|
|
130
|
+
exec(`git push origin HEAD:${branchName}`, { stdio: 'inherit' });
|
|
131
|
+
console.log('Changes committed and pushed successfully.');
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
console.error('Auto-commit failed:', error.message);
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Create a GitHub actions workflow file for translations
|
|
141
|
+
* @param basePath Base path of the project
|
|
142
|
+
* @param translationPaths Paths to translation files
|
|
143
|
+
*/
|
|
144
|
+
export function createGitHubActionFile(basePath, translationPaths) {
|
|
145
|
+
return githubService.createGitHubActionFile(basePath, translationPaths);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Check if the GitHub workflow file exists
|
|
149
|
+
* @param basePath Base path of the project
|
|
150
|
+
*/
|
|
151
|
+
export function workflowExists(basePath) {
|
|
152
|
+
return githubService.workflowExists(basePath);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Automatically commit and push changes when running in GitHub Actions
|
|
156
|
+
* @param filesPath Path pattern for files to commit
|
|
157
|
+
*/
|
|
158
|
+
export function autoCommitChanges(filesPath) {
|
|
159
|
+
return githubService.autoCommitChanges(filesPath);
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=github.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github.js","sourceRoot":"","sources":["../../src/utils/github.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAmB,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChD,OAAO,IAAI,MAAM,MAAM,CAAC;AAaxB,MAAM,mBAAmB,GAAuB;IAC9C,IAAI,EAAE,CAAC,GAAW,EAAE,OAAyB,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;IACxE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE;IACzB,IAAI;IACJ,GAAG,EAAE,OAAO,CAAC,GAAG;CACjB,CAAC;AAEF,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AAEnD,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,EAAE,GAAG,mBAAmB,EAAE;IAEhC;;OAEG;IACH,eAAe,CAAC,aAA0C,EAAE;QAC1D,IAAI,CAAC,IAAI,GAAG,EAAE,GAAG,mBAAmB,EAAE,GAAG,UAAU,EAAE,CAAC;QACtD,OAAO,IA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|
|
3
|
+
import { createImport, checkImportStatus, bulkUpdateTranslations } from '../api/imports.js';
|
|
4
|
+
import { findTranslationFiles as findFiles, flattenTranslations } from './files.js';
|
|
5
|
+
/**
|
|
6
|
+
* Get the file format based on extension
|
|
7
|
+
* @param filePath Path to the file
|
|
8
|
+
* @returns The file format or null if not supported
|
|
9
|
+
*/
|
|
10
|
+
function getFileFormat(filePath) {
|
|
11
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
12
|
+
if (ext === '.json')
|
|
13
|
+
return 'json';
|
|
14
|
+
if (ext === '.yml' || ext === '.yaml')
|
|
15
|
+
return 'yaml';
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Read file content and convert to base64
|
|
20
|
+
* @param filePath Path to the file
|
|
21
|
+
* @returns Base64 encoded content
|
|
22
|
+
*/
|
|
23
|
+
async function readFileContent(filePath) {
|
|
24
|
+
const content = await fs.readFile(filePath, 'utf8');
|
|
25
|
+
const format = getFileFormat(filePath);
|
|
26
|
+
if (format === 'json') {
|
|
27
|
+
try {
|
|
28
|
+
const jsonContent = JSON.parse(content);
|
|
29
|
+
const flattened = flattenTranslations(jsonContent);
|
|
30
|
+
return Buffer.from(JSON.stringify(flattened)).toString('base64');
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return Buffer.from(content).toString('base64');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return Buffer.from(content).toString('base64');
|
|
37
|
+
}
|
|
38
|
+
export const importService = {
|
|
39
|
+
/**
|
|
40
|
+
* Find translation files based on configuration
|
|
41
|
+
* @param config Project configuration
|
|
42
|
+
* @param basePath Base path to look for files (defaults to cwd)
|
|
43
|
+
* @returns Array of import file objects
|
|
44
|
+
*/
|
|
45
|
+
async findTranslationFiles(config, basePath = process.cwd()) {
|
|
46
|
+
const options = {
|
|
47
|
+
basePath,
|
|
48
|
+
parseContent: false,
|
|
49
|
+
includeContent: false,
|
|
50
|
+
extractKeys: false,
|
|
51
|
+
includeNamespace: true,
|
|
52
|
+
returnFullResult: false
|
|
53
|
+
};
|
|
54
|
+
const files = await findFiles(config, options);
|
|
55
|
+
return files.map(file => ({
|
|
56
|
+
path: path.isAbsolute(file.path) ? path.relative(basePath, file.path) : file.path,
|
|
57
|
+
language: file.locale,
|
|
58
|
+
format: file.format === 'yml' ? 'yaml' : file.format,
|
|
59
|
+
namespace: file.namespace || ''
|
|
60
|
+
}));
|
|
61
|
+
},
|
|
62
|
+
/**
|
|
63
|
+
* Import translations from files
|
|
64
|
+
* @param config Project configuration
|
|
65
|
+
* @param basePath Base path to look for files (defaults to cwd)
|
|
66
|
+
* @returns Result of the import operation
|
|
67
|
+
*/
|
|
68
|
+
async importTranslations(config, basePath = process.cwd()) {
|
|
69
|
+
const files = await this.findTranslationFiles(config, basePath);
|
|
70
|
+
if (!files.length) {
|
|
71
|
+
return { status: 'no_files' };
|
|
72
|
+
}
|
|
73
|
+
const sourceFiles = files.filter(file => file.language === config.sourceLocale);
|
|
74
|
+
const targetFiles = files.filter(file => file.language !== config.sourceLocale);
|
|
75
|
+
const importedFiles = {
|
|
76
|
+
source: sourceFiles,
|
|
77
|
+
target: targetFiles
|
|
78
|
+
};
|
|
79
|
+
if (!sourceFiles.length) {
|
|
80
|
+
return {
|
|
81
|
+
status: 'failed',
|
|
82
|
+
error: 'No source language files found. Source language files must be included in the first import.',
|
|
83
|
+
files: importedFiles
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const allTranslations = [];
|
|
87
|
+
for (const file of sourceFiles) {
|
|
88
|
+
const fullPath = path.join(basePath, file.path);
|
|
89
|
+
allTranslations.push({
|
|
90
|
+
language: file.language,
|
|
91
|
+
format: file.format === 'yml' ? 'yaml' : file.format,
|
|
92
|
+
filename: file.path,
|
|
93
|
+
content: await readFileContent(fullPath)
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
for (const file of targetFiles) {
|
|
97
|
+
const fullPath = path.join(basePath, file.path);
|
|
98
|
+
allTranslations.push({
|
|
99
|
+
language: file.language,
|
|
100
|
+
format: file.format === 'yml' ? 'yaml' : file.format,
|
|
101
|
+
filename: file.path,
|
|
102
|
+
content: await readFileContent(fullPath)
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
const importResult = await createImport({
|
|
106
|
+
projectId: config.projectId,
|
|
107
|
+
translations: allTranslations
|
|
108
|
+
});
|
|
109
|
+
if (importResult.import?.status === 'failed') {
|
|
110
|
+
return {
|
|
111
|
+
...importResult.import,
|
|
112
|
+
files: importedFiles
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
let finalImportResult = importResult;
|
|
116
|
+
while (finalImportResult.import?.status === 'processing') {
|
|
117
|
+
const pollInterval = finalImportResult.import.poll_interval || 5;
|
|
118
|
+
await new Promise(resolve => setTimeout(resolve, pollInterval * 1000));
|
|
119
|
+
finalImportResult = await checkImportStatus(config.projectId, finalImportResult.import.id);
|
|
120
|
+
if (finalImportResult.import?.status === 'failed') {
|
|
121
|
+
return {
|
|
122
|
+
...finalImportResult.import,
|
|
123
|
+
files: importedFiles
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const { import: { status = 'completed', statistics, warnings, translations_url, sourceImport } = {} } = finalImportResult;
|
|
128
|
+
return {
|
|
129
|
+
status,
|
|
130
|
+
statistics,
|
|
131
|
+
warnings,
|
|
132
|
+
translations_url,
|
|
133
|
+
sourceImport,
|
|
134
|
+
files: importedFiles
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
/**
|
|
138
|
+
* Push local translations to the API
|
|
139
|
+
* @param config Project configuration
|
|
140
|
+
* @param basePath Base path to look for files (defaults to cwd)
|
|
141
|
+
* @returns Result of the push operation
|
|
142
|
+
*/
|
|
143
|
+
async pushTranslations(config, basePath = process.cwd()) {
|
|
144
|
+
const files = await this.findTranslationFiles(config, basePath);
|
|
145
|
+
if (!files.length) {
|
|
146
|
+
return { status: 'no_files' };
|
|
147
|
+
}
|
|
148
|
+
const allTranslations = [];
|
|
149
|
+
for (const file of files) {
|
|
150
|
+
const fullPath = path.join(basePath, file.path);
|
|
151
|
+
allTranslations.push({
|
|
152
|
+
language: file.language,
|
|
153
|
+
format: file.format === 'yml' ? 'yaml' : file.format,
|
|
154
|
+
filename: file.path,
|
|
155
|
+
content: await readFileContent(fullPath)
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
const importResult = await bulkUpdateTranslations({
|
|
159
|
+
projectId: config.projectId,
|
|
160
|
+
translations: allTranslations
|
|
161
|
+
});
|
|
162
|
+
if (importResult.import?.status === 'failed') {
|
|
163
|
+
return {
|
|
164
|
+
...importResult.import,
|
|
165
|
+
files: { source: [], target: files }
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
let finalImportResult = importResult;
|
|
169
|
+
while (finalImportResult.import?.status === 'processing') {
|
|
170
|
+
const pollInterval = finalImportResult.import.poll_interval || 5;
|
|
171
|
+
await new Promise(resolve => setTimeout(resolve, pollInterval * 1000));
|
|
172
|
+
finalImportResult = await checkImportStatus(config.projectId, finalImportResult.import.id);
|
|
173
|
+
if (finalImportResult.import?.status === 'failed') {
|
|
174
|
+
return {
|
|
175
|
+
...finalImportResult.import,
|
|
176
|
+
files: { source: [], target: files }
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const { import: { status = 'completed', statistics, warnings, translations_url, sourceImport } = {} } = finalImportResult;
|
|
181
|
+
return {
|
|
182
|
+
status,
|
|
183
|
+
statistics,
|
|
184
|
+
warnings,
|
|
185
|
+
translations_url,
|
|
186
|
+
sourceImport,
|
|
187
|
+
files: { source: [], target: files }
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Find translation files based on configuration
|
|
193
|
+
* @param config Project configuration
|
|
194
|
+
* @param basePath Base path to look for files (defaults to cwd)
|
|
195
|
+
* @returns Array of import file objects
|
|
196
|
+
*/
|
|
197
|
+
export async function findTranslationFiles(config, basePath = process.cwd()) {
|
|
198
|
+
return importService.findTranslationFiles(config, basePath);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Import translations from files
|
|
202
|
+
* @param config Project configuration
|
|
203
|
+
* @param basePath Base path to look for files (defaults to cwd)
|
|
204
|
+
* @returns Result of the import operation
|
|
205
|
+
*/
|
|
206
|
+
export async function importTranslations(config, basePath = process.cwd()) {
|
|
207
|
+
return importService.importTranslations(config, basePath);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Push translations to the API
|
|
211
|
+
* @param config Project configuration
|
|
212
|
+
* @param basePath Base path to look for files (defaults to cwd)
|
|
213
|
+
* @returns Result of the push operation
|
|
214
|
+
*/
|
|
215
|
+
export async function pushTranslations(config, basePath = process.cwd()) {
|
|
216
|
+
return importService.pushTranslations(config, basePath);
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=import-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-service.js","sourceRoot":"","sources":["../../src/utils/import-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAkB,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC5G,OAAO,EAAE,oBAAoB,IAAI,SAAS,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAqDpF;;;;GAIG;AACH,SAAS,aAAa,CAAC,QAAgB;IACrC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;IACjD,IAAI,GAAG,KAAK,OAAO;QAAE,OAAO,MAAM,CAAC;IACnC,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,OAAO;QAAE,OAAO,MAAM,CAAC;IACrD,OAAO,IAAI,CAA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