1
0
mirror of synced 2025-12-19 18:10:59 -05:00
Files
docs/script/prevent-translation-commits.js
Kevin Heis 42e785b0a8 Migrate CommonJS to ESM (#20301)
* First run of script

* Get the app running --- ish

* Get NextJS working

* Remove `node:`

* Get more tests passing in unit directory

* Update FailBot test to use nock

* Update test.yml

* Update Dockerfile

* tests/content fixes

* Update page.js

* Update build-changelog.js

* updating tests/routing

* Update orphan-tests.js

* updating tests/rendering

* Update .eslintrc.js

* Update .eslintrc.js

* Install jest/globals

* "linting" tests

* staging update to server.mjs

* Change '.github/allowed-actions.js' to a ESM export

* Lint

* Fixes for the main package.json

* Move Jest to be last in the npm test command so we can pass args

* Just use 'npm run lint' in the npm test command

* update algolia label script

* update openapi script

* update require on openapi

* Update enterprise-algolia-label.js

* forgot JSON.parse

* Update lunr-search-index.js

* Always explicitly include process.cwd() for JSON file reads pathed from project root

* update graphql/update-files.js script

* Update other npm scripts using jest to pass ESM NODE_OPTIONS

* Update check-for-enterprise-issues-by-label.js for ESM

* Update create-enterprise-issue.js for ESM

* Import jest global for browser tests

* Convert 'script/deploy' to ESM

Co-authored-by: Grace Park <gracepark@github.com>
Co-authored-by: James M. Greene <jamesmgreene@github.com>
2021-07-14 13:49:18 -07:00

34 lines
1.6 KiB
JavaScript
Executable File

#!/usr/bin/env node
import xDotenv from 'dotenv'
import { execSync } from 'child_process'
// [start-readme]
//
// This script is run as a git precommit hook (installed by husky after npm install).
// It detects changes to files the in the translations folder and prevents the commit
// if any changes exist.
//
// [end-readme]
xDotenv.config()
// Ignore this hook in GitHub Actions workflows
if (process.env.CI) process.exit()
// Allow this hook to be overriden with an environment variable
if (process.env.ALLOW_TRANSLATION_COMMITS) process.exit()
const filenames = execSync('git diff --cached --name-only').toString().trim().split('\n')
const localizedFilenames = filenames.filter(filename => filename.startsWith('translations/'))
if (localizedFilenames.length) {
console.error('\n✋ Uh oh! Detected changes to the following files in the `/translations` directory:')
console.table(localizedFilenames.join('\n'))
console.error('The content in this directory is managed by our Crowdin integration and should not be edited directly in the repo.')
console.error('For more information on how the localization process works, see translations/README.md')
console.error('\nIf you have accidentally edited these files, you can unstage these changes on the command line using `git restore --staged translations`\n')
console.error('\nIf you are performing a merge from `main`, you should bypass this hook by using ` git commit --no-verify`\n')
console.error('\nIf you need to edit translated files often, you can set `ALLOW_TRANSLATION_COMMITS=true` in your .env file.`\n')
process.exit(1)
}