-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: handle scoped only libs #179
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { setConfig } from '../config'; | ||
import { messages } from '../messages'; | ||
import { Config } from '../types'; | ||
import { Config, ScopeMap } from '../types'; | ||
import { countKeys } from '../utils/keys.utils'; | ||
import { getLogger } from '../utils/logger'; | ||
import { resolveConfig } from '../utils/resolve-config'; | ||
|
@@ -23,6 +23,19 @@ export async function buildTranslationFiles(inlineConfig: Config) { | |
const result = buildKeys(config); | ||
const { scopeToKeys, fileCount } = result; | ||
|
||
if (config.scopedOnly) { | ||
if (Object.keys(scopeToKeys.__global).length) { | ||
logger.log( | ||
'\n\x1b[31m%s\x1b[0m', | ||
'⚠️', | ||
'Global keys found with scopedOnly flag active\n' | ||
); | ||
if (config.emitErrorOnExtraKeys) { | ||
process.exit(2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why exit code 2? 🤔 |
||
} | ||
} | ||
delete (scopeToKeys as Partial<ScopeMap>).__global; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to delete the key? |
||
} | ||
logger.success(`${messages.extract} 🗝`); | ||
|
||
let keysFound = 0; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { setConfig } from '../config'; | ||
import { buildKeys } from '../keys-builder/build-keys'; | ||
import { messages } from '../messages'; | ||
import { Config } from '../types'; | ||
import { Config, ScopeMap } from '../types'; | ||
import { getLogger } from '../utils/logger'; | ||
import { resolveConfig } from '../utils/resolve-config'; | ||
|
||
|
@@ -29,6 +29,19 @@ export function findMissingKeys(inlineConfig: Config) { | |
|
||
const result = buildKeys(config); | ||
logger.success(`${messages.extract} 🗝`); | ||
if (config.scopedOnly) { | ||
if (Object.keys(result.scopeToKeys.__global).length) { | ||
logger.log( | ||
'\n\x1b[31m%s\x1b[0m', | ||
'⚠️', | ||
'Global keys found with scopedOnly flag active\n' | ||
); | ||
if (config.emitErrorOnExtraKeys) { | ||
process.exit(2); | ||
} | ||
} | ||
delete (result.scopeToKeys as Partial<ScopeMap>).__global; | ||
} | ||
Comment on lines
+32
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate code from the builder |
||
|
||
const { addMissingKeys, emitErrorOnExtraKeys } = config; | ||
compareKeysToFiles({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
export function marker<T extends string | string[]>(key: T): T { | ||
export function marker<T extends string | string[]>( | ||
key: T, | ||
params?: unknown, | ||
lang?: string | ||
): T { | ||
return key; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally speaking, shouldn't we just skip creation if there aren't any keys there? instead of introducing a new config? or maybe introduce "createEmptyFiles" or something, WDYT?