-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(clang-format-git-python): create new package named `clang-format…
…-git-python` (#79) A new feature has arrived. `clang-format-git-python` is now available. See: #60 * wip: update root's `package-lock.json` and package's `package.json` * rename: change the directory of `git-clang-format` * wip: create `clangFormatGitPath.js` * wip: create `index.js` * wip: create `cli.js` * test: create `index.test.js` * test: create `clangFormatGitPath.test.js` * test: create `cli.test.js` * ci: change the target path of download-artifact in `llvm-build-bump-pr` * chore: update `postinstall` script and delete `pretest` script * rename: `clangFormatGitPath.js` to `gitClangFormatPath.js` * style: change the order of `gitClangFormatPath` and `clangFormatGitPath` * rename: `git-clang-format-python` to `git-clang-format` * rename: variable `clangFormatGitPath` to `clangFormatGitPythonPath` * chore: update `package-lock.json` * wip
- Loading branch information
1 parent
83aae8c
commit 063411e
Showing
12 changed files
with
131 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env node | ||
|
||
const { spawn } = require('child_process'); | ||
|
||
const { clangFormatPath } = require('clang-format-node'); | ||
|
||
const { gitClangFormatPath } = require('./utils/gitClangFormatPath'); | ||
|
||
const spawned = spawn( | ||
'python', | ||
// Both `--binary=path/to/the/binary` and `--binary path/to/the/binary` commands are valid (the only difference is the `=`). | ||
// | ||
// If you pass a `--binary` argument like `npx git-clang-format-python --binary="path/to/the/binary"` in bash, | ||
// the `--binary="path/to/the/binary"` argument will override the current `--binary=${clangFormatPath}` code. | ||
[gitClangFormatPath, `--binary=${clangFormatPath}`, ...process.argv.slice(2)], | ||
{ | ||
stdio: 'inherit', | ||
}, | ||
); | ||
|
||
spawned.on('close', code => { | ||
if (code !== 0) { | ||
// eslint-disable-next-line no-console | ||
console.error(`Process exited with code: ${code}`); | ||
process.exit(code); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const { doesNotThrow, throws } = require('node:assert'); | ||
const { execSync } = require('node:child_process'); | ||
const { resolve } = require('node:path'); | ||
const { describe, it } = require('node:test'); | ||
|
||
const cli = resolve(__dirname, 'cli.js'); | ||
|
||
describe('cli doesNotThrow and throws testing', () => { | ||
// Correct | ||
it('node cli.js', () => { | ||
doesNotThrow(() => { | ||
execSync(`node ${cli}`); // Expected output: 'no modified files to format' | ||
}); | ||
}); | ||
it('node cli.js --help', () => { | ||
doesNotThrow(() => { | ||
execSync(`node ${cli} --help`); | ||
}); | ||
}); | ||
|
||
// Wrong | ||
it('node cli.js --abcdefg', () => { | ||
throws(() => { | ||
execSync(`node ${cli} --abcdefg`); | ||
}); | ||
}); | ||
it('node cli.js --binary=', () => { | ||
throws(() => { | ||
execSync(`node ${cli} --binary=`); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const { | ||
gitClangFormatPath, | ||
clangFormatGitPythonPath, | ||
} = require('./utils/gitClangFormatPath'); | ||
|
||
module.exports = { | ||
gitClangFormatPath, | ||
clangFormatGitPythonPath, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const { ok } = require('node:assert'); | ||
const { describe, it } = require('node:test'); | ||
|
||
const { gitClangFormatPath, clangFormatGitPythonPath } = require('./index'); | ||
|
||
describe('index ok testing', () => { | ||
it('gitClangFormatPath should be imported correctly', () => { | ||
ok(gitClangFormatPath); | ||
}); | ||
it('clangFormatGitPythonPath should be imported correctly', () => { | ||
ok(clangFormatGitPythonPath); | ||
}); | ||
}); |
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
packages/clang-format-git-python/src/utils/gitClangFormatPath.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const { resolve } = require('path'); | ||
|
||
/** | ||
* The ABSOLUTE path to the [`git-clang-format`](../script/git-clang-format) Python script. | ||
* | ||
* @alias `clangFormatGitPythonPath`({@link clangFormatGitPythonPath}) | ||
*/ | ||
const gitClangFormatPath = resolve(__dirname, `..`, `script`, `git-clang-format`); | ||
|
||
/** | ||
* The ABSOLUTE path to the [`git-clang-format`](../script/git-clang-format) Python script. | ||
* | ||
* @alias `gitClangFormatPath`({@link gitClangFormatPath}) | ||
*/ | ||
const clangFormatGitPythonPath = gitClangFormatPath; | ||
|
||
module.exports = { | ||
gitClangFormatPath, | ||
clangFormatGitPythonPath, | ||
}; |
17 changes: 17 additions & 0 deletions
17
packages/clang-format-git-python/src/utils/gitClangFormatPath.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const { strictEqual } = require('node:assert'); | ||
const { resolve } = require('node:path'); | ||
const { describe, it } = require('node:test'); | ||
|
||
const { gitClangFormatPath, clangFormatGitPythonPath } = require('./gitClangFormatPath'); | ||
|
||
describe('gitClangFormatPath strictEqual testing', () => { | ||
it('gitClangFormatPath === clangFormatGitPythonPath', () => { | ||
strictEqual(gitClangFormatPath, clangFormatGitPythonPath); | ||
}); | ||
it('clangFormatGitPythonPath === resolve(__dirname, `..`, `script`, `git-clang-format`)', () => { | ||
strictEqual( | ||
clangFormatGitPythonPath, | ||
resolve(__dirname, `..`, `script`, `git-clang-format`), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters