Skip to content

Commit

Permalink
new: Add validate command. (#8)
Browse files Browse the repository at this point in the history
* Start on validation.

* Add more checks.

* Add validate command.

* Fix issues.

* Add React components.

* Polish.

* Add license.

* Improve validate output.

* Add docs.

* Update docs.
  • Loading branch information
milesj authored Nov 12, 2020
1 parent 6ee39cc commit 7155b20
Show file tree
Hide file tree
Showing 17 changed files with 676 additions and 128 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Miles Johnson

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.
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"scripts": {
"prepare": "beemo create-config --silent",
"setup": "beemo typescript",
"build": "yarn run packemon build --addEngines --checkLicenses --generateDeclaration",
"build": "yarn run packemon build --addEngines --generateDeclaration",
"validate": "yarn run packemon validate",
"ci": "yarn run type && yarn run test && yarn run lint",
"clean": "rm -rf {build,dts,lib}",
"coverage": "yarn run test --coverage",
Expand All @@ -20,7 +21,7 @@
"release": "npx np --yolo",
"test": "beemo jest",
"type": "beemo typescript --noEmit",
"prerelease": "yarn run ci && yarn run setup && yarn run build",
"prerelease": "yarn run ci && yarn run setup && yarn run build && yarn run validate",
"packemon": "node ./build/bin.js"
},
"repository": "https://github.com/milesj/packemon.git",
Expand Down Expand Up @@ -59,9 +60,9 @@
},
"devDependencies": {
"@milesj/build-tools": "^2.13.1",
"@types/fs-extra": "^9.0.2",
"@types/node": "^14.14.6",
"@types/react": "^16.9.55",
"@types/fs-extra": "^9.0.4",
"@types/node": "^14.14.7",
"@types/react": "^16.9.56",
"@types/rimraf": "^3.0.0",
"@types/semver": "^7.3.4"
},
Expand All @@ -71,13 +72,13 @@
"@babel/preset-flow": "^7.12.1",
"@babel/preset-react": "^7.12.5",
"@babel/preset-typescript": "^7.12.1",
"@boost/cli": "^2.4.4",
"@boost/common": "^2.3.0",
"@boost/debug": "^2.1.4",
"@boost/cli": "^2.6.0",
"@boost/common": "^2.4.0",
"@boost/debug": "^2.1.5",
"@boost/event": "^2.2.0",
"@boost/pipeline": "^2.1.5",
"@boost/pipeline": "^2.1.6",
"@boost/terminal": "^2.1.0",
"@microsoft/api-extractor": "^7.11.2",
"@microsoft/api-extractor": "^7.11.4",
"@rollup/plugin-babel": "^5.2.1",
"@rollup/plugin-commonjs": "^16.0.0",
"@rollup/plugin-node-resolve": "^10.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"rules": {
"no-console": "off",
"no-magic-numbers": "off",
"no-use-before-define": "off",
"sort-keys": "off",
"promise/always-return": "off"
}
Expand Down
35 changes: 6 additions & 29 deletions src/Package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

import fs from 'fs-extra';
import ts from 'typescript';
import spdxLicenses from 'spdx-license-list';
import { Memoize, Path, toArray } from '@boost/common';
import Artifact from './Artifact';
import Project from './Project';
import PackageValidator from './PackageValidator';
import {
FeatureFlags,
PackageConfig,
BuildOptions,
PackemonPackage,
PackemonPackageConfig,
TSConfigStructure,
ValidateOptions,
} from './types';

export default class Package {
Expand Down Expand Up @@ -44,10 +45,6 @@ export default class Package {
}

async build(options: BuildOptions): Promise<void> {
if (options.checkLicenses) {
this.checkLicense();
}

// Build artifacts in parallel
await Promise.all(
this.artifacts.map(async (artifact) => {
Expand Down Expand Up @@ -79,6 +76,10 @@ export default class Package {
await Promise.all(this.artifacts.map((artifact) => artifact.cleanup()));
}

async validate(options: ValidateOptions): Promise<PackageValidator> {
return new PackageValidator(this.path, this.packageJson).validate(options);
}

getName(): string {
return this.packageJson.name;
}
Expand Down Expand Up @@ -196,30 +197,6 @@ export default class Package {
return result;
}

protected checkLicense() {
const { packageJson: contents } = this;
const spdxLicenseTypes = new Set(
Object.keys(spdxLicenses).map((key) => key.toLocaleLowerCase()),
);

if (contents.license) {
toArray(
typeof contents.license === 'string'
? { type: contents.license, url: spdxLicenses[contents.license] }
: contents.license,
).forEach((license) => {
if (!spdxLicenseTypes.has(license.type.toLocaleLowerCase())) {
console.error(
`Invalid license ${license.type} for package "${this.getName()}".`,
'Must be an official SPDX license type.',
);
}
});
} else {
console.error(`No license found for package "${this.getName()}".`);
}
}

protected async syncPackageJson() {
await fs.writeJson(this.packageJsonPath.path(), this.packageJson, { spaces: 2 });
}
Expand Down
Loading

0 comments on commit 7155b20

Please sign in to comment.