Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Get git logs for both source and locale
const localeLog = await getLog(localePath)
const sourceLog = await getLog(sourcePath)
// If file is not commited, there's not much we can do
if (localeLog.total === 0) return 'unchanged'
// If file is newer than latest commit
// and value is changed then it's new
const { mtime } = await fs.stat(localePath)
const modifiedDate = new Date(mtime)
const commitDate = new Date(localeLog.latest.date)
if (modifiedDate > commitDate) {
const commitJson = await getJsonContent(localePath, localeLog.latest.hash)
if (helpers.getObjectValueByPath(commitJson, fileKey) !== helpers.getObjectValueByPath(localeJson, fileKey)) return 'new'
}
const latestSourceCommitDate = new Date(sourceLog.latest.date)
const latestLocaleCommitDate = new Date(localeLog.latest.date)
// If source has been updated after latest locale
// then we might have a mismatch
if (latestSourceCommitDate > latestLocaleCommitDate) {
const previousCommit = getPreviousCommit(sourceLog, localeLog.latest)
if (!previousCommit) throw new Error('asdasdas')
const oldJson = await getJsonContent(sourcePath, previousCommit.hash)
const newJson = await getJsonContent(sourcePath, sourceLog.latest.hash)
const changes = diffJson.diff(oldJson, newJson)
async function checkStatus (locale, key) {
const { sourcePath, localePath, fileKey } = getPaths(locale, key)
setupCache(sourcePath)
setupCache(localePath)
// If no file exists yet
// translation is missing
if (!fs.existsSync(localePath)) return 'missing'
// If file exists but no key found
// then we are missing translation
const localeJson = await fs.readJson(localePath)
if (!helpers.getObjectValueByPath(localeJson, fileKey)) return 'missing'
// Get git logs for both source and locale
const localeLog = await getLog(localePath)
const sourceLog = await getLog(sourcePath)
// If file is not commited, there's not much we can do
if (localeLog.total === 0) return 'unchanged'
// If file is newer than latest commit
// and value is changed then it's new
const { mtime } = await fs.stat(localePath)
const modifiedDate = new Date(mtime)
const commitDate = new Date(localeLog.latest.date)
if (modifiedDate > commitDate) {
const commitJson = await getJsonContent(localePath, localeLog.latest.hash)
if (helpers.getObjectValueByPath(commitJson, fileKey) !== helpers.getObjectValueByPath(localeJson, fileKey)) return 'new'
items () {
const [ section, name ] = this.name.split('/')
const kebab = upperFirst(camelCase(section))
return getObjectValueByPath(
this.tablesOfContents,
`${kebab}.${name}`,
[]
).map(item => ({
...item,
offsetTop: 0,
target: null
}))
}
},
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
const fn = this[`gen${capitalize(key)}`]
if (fn) {
newItem[key] = fn(newItem[key], item)
}
}
newItem.description = this.genDescription(item.name || item, item)
newItem.newIn = getObjectValueByPath(
this.newIn,
`${this.type}.${this.target}.${newItem.name}`
)
newItem.deprecatedIn = getObjectValueByPath(
this.deprecatedIn,
`${this.type}.${this.target}.${newItem.name}`
)
if (newItem.deprecatedIn === false) continue
if (!newItem.newIn && newItem.source) {
newItem.newIn = getObjectValueByPath(
this.newIn,
`${this.type}.${newItem.source}.${newItem.name}`
)
}
if (!newItem.deprecatedIn && newItem.source) {
newItem.deprecatedIn = getObjectValueByPath(
this.deprecatedIn,
newItem.description = this.genDescription(item.name || item, item)
newItem.newIn = getObjectValueByPath(
this.newIn,
`${this.type}.${this.target}.${newItem.name}`
)
newItem.deprecatedIn = getObjectValueByPath(
this.deprecatedIn,
`${this.type}.${this.target}.${newItem.name}`
)
if (newItem.deprecatedIn === false) continue
if (!newItem.newIn && newItem.source) {
newItem.newIn = getObjectValueByPath(
this.newIn,
`${this.type}.${newItem.source}.${newItem.name}`
)
}
if (!newItem.deprecatedIn && newItem.source) {
newItem.deprecatedIn = getObjectValueByPath(
this.deprecatedIn,
`${this.type}.${newItem.source}.${newItem.name}`
)
}
items[source].push(newItem)
}
return items
const newItem = item !== Object(item)
? { name: item }
: Object.assign({}, item)
const keys = Object.keys(newItem)
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
const fn = this[`gen${capitalize(key)}`]
if (fn) {
newItem[key] = fn(newItem[key], item)
}
}
newItem.description = this.genDescription(item.name || item, item)
newItem.newIn = getObjectValueByPath(
this.newIn,
`${this.type}.${this.target}.${newItem.name}`
)
newItem.deprecatedIn = getObjectValueByPath(
this.deprecatedIn,
`${this.type}.${this.target}.${newItem.name}`
)
if (newItem.deprecatedIn === false) continue
if (!newItem.newIn && newItem.source) {
newItem.newIn = getObjectValueByPath(
this.newIn,
`${this.type}.${newItem.source}.${newItem.name}`
)
newItem.deprecatedIn = getObjectValueByPath(
this.deprecatedIn,
`${this.type}.${this.target}.${newItem.name}`
)
if (newItem.deprecatedIn === false) continue
if (!newItem.newIn && newItem.source) {
newItem.newIn = getObjectValueByPath(
this.newIn,
`${this.type}.${newItem.source}.${newItem.name}`
)
}
if (!newItem.deprecatedIn && newItem.source) {
newItem.deprecatedIn = getObjectValueByPath(
this.deprecatedIn,
`${this.type}.${newItem.source}.${newItem.name}`
)
}
items[source].push(newItem)
}
return items
},
missingItems () {