diff --git a/src/packages/graphql-monitoring/LICENSE b/src/packages/graphql-monitoring/LICENSE deleted file mode 100644 index 08f2f9069bdba8b6050d33b1b7b7467f70898b91..0000000000000000000000000000000000000000 --- a/src/packages/graphql-monitoring/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2019 Alex Viscreanu - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/src/packages/monorepo-scanner/src/scans/Licenses.scan.js b/src/packages/monorepo-scanner/src/scans/Licenses.scan.js new file mode 100644 index 0000000000000000000000000000000000000000..c0d8f66f3c54e9f44d3d0bb733e19f76baee972c --- /dev/null +++ b/src/packages/monorepo-scanner/src/scans/Licenses.scan.js @@ -0,0 +1,82 @@ +// @flow strict-local + +import fs from 'fs'; +import path from 'path'; +import { Workspaces } from '@kiwicom/monorepo'; + +// Every package must have either: +// - licence defined as UNLICENSED and no license file, or +// - license defined as MIT and contain license file + +const supportedLicenses = ['UNLICENSED', 'MIT']; + +Workspaces.iterateWorkspaces(packageJSONLocation => { + // $FlowAllowDynamicImport + const packageJson = require(packageJSONLocation); + test(`License for workspace ${packageJson.name}`, () => { + const license = packageJson.license; + + expect( + license !== undefined && supportedLicenses.includes(license), + ).toGiveHelp( + `Every workspace must define its license in package.json file. It should be one of: ${supportedLicenses.join( + ', ', + )}`, + ); + + // license file should be on the same level as package.json + const licenseFilePath = path.join( + path.dirname(packageJSONLocation), + 'LICENSE', + ); + + if (license === 'UNLICENSED') { + expect(fs.existsSync(licenseFilePath) === false).toGiveHelp( + 'Unlicensed workspaces should not have LICENSE file in their root.', + ); + } else if (license === 'MIT') { + expect(fs.existsSync(licenseFilePath) === true).toGiveHelp( + 'Unlicensed workspaces must have LICENSE file in their root.', + ); + expect( + mitLicenseRegexp.test( + fs.readFileSync(licenseFilePath, { encoding: 'utf8' }), + ), + ).toGiveHelp( + `MIT license should follow standard format:\n\n${mitLicenseRegexp.toString()}`, + ); + } else { + throw new Error( + `Unknown workspace license. Supported licenses are: ${supportedLicenses.join( + ', ', + )}`, + ); + } + }); +}); + +const mitLicenseRegexp = new RegExp( + `MIT License + +Copyright \\(c\\) [0-9]{4}-present, Kiwi\\.com(?:.+)? + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files \\(the "Software"\\), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +`, + 's', +);