`
Example: `['en', 'ja']`
#### pattern
Type: `string`
File path with glob.
#### options
Additional options.
#### defaultLocale
Type: `string`
Default: `en`
Set default locale for your app.
##### cwd
Type: `string`
Default: `.`
**You most likely don't need this.**
Change run path.
================================================
FILE: src/extract-react-intl/test/__snapshots__/test.ts.snap
================================================
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`babel plugin execution order 1`] = `
{
"en": {
"src.extract-react-intl.test.pluginOrdering.test": "auto",
},
}
`;
exports[`extract from file 1`] = `
{
"en": {
"components.App.1248161314": "Submit button",
"components.App.hello": "hello",
"components.App.world": "world",
"components/Greeting/welcome": "
Welcome {name}, you have received {unreadCount, plural,
=0 {no new messages}
one {{formattedUnreadCount} new message}
other {{formattedUnreadCount} new messages}
} since {formattedLastLoginTime}.
",
},
"ja": {
"components.App.1248161314": "",
"components.App.hello": "",
"components.App.world": "",
"components/Greeting/welcome": "",
},
}
`;
exports[`extract from file by enabling cache and extract from cache 1`] = `
{
"en": {
"components.App.1248161314": "Submit button",
"components.App.hello": "hello",
"components.App.world": "world",
"components/Greeting/welcome": "
Welcome {name}, you have received {unreadCount, plural,
=0 {no new messages}
one {{formattedUnreadCount} new message}
other {{formattedUnreadCount} new messages}
} since {formattedLastLoginTime}.
",
},
"ja": {
"components.App.1248161314": "",
"components.App.hello": "",
"components.App.world": "",
"components/Greeting/welcome": "",
},
}
`;
exports[`extract from file by enabling cache and extract from cache 2`] = `
{
"en": {
"components.App.1248161314": "Submit button",
"components.App.hello": "hello",
"components.App.world": "world",
"components/Greeting/welcome": "
Welcome {name}, you have received {unreadCount, plural,
=0 {no new messages}
one {{formattedUnreadCount} new message}
other {{formattedUnreadCount} new messages}
} since {formattedLastLoginTime}.
",
},
"ja": {
"components.App.1248161314": "",
"components.App.hello": "",
"components.App.world": "",
"components/Greeting/welcome": "",
},
}
`;
exports[`extract from file with descriptions 1`] = `
{
"en": {
"components.App.hello": {
"description": "hello message description",
"message": "hello",
},
"components.App.world": {
"description": "world message description",
"message": "world",
},
"components/Greeting/welcome": {
"description": "Welcome message description",
"message": "
Welcome {name}, you have received {unreadCount, plural,
=0 {no new messages}
one {{formattedUnreadCount} new message}
other {{formattedUnreadCount} new messages}
} since {formattedLastLoginTime}.
",
},
},
"ja": {
"components.App.hello": {
"description": "hello message description",
"message": "",
},
"components.App.world": {
"description": "world message description",
"message": "",
},
"components/Greeting/welcome": {
"description": "Welcome message description",
"message": "",
},
},
}
`;
================================================
FILE: src/extract-react-intl/test/fixtures/.babelrc
================================================
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"browsers": [
"last 2 versions",
"safari >= 7"
]
}
}
],
"@babel/preset-react",
"@babel/preset-flow"
],
"plugins": [
"@babel/plugin-proposal-class-properties"
],
"env": {
"react-intl": {
"plugins": [
[
"react-intl-auto",
{
"removePrefix": "src.extract-react-intl.test.fixtures"
}
]
]
}
}
}
================================================
FILE: src/extract-react-intl/test/fixtures/components/App/index.js
================================================
// @flow
import React, { Component } from 'react'
import { FormattedMessage, injectIntl } from 'react-intl'
import Greeting from '../Greeting'
import messages from './messages'
injectIntl(({ intl }) => {
const label = intl.formatMessage({ defaultMessage: "Submit button" })
return
});
export default class App extends Component {
render() {
const user = {
name: 'Eric',
unreadCount: 4,
lastLoginTime: Date.now() - 1000 * 60 * 60 * 24
}
return (
)
}
}
================================================
FILE: src/extract-react-intl/test/fixtures/components/App/messages.js
================================================
// @flow
import { defineMessages } from 'react-intl'
export default defineMessages({
// hello message description
hello: 'hello',
// world message description
world: 'world'
})
================================================
FILE: src/extract-react-intl/test/fixtures/components/Greeting/index.js
================================================
// @flow
import React, { Component } from 'react'
import {
FormattedMessage,
FormattedNumber,
FormattedRelative
} from 'react-intl'
import messages from './messages'
type Props = {
user: {
name: string,
unreadCount: number,
lastLoginTime: number
}
}
export default class Greeting extends Component {
props: Props
render() {
const { user } = this.props
return (
{user.name},
unreadCount: user.unreadCount,
formattedUnreadCount: (
),
formattedLastLoginTime: (
)
}}
/>
)
}
}
function defaultMessage() {
return 'hello'
}
================================================
FILE: src/extract-react-intl/test/fixtures/components/Greeting/messages.js
================================================
// @flow
import { defineMessages } from 'react-intl'
export default defineMessages({
// Welcome message description
welcome: {
id: 'components/Greeting/welcome',
defaultMessage: `
Welcome {name}, you have received {unreadCount, plural,
=0 {no new messages}
one {{formattedUnreadCount} new message}
other {{formattedUnreadCount} new messages}
} since {formattedLastLoginTime}.
`
}
})
================================================
FILE: src/extract-react-intl/test/fixtures/components/LanguageProvider/index.js
================================================
// @flow
import React, { Component } from 'react'
import { addLocaleData, IntlProvider } from 'react-intl'
import enLocaleData from 'react-intl/locale-data/en'
import jaLocaleData from 'react-intl/locale-data/ja'
import enMessages from '../../translations/en.json'
import jaMessages from '../../translations/ja.json'
addLocaleData(enLocaleData)
addLocaleData(jaLocaleData)
const messages = {
en: enMessages,
ja: jaMessages
}
export default class LanguageProvider extends Component {
props: { children?: React$Element<*> }
state: { locale: string } = { locale: 'en' }
render() {
const { locale } = this.state
return (
)
}
}
================================================
FILE: src/extract-react-intl/test/fixtures/index.html
================================================
Example
================================================
FILE: src/extract-react-intl/test/fixtures/index.js
================================================
// @flow
import React from 'react'
import ReactDOM from 'react-dom'
import App from './components/App'
import LanguageProvider from './components/LanguageProvider'
ReactDOM.render(
,
document.getElementById('root')
)
================================================
FILE: src/extract-react-intl/test/pluginOrdering/.babelrc
================================================
{
"presets": ["@babel/preset-flow"],
"plugins": ["react-intl-auto"]
}
================================================
FILE: src/extract-react-intl/test/pluginOrdering/messages.js
================================================
import { defineMessages } from 'react-intl'
export default defineMessages({
test: 'auto'
})
================================================
FILE: src/extract-react-intl/test/resolution/.babelrc
================================================
{
"presets": ["@babel/preset-flow"],
"plugins": ["react-intl"]
}
================================================
FILE: src/extract-react-intl/test/resolution/messages.js
================================================
import { defineMessages } from 'react-intl'
export default defineMessages({
test: {
id: 'test',
defaultMessage: 'test'
}
})
================================================
FILE: src/extract-react-intl/test/test.ts
================================================
import m from '..'
const pattern = 'src/extract-react-intl/test/fixtures/**/*.js'
const locales = ['en', 'ja']
test('extract from file', async () => {
process.env.BABEL_ENV = 'react-intl'
const x = await m(locales, pattern, {
defaultLocale: 'en',
cwd: `${__dirname}/fixtures`,
extractFromFormatMessageCall: true
})
expect(x).toMatchSnapshot()
})
test('extract from file by enabling cache and extract from cache', async () => {
process.env.BABEL_ENV = 'react-intl'
const x = await m(locales, pattern, {
defaultLocale: 'en',
cwd: `${__dirname}/fixtures`,
extractFromFormatMessageCall: true,
cache: true,
cacheLocation: '.test-cache'
})
expect(x).toMatchSnapshot()
const y = await m(locales, pattern, {
defaultLocale: 'en',
cwd: `${__dirname}/fixtures`,
extractFromFormatMessageCall: true,
cache: true,
cacheLocation: '.test-cache'
})
expect(y).toMatchSnapshot()
})
// TODO: fix
test.skip('babelrc path resolution', async () => {
const x = await m(['en'], './extract-react-intl/test/resolution/**/*.js', {
defaultLocale: 'en',
cwd: `${__dirname}/resolution`
})
expect(x).toMatchSnapshot()
})
test('babel plugin execution order', async () => {
const x = await m(
['en'],
'src/extract-react-intl/test/pluginOrdering/**/*.js',
{ defaultLocale: 'en', cwd: `${__dirname}/pluginOrdering` }
)
expect(x).toMatchSnapshot()
})
test('error', async () => {
expect.assertions(1)
await m(locales, 'notfound', {
defaultLocale: 'en',
cwd: `${__dirname}/fixtures`
}).catch((error) => {
expect(error.message).toMatch('File not found')
})
})
test('extract from file with descriptions', async () => {
process.env.BABEL_ENV = 'react-intl'
const x = await m(locales, pattern, {
defaultLocale: 'en',
cwd: './test/fixtures',
withDescriptions: true
})
expect(x).toMatchSnapshot()
})
================================================
FILE: src/global.d.ts
================================================
declare module 'read-babelrc-up' {
function sync(opts: { cwd: string }): {
path: string
babel: import('@babel/core').TransformOptions
}
}
================================================
FILE: src/index.ts
================================================
import path from 'path'
import fs from 'fs'
import yaml from 'js-yaml'
import { promisify } from 'util'
import { flatten, unflatten } from 'flat'
import loadJsonFile from 'load-json-file'
import writeJsonFile from 'write-json-file'
import sortKeys from 'sort-keys'
import _extractReactIntl from './extract-react-intl/index.js'
const writeJson = (outputPath: string, obj: object, indent: number) => {
return writeJsonFile(`${outputPath}.json`, obj, { indent })
}
const writeYaml = (outputPath: string, obj: object, indent: number) => {
return promisify(fs.writeFile)(
`${outputPath}.yml`,
yaml.dump(obj, { indent }),
'utf8'
)
}
const isJson = (ext: string) => ext === 'json'
function loadLocaleFiles(locales: string[], buildDir: string, ext: string) {
const oldLocaleMaps: Record> = {}
try {
fs.mkdirSync(buildDir, { recursive: true })
} catch {
// Directory already exists or other error, continue
}
for (const locale of locales) {
const file = path.resolve(buildDir, `${locale}.${ext}`)
// Initialize json file
try {
const output = isJson(ext) ? JSON.stringify({}) : yaml.dump({})
fs.writeFileSync(file, output, { flag: 'wx' })
} catch (error: unknown) {
if ((error as NodeJS.ErrnoException).code !== 'EEXIST') {
throw error
}
}
let messages = isJson(ext)
? loadJsonFile.sync(file)
: yaml.load(fs.readFileSync(file, 'utf8'), { json: true })
messages = flatten(messages)
oldLocaleMaps[locale] = {}
for (const messageKey of Object.keys(messages as object)) {
const message = (messages as Record)[messageKey]
if (message && typeof message === 'string' && message !== '') {
oldLocaleMaps[locale][messageKey] = (
messages as Record
)[messageKey] as object
}
}
}
return oldLocaleMaps
}
type Opts = {
[key: string]: unknown
defaultLocale: string
format?: string
flat?: boolean
overwriteDefault?: boolean
indent?: number
}
const extractMessage = async (
locales: string[],
pattern: string,
buildDir: string,
{
format = 'json',
flat = isJson(format),
defaultLocale = 'en',
overwriteDefault = true,
indent = 2,
...opts
}: Opts = {
defaultLocale: 'en'
}
) => {
if (!Array.isArray(locales)) {
throw new TypeError(`Expected a Array, got ${typeof locales}`)
}
if (typeof pattern !== 'string') {
throw new TypeError(`Expected a string, got ${typeof pattern}`)
}
if (typeof buildDir !== 'string') {
throw new TypeError(`Expected a string, got ${typeof buildDir}`)
}
const ext = isJson(format) ? 'json' : 'yml'
const oldLocaleMaps = loadLocaleFiles(locales, buildDir, ext)
const extractorOptions = {
defaultLocale,
withDescriptions: false,
cwd: process.cwd(),
extractFromFormatMessageCall: true,
...opts
}
const newLocaleMaps = await _extractReactIntl(
locales,
pattern,
extractorOptions
)
return Promise.all(
locales.map((locale) => {
// If the default locale, overwrite the origin file
let localeMap =
locale === defaultLocale && overwriteDefault
? // Create a clone so we can use only current valid messages below
{ ...oldLocaleMaps[locale], ...newLocaleMaps[locale] }
: { ...newLocaleMaps[locale], ...oldLocaleMaps[locale] }
// Only keep existing keys
localeMap = Object.fromEntries(
Object.entries(localeMap).filter(([key]) =>
Object.keys(newLocaleMaps[locale]).includes(key)
)
)
const fomattedLocaleMap: object = flat
? sortKeys(localeMap, { deep: true })
: sortKeys(unflatten(localeMap, { object: true }), { deep: true })
const fn = isJson(format) ? writeJson : writeYaml
return fn(path.resolve(buildDir, locale), fomattedLocaleMap, indent)
})
)
}
extractMessage.extractReactIntl = _extractReactIntl
export default extractMessage
================================================
FILE: src/test/fixtures/custom/a/messages.js
================================================
import { defineMessages } from '../i18n'
export default defineMessages({
hello: {
id: 'a.custom.hello',
defaultMessage: 'hello'
},
world: {
id: 'a.custom.world',
defaultMessage: 'world'
}
})
================================================
FILE: src/test/fixtures/custom/b/messages.js
================================================
import { defineMessages } from '../i18n'
export default defineMessages({
hello: {
id: 'b.custom.message',
defaultMessage: 'Message'
}
})
================================================
FILE: src/test/fixtures/custom/i18n.js
================================================
export { defineMessages } from 'react-intl'
================================================
FILE: src/test/fixtures/default/a/App.js
================================================
import React from 'react'
import { useIntl } from 'react-intl'
export const SubmitButton = () => {
const intl = useIntl()
const label = intl.formatMessage({
id: 'a.submit',
defaultMessage: 'Submit Button'
})
return
}
================================================
FILE: src/test/fixtures/default/a/messages.js
================================================
import { defineMessages } from 'react-intl'
export default defineMessages({
hello: {
id: 'a.hello',
defaultMessage: 'hello'
},
world: {
id: 'a.world',
defaultMessage: 'world'
}
})
================================================
FILE: src/test/fixtures/default/b/messages.js
================================================
import { defineMessages } from 'react-intl'
export default defineMessages({
hello: {
id: 'b.hello',
defaultMessage: 'hello'
},
world: {
id: 'b.world',
defaultMessage: 'world'
}
})
================================================
FILE: src/test/fixtures/removed/a/messages.js
================================================
import { defineMessages } from 'react-intl'
export default defineMessages({
hello: {
id: 'a.hello',
defaultMessage: 'hello'
}
})
================================================
FILE: src/test/fixtures/removed/b/messages.js
================================================
import { defineMessages } from 'react-intl'
export default defineMessages({
hello: {
id: 'b.hello',
defaultMessage: 'hello'
},
world: {
id: 'b.world',
defaultMessage: 'world'
}
})
================================================
FILE: src/test/fixtures/unsorted/a/messages.js
================================================
import { defineMessages } from 'react-intl'
export default defineMessages({
hello: {
id: 'a.hello',
defaultMessage: 'hello'
},
helloZ: {
id: 'z.hello',
defaultMessage: 'hello'
},
helloC: {
id: 'c.hello',
defaultMessage: 'hello'
},
world: {
id: 'a.world',
defaultMessage: 'world'
}
})
================================================
FILE: src/test/fixtures/unsorted/b/messages.js
================================================
import { defineMessages } from 'react-intl'
export default defineMessages({
hello: {
id: 'b.hello',
defaultMessage: 'hello'
},
helloY: {
id: 'y.hello',
defaultMessage: 'hello'
},
world: {
id: 'b.world',
defaultMessage: 'world'
}
})
================================================
FILE: src/test/json/__snapshots__/test.ts.snap
================================================
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`export json - nest 1`] = `
{
"a": {
"hello": "hello",
"submit": "Submit Button",
"world": "world",
},
"b": {
"hello": "hello",
"world": "world",
},
}
`;
exports[`export json - nest 2`] = `
{
"a": {
"hello": "",
"submit": "",
"world": "",
},
"b": {
"hello": "",
"world": "",
},
}
`;
exports[`export json 1`] = `
{
"a.hello": "hello",
"a.submit": "Submit Button",
"a.world": "world",
"b.hello": "hello",
"b.world": "world",
}
`;
exports[`export json 2`] = `
{
"a.hello": "",
"a.submit": "",
"a.world": "",
"b.hello": "",
"b.world": "",
}
`;
exports[`export json with removed messages 1`] = `
{
"a.hello": "hello",
"a.submit": "Submit Button",
"a.world": "world",
"b.hello": "hello",
"b.world": "world",
}
`;
exports[`export json with removed messages 2`] = `
{
"a.hello": "",
"a.submit": "",
"a.world": "",
"b.hello": "",
"b.world": "",
}
`;
exports[`export json with removed messages 3`] = `
{
"a.hello": "hello",
"b.hello": "hello",
"b.world": "world",
}
`;
exports[`export json with removed messages 4`] = `
{
"a.hello": "",
"b.hello": "",
"b.world": "",
}
`;
exports[`export using custom module 1`] = `
{
"a.custom.hello": "hello",
"a.custom.world": "world",
"b.custom.message": "Message",
}
`;
exports[`export using custom module 2`] = `
{
"a.custom.hello": "",
"a.custom.world": "",
"b.custom.message": "",
}
`;
exports[`sort keys 1`] = `
[
"a.hello",
"a.world",
"b.hello",
"b.world",
"c.hello",
"y.hello",
"z.hello",
]
`;
exports[`sort keys 2`] = `
[
"a.hello",
"a.world",
"b.hello",
"b.world",
"c.hello",
"y.hello",
"z.hello",
]
`;
exports[`with overwriteDefault 1`] = `
{
"a.custom.hello": "hello",
"a.custom.world": "world",
"b.custom.message": "Default Message",
}
`;
exports[`with overwriteDefault 2`] = `
{
"a.custom.hello": "",
"a.custom.world": "",
"b.custom.message": "",
}
`;
================================================
FILE: src/test/json/test.ts
================================================
import fs from 'fs'
import path from 'path'
import tempy from 'tempy'
import m from '../..'
test('export json', async () => {
const tmp = tempy.directory()
await m(['en', 'ja'], 'src/test/fixtures/default/**/*.js', tmp)
const en = JSON.parse(fs.readFileSync(path.resolve(tmp, 'en.json'), 'utf8'))
const ja = JSON.parse(fs.readFileSync(path.resolve(tmp, 'ja.json'), 'utf8'))
expect(en).toMatchSnapshot()
expect(ja).toMatchSnapshot()
})
test('export json with removed messages', async () => {
const tmp = tempy.directory()
await m(['en', 'ja'], 'src/test/fixtures/default/**/*.js', tmp)
const enBefore = JSON.parse(
fs.readFileSync(path.resolve(tmp, 'en.json'), 'utf8')
)
const jaBefore = JSON.parse(
fs.readFileSync(path.resolve(tmp, 'ja.json'), 'utf8')
)
expect(enBefore).toMatchSnapshot()
expect(jaBefore).toMatchSnapshot()
await m(['en', 'ja'], 'src/test/fixtures/removed/**/*.js', tmp)
const en = JSON.parse(fs.readFileSync(path.resolve(tmp, 'en.json'), 'utf8'))
const ja = JSON.parse(fs.readFileSync(path.resolve(tmp, 'ja.json'), 'utf8'))
expect(en).toMatchSnapshot()
expect(ja).toMatchSnapshot()
})
test('export json - nest', async () => {
const tmp = tempy.directory()
await m(['en', 'ja'], 'src/test/fixtures/default/**/*.js', tmp, {
defaultLocale: 'en',
flat: false
})
const en = JSON.parse(fs.readFileSync(path.resolve(tmp, 'en.json'), 'utf8'))
const ja = JSON.parse(fs.readFileSync(path.resolve(tmp, 'ja.json'), 'utf8'))
expect(en).toMatchSnapshot()
expect(ja).toMatchSnapshot()
})
test('sort keys', async () => {
const tmp = tempy.directory()
const enPath = path.resolve(tmp, 'en.json')
const jaPath = path.resolve(tmp, 'ja.json')
await m(['en', 'ja'], 'src/test/fixtures/unsorted/**/*.js', tmp)
const en = JSON.parse(fs.readFileSync(enPath, 'utf8'))
const ja = JSON.parse(fs.readFileSync(jaPath, 'utf8'))
expect(Object.keys(en)).toMatchSnapshot()
expect(Object.keys(ja)).toMatchSnapshot()
})
test('export using custom module', async () => {
const tmp = tempy.directory()
await m(['en', 'ja'], 'src/test/fixtures/custom/**/*.js', tmp, {
defaultLocale: 'en',
moduleSourceName: '../i18n'
})
const en = JSON.parse(fs.readFileSync(path.resolve(tmp, 'en.json'), 'utf8'))
const ja = JSON.parse(fs.readFileSync(path.resolve(tmp, 'ja.json'), 'utf8'))
expect(en).toMatchSnapshot()
expect(ja).toMatchSnapshot()
})
test('with overwriteDefault', async () => {
const tmp = tempy.directory()
fs.writeFileSync(
path.resolve(tmp, 'en.json'),
JSON.stringify(
{
'a.custom.hello': 'hello',
'a.custom.world': 'world',
'b.custom.message': 'Default Message'
},
null,
2
),
'utf8'
)
await m(['en', 'ja'], 'src/test/fixtures/custom/**/*.js', tmp, {
defaultLocale: 'en',
moduleSourceName: '../i18n',
overwriteDefault: false
})
const en = JSON.parse(fs.readFileSync(path.resolve(tmp, 'en.json'), 'utf8'))
const ja = JSON.parse(fs.readFileSync(path.resolve(tmp, 'ja.json'), 'utf8'))
expect(en).toMatchSnapshot()
expect(ja).toMatchSnapshot()
})
================================================
FILE: src/test/test.ts
================================================
import m from '..'
test('errors', async () => {
// @ts-expect-error testing invalid argument type
await expect(m('hello')).rejects.toThrow('Expected a Array')
// @ts-expect-error testing invalid argument type
await expect(m(['en', 'ja'], 2)).rejects.toThrow('Expected a string')
// @ts-expect-error testing invalid argument type
await expect(m(['en', 'ja'], 'app/', 2)).rejects.toThrow('Expected a string')
})
================================================
FILE: src/test/yaml/__snapshots__/test.ts.snap
================================================
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`export yaml - flat 1`] = `
{
"a.hello": "hello",
"a.submit": "Submit Button",
"a.world": "world",
"b.hello": "hello",
"b.world": "world",
}
`;
exports[`export yaml - flat 2`] = `
{
"a.hello": "",
"a.submit": "",
"a.world": "",
"b.hello": "",
"b.world": "",
}
`;
exports[`export yaml 1`] = `
{
"a": {
"hello": "hello",
"submit": "Submit Button",
"world": "world",
},
"b": {
"hello": "hello",
"world": "world",
},
}
`;
exports[`export yaml 2`] = `
{
"a": {
"hello": "",
"submit": "",
"world": "",
},
"b": {
"hello": "",
"world": "",
},
}
`;
exports[`exsit yaml 1`] = `
{
"a": {
"hello": "hello",
"submit": "Submit Button",
"world": "world",
},
"b": {
"hello": "hello",
"world": "world",
},
}
`;
exports[`exsit yaml 2`] = `
{
"a": {
"hello": "hello2",
"submit": "",
"world": "",
},
"b": {
"hello": "",
"world": "",
},
}
`;
================================================
FILE: src/test/yaml/test.ts
================================================
import fs from 'fs'
import path from 'path'
import tempy from 'tempy'
import tempWrite from 'temp-write'
import yaml from 'js-yaml'
import m from '../..'
const fixturesPath = 'src/test/fixtures/default/**/*.js'
const yamlLoad = (tmp: string, file = '') =>
yaml.load(fs.readFileSync(path.resolve(tmp, file), 'utf8'))
const defaultLocale = 'en'
test('export yaml', async () => {
const tmp = tempy.directory()
await m(['en', 'ja'], fixturesPath, tmp, { defaultLocale, format: 'yaml' })
expect(yamlLoad(tmp, 'en.yml')).toMatchSnapshot()
expect(yamlLoad(tmp, 'ja.yml')).toMatchSnapshot()
})
test('export yaml - flat', async () => {
const tmp = tempy.directory()
await m(['en', 'ja'], fixturesPath, tmp, {
defaultLocale,
format: 'yaml',
flat: true
})
expect(yamlLoad(tmp, 'en.yml')).toMatchSnapshot()
expect(yamlLoad(tmp, 'ja.yml')).toMatchSnapshot()
})
test('exsit yaml', async () => {
const x = { a: { hello: 'hello2' } }
const tmpEn = tempWrite.sync(yaml.dump(x), 'en.yml')
await m(['en'], fixturesPath, path.dirname(tmpEn), {
defaultLocale,
format: 'yaml'
})
expect(yaml.load(fs.readFileSync(tmpEn, 'utf8'))).toMatchSnapshot()
const tmpJa = tempWrite.sync(yaml.dump(x), 'ja.yml')
await m(['ja'], fixturesPath, path.dirname(tmpJa), {
defaultLocale,
format: 'yaml'
})
expect(yaml.load(fs.readFileSync(tmpJa, 'utf8'))).toMatchSnapshot()
})
================================================
FILE: tsconfig.json
================================================
{
"compilerOptions": {
/* Language and Environment */
"target": "ES2022",
"lib": ["ES2022", "DOM"],
"module": "Node16",
"moduleResolution": "Node16",
/* Modules */
"allowImportingTsExtensions": false,
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
/* Emit */
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "dist",
"removeComments": false,
"importHelpers": false,
"downlevelIteration": false,
/* Interop Constraints */
"allowJs": false,
"checkJs": false,
/* Type Checking */
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"useUnknownInCatchVariables": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"exactOptionalPropertyTypes": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": false,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": false,
/* Completeness */
"skipLibCheck": true
},
"include": ["src/**/*"],
"exclude": [
"node_modules",
"dist",
"**/*.test.ts",
"**/*.spec.ts",
"**/test.*"
]
}