-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CB-4911 feat: use node for license check
- Loading branch information
Showing
4 changed files
with
67 additions
and
37 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
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 |
---|---|---|
@@ -1,10 +1 @@ | ||
#!/usr/bin/env sh | ||
source ./webapp/scripts/license.sh | ||
|
||
validate_missed_license "/* | ||
* CloudBeaver - Cloud Database Manager | ||
* Copyright (C) 2020-2024 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0. | ||
* you may not use this file except in compliance with the License. | ||
*/" "^.+\.(ts|tsx|css|scss)$" | ||
node ./webapp/scripts/license-check.mjs ./.vscode/license.code-snippets license |
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,65 @@ | ||
import { exec, execSync } from 'child_process'; | ||
import fs from 'fs'; | ||
import { resolve } from 'path'; | ||
import { createInterface } from 'readline'; | ||
|
||
const snippetPath = resolve(process.argv[2]); | ||
const snippetName = process.argv[3]; | ||
const snippets = JSON.parse(fs.readFileSync(snippetPath, 'utf8')); | ||
const licenseSnippet = snippets[snippetName]; | ||
|
||
const scopes = licenseSnippet.scope.split(','); | ||
const license = licenseSnippet.body; | ||
const extensions = new Set(); | ||
|
||
for (const scope of scopes) { | ||
switch (scope.trim()) { | ||
case 'typescript': | ||
extensions.add('.ts'); | ||
break; | ||
case 'typescriptreact': | ||
extensions.add('.tsx'); | ||
break; | ||
case 'javascript': | ||
extensions.add('.js'); | ||
break; | ||
case 'javascriptreact': | ||
extensions.add('.jsx'); | ||
break; | ||
case 'css': | ||
extensions.add('.css'); | ||
break; | ||
case 'scss': | ||
extensions.add('.scss'); | ||
break; | ||
} | ||
} | ||
|
||
const output = exec('git diff --cached --name-only --diff-filter=ACMR'); | ||
const rl = createInterface(output.stdout); | ||
const invalidFiles = []; | ||
|
||
for await (const line of rl) { | ||
const extension = line.slice(line.lastIndexOf('.')); | ||
if (extensions.has(extension)) { | ||
const fileRl = createInterface(fs.createReadStream(line)); | ||
|
||
let fileLineIndex = 0; | ||
for await (const fileLine of fileRl) { | ||
if (fileLine !== license[fileLineIndex]) { | ||
invalidFiles.push(line); | ||
break; | ||
} | ||
fileLineIndex++; | ||
if (fileLineIndex === license.length) { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (invalidFiles.length > 0) { | ||
execSync('git restore --staged ' + invalidFiles.join(' ')); | ||
process.stdout.write('Found files without license header. Please add license to all unstaged files.'); | ||
process.exit(1); | ||
} |
This file was deleted.
Oops, something went wrong.