forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add/generate/verify NOTICE.txt file (#17504)
* [dev/notice] add scripts for generating NOTICE.txt file * [notice] react-resize-detector@0.6.0 was removed in b445389 * [notice] move notice text into relevant source * [dev/notice] Generate NOTICE.txt file * [jenkins] verify that notice.txt is up to date in CI * [tasks/notice] update test to use new NOTICE.txt file * [dev/notice] update company name in NOTICE.txt * [notice/cli] exit with 0 when --help requested * [notice/cli] add helpful logging * [notice/cli] use --validate flag name instead * [notice/cli] simplify NEWLINE_RE, ignore obscure line endings * [utils/decode_geo_hash] fixup comment * [utils/decode_geo_hash] remove useless comment
- Loading branch information
Showing
15 changed files
with
490 additions
and
54 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
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,2 @@ | ||
require('../src/babel-register'); | ||
require('../src/dev/notice/cli'); |
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,74 @@ | ||
import { readFileSync, writeFileSync } from 'fs'; | ||
import { resolve, relative } from 'path'; | ||
|
||
import getopts from 'getopts'; | ||
import dedent from 'dedent'; | ||
import { createToolingLog, pickLevelFromFlags } from '@kbn/dev-utils'; | ||
|
||
import { REPO_ROOT } from '../constants'; | ||
import { generateNoticeText } from './generate_notice_text'; | ||
|
||
const NOTICE_PATH = resolve(REPO_ROOT, 'NOTICE.txt'); | ||
|
||
const unknownFlags = []; | ||
const opts = getopts(process.argv.slice(2), { | ||
boolean: [ | ||
'help', | ||
'validate', | ||
'verbose', | ||
'debug', | ||
], | ||
unknown(flag) { | ||
unknownFlags.push(flag); | ||
} | ||
}); | ||
|
||
const log = createToolingLog(pickLevelFromFlags(opts)); | ||
log.pipe(process.stdout); | ||
|
||
if (unknownFlags.length) { | ||
log.error(`Unknown flags ${unknownFlags.map(f => `"${f}"`).join(',')}`); | ||
process.exitCode = 1; | ||
opts.help = true; | ||
} | ||
|
||
if (opts.help) { | ||
process.stdout.write('\n' + dedent` | ||
Regenerate or validate NOTICE.txt. | ||
Entries in NOTICE.txt are collected by finding all multi-line comments | ||
that start with a "@notice" tag and copying their text content into | ||
NOTICE.txt at the root of the repository. | ||
Options: | ||
--help Show this help info | ||
--validate Don't write the NOTICE.txt, just fail if updates would have been made | ||
--verbose Set logging level to verbose | ||
--debug Set logging level to debug | ||
` + '\n\n'); | ||
process.exit(); | ||
} | ||
|
||
(async function run() { | ||
log.info('Searching source files for multi-line comments starting with @notify'); | ||
const newText = await generateNoticeText(log); | ||
if (!opts.validate) { | ||
log.info('Wrote notice text to', NOTICE_PATH); | ||
writeFileSync(NOTICE_PATH, newText, 'utf8'); | ||
return; | ||
} | ||
|
||
const currentText = readFileSync(NOTICE_PATH, 'utf8'); | ||
if (currentText === newText) { | ||
log.success(NOTICE_PATH, 'is up to date'); | ||
return; | ||
} | ||
|
||
log.error( | ||
`${relative(process.cwd(), NOTICE_PATH)} is out of date, run \`node scripts/notice\` to update the file and commit the results.` | ||
); | ||
process.exit(1); | ||
}()).catch(error => { | ||
log.error(error); | ||
process.exit(1); | ||
}); |
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,67 @@ | ||
import vfs from 'vinyl-fs'; | ||
|
||
import { REPO_ROOT } from '../constants'; | ||
|
||
const NOTICE_COMMENT_RE = /\/\*[\s\n\*]*@notice([\w\W]+?)\*\//g; | ||
const NEWLINE_RE = /\r?\n/g; | ||
|
||
export async function generateNoticeText(log) { | ||
const globs = [ | ||
'**/*.{js,less,css,ts}', | ||
]; | ||
|
||
const options = { | ||
cwd: REPO_ROOT, | ||
nodir: true, | ||
ignore: [ | ||
'{node_modules,build,target,dist,optimize}/**', | ||
'packages/*/{node_modules,build,target,dist}/**', | ||
] | ||
}; | ||
|
||
log.debug('vfs.src globs', globs); | ||
log.debug('vfs.src options', options); | ||
const files = vfs.src(globs, options); | ||
|
||
const noticeComments = []; | ||
await new Promise((resolve, reject) => { | ||
files | ||
.on('data', (file) => { | ||
log.verbose(`Checking for @notice comments in ${file.relative}`); | ||
|
||
const source = file.contents.toString('utf8'); | ||
let match; | ||
while ((match = NOTICE_COMMENT_RE.exec(source)) !== null) { | ||
log.info(`Found @notice comment in ${file.relative}`); | ||
noticeComments.push(match[1]); | ||
} | ||
}) | ||
.on('error', reject) | ||
.on('end', resolve); | ||
}); | ||
|
||
let noticeText = ''; | ||
noticeText += 'Kibana\n'; | ||
noticeText += `Copyright 2012-${(new Date()).getUTCFullYear()} Elasticsearch B.V.\n`; | ||
|
||
for (const comment of noticeComments.sort()) { | ||
noticeText += '\n---\n'; | ||
noticeText += comment | ||
.split(NEWLINE_RE) | ||
.map(line => ( | ||
line | ||
// trim whitespace | ||
.trim() | ||
// trim leading * and a single space | ||
.replace(/(^\* ?)/, '') | ||
)) | ||
.join('\n') | ||
.trim(); | ||
noticeText += '\n'; | ||
} | ||
|
||
noticeText += '\n'; | ||
|
||
log.debug(`notice text:\n\n${noticeText}`); | ||
return noticeText; | ||
} |
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 @@ | ||
export { generateNoticeText } from './generate_notice_text'; |
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
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
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
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
Oops, something went wrong.