@donmahallem/lerna2codecov 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ export interface ICodecovProject {
2
+ paths?: string[];
3
+ }
4
+ export declare type CodecovProjects = {
5
+ [key: string]: ICodecovProject;
6
+ };
7
+ export interface ICodecovConfig {
8
+ coverage?: {
9
+ status?: {
10
+ project?: CodecovProjects;
11
+ };
12
+ };
13
+ }
14
+ //# sourceMappingURL=codecov-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codecov-config.d.ts","sourceRoot":"","sources":["../../src/codecov-config.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,eAAe;IAC5B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AACD,oBAAY,eAAe,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAA;CAAE,CAAC;AACjE,MAAM,WAAW,cAAc;IAC3B,QAAQ,CAAC,EAAE;QACP,MAAM,CAAC,EAAE;YACL,OAAO,CAAC,EAAE,eAAe,CAAC;SAC7B,CAAC;KACL,CAAC;CACL"}
@@ -0,0 +1,3 @@
1
+ export * from './codecov-config';
2
+ export { IUpdateOptions, updateConfig } from './update-config';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { Command } from 'commander';
2
+ /**
3
+ * @param opts
4
+ * @param opts.exitOverride
5
+ */
6
+ export declare function updateCommand(opts?: {
7
+ exitOverride: boolean;
8
+ }): Command;
9
+ //# sourceMappingURL=update-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-command.d.ts","sourceRoot":"","sources":["../../src/update-command.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAcpC;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,CAAC,EAAE;IAAE,YAAY,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAwBvE"}
@@ -0,0 +1,13 @@
1
+ import { Project } from '@lerna/project';
2
+ import { ICodecovConfig } from './codecov-config';
3
+ export interface IUpdateOptions {
4
+ stripScope?: boolean;
5
+ }
6
+ /**
7
+ * @param {Project} project Lerna Project
8
+ * @param {import('./codecov-config').ICodecovConfig} codecovCfg parsed codecov config
9
+ * @param {IUpdateOptions} opts Options
10
+ * @returns {Promise<ICodecovConfig>} a promise which resolves with the updated Codecov config
11
+ */
12
+ export declare function updateConfig(project: Project, codecovCfg: ICodecovConfig, opts?: IUpdateOptions): Promise<ICodecovConfig>;
13
+ //# sourceMappingURL=update-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-config.d.ts","sourceRoot":"","sources":["../../src/update-config.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGzC,OAAO,EAAmB,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEnE,MAAM,WAAW,cAAc;IAC3B,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB;AAgBD;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAwB/H"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @param {string} lernaRoot path to lerna project root
3
+ * @param {string} codecovFile path to codecov file
4
+ * @returns {Promise<void>} a Promise which resolves on success
5
+ */
6
+ export declare function update(lernaRoot: string, codecovFile: string): Promise<void>;
7
+ //# sourceMappingURL=update.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../src/update.ts"],"names":[],"mappings":"AAWA;;;;GAIG;AACH,wBAAsB,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAWlF"}
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@donmahallem/lerna2codecov",
3
+ "version": "0.1.0",
4
+ "description": "Updates projects entry in codecov.yml from lerna project",
5
+ "main": "dist/cjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/types/index.d.ts",
8
+ "private": false,
9
+ "keywords": [
10
+ "lerna",
11
+ "codecov"
12
+ ],
13
+ "scripts": {
14
+ "build": "rollup -c ./rollup.config.js && npm run build:types",
15
+ "build:types": "tsc --project ./tsconfig.lib.json -d --declarationDir dist/types --declarationMap --emitDeclarationOnly",
16
+ "build:readme": "npx @appnest/readme generate --input ../package_readme_blueprint.md --config readme_config.json",
17
+ "test": "mocha --config ../../.mocharc.yml",
18
+ "test:coverage": "nyc --nycrc-path ../../.nycrc.json npm run test",
19
+ "lint": "eslint -c ./.eslintrc.js --ext .ts ./src",
20
+ "postlint": "prettier --config ./../../.prettierrc src/**/*.ts --check",
21
+ "lint:fix": "eslint -c ./.eslintrc.js --ext .ts ./src --fix",
22
+ "postlint:fix": "prettier --config ./../../.prettierrc src/**/*.ts --write",
23
+ "docs": "typedoc --options ./typedoc.config.js",
24
+ "prepublishOnly": "npm run clean && npm run test && npm run docs && npm run build",
25
+ "version": "npm run build:readme && git add README.md",
26
+ "clean": "rimraf ./dist ./.nyc_output ./coverage ./docs"
27
+ },
28
+ "homepage": "https://github.com/donmahallem/js-libs/tree/master/packages/lerna2codecov",
29
+ "author": {
30
+ "name": "donmahallem",
31
+ "email": "donmahallem@users.noreply.github.com",
32
+ "url": "https://github.com/donmahallem"
33
+ },
34
+ "license": "Apache-2.0",
35
+ "bugs": {
36
+ "url": "https://github.com/donmahallem/js-libs/issues"
37
+ },
38
+ "bin": {
39
+ "lerna2codecov": "./dist/cli/cli.js"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "https://github.com/donmahallem/js-libs.git"
44
+ },
45
+ "engines": {
46
+ "node": ">=14"
47
+ },
48
+ "files": [
49
+ "dist/*",
50
+ "src/*",
51
+ "!src/**/*.spec.ts"
52
+ ],
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "dependencies": {
57
+ "@lerna/project": "~4.0.0",
58
+ "commander": "^8.3.0",
59
+ "deepmerge": "~4.2.2",
60
+ "yaml": "~1.10.2"
61
+ },
62
+ "devDependencies": {
63
+ "@types/deepmerge": "2.2.0",
64
+ "@types/lerna__package": "4.0.0",
65
+ "@types/lerna__project": "4.0.0"
66
+ },
67
+ "gitHead": "565f053c83362152c3b55c270efee1088e6aae47"
68
+ }
package/src/cli.ts ADDED
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Package @donmahallem/lerna2codecov
3
+ * Source https://github.com/donmahallem/js-libs/tree/master/packages/lerna2codecov
4
+ */
5
+
6
+ import { updateCommand } from './update-command';
7
+
8
+ void updateCommand().parseAsync(process.argv);
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Package @donmahallem/lerna2codecov
3
+ * Source https://github.com/donmahallem/js-libs/tree/master/packages/lerna2codecov
4
+ */
5
+
6
+ export interface ICodecovProject {
7
+ paths?: string[];
8
+ }
9
+ export type CodecovProjects = { [key: string]: ICodecovProject };
10
+ export interface ICodecovConfig {
11
+ coverage?: {
12
+ status?: {
13
+ project?: CodecovProjects;
14
+ };
15
+ };
16
+ }
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ /*
2
+ * Package @donmahallem/lerna2codecov
3
+ * Source https://github.com/donmahallem/js-libs/tree/master/packages/lerna2codecov
4
+ */
5
+
6
+ export * from './codecov-config';
7
+ export { IUpdateOptions, updateConfig } from './update-config';
@@ -0,0 +1,48 @@
1
+ /*
2
+ * Package @donmahallem/lerna2codecov
3
+ * Source https://github.com/donmahallem/js-libs/tree/master/packages/lerna2codecov
4
+ */
5
+
6
+ import { Command } from 'commander';
7
+ import { resolve } from 'path';
8
+ import { update } from './update';
9
+
10
+ interface IUpdateOptions {
11
+ codecov: string;
12
+ lerna: string;
13
+ }
14
+ /**
15
+ * @param path
16
+ */
17
+ function resolvePath(path: string): string {
18
+ return resolve(path);
19
+ }
20
+ /**
21
+ * @param opts
22
+ * @param opts.exitOverride
23
+ */
24
+ export function updateCommand(opts?: { exitOverride: boolean }): Command {
25
+ const program: Command = new Command('lerna2codecov');
26
+ program
27
+ /**
28
+ * version gets replaced by rollup
29
+ */
30
+ .version('__BUILD_VERSION__')
31
+ .addHelpText('beforeAll', 'Update script for codecov configs');
32
+ const updateCommand: Command = new Command('update');
33
+ if (opts?.exitOverride) {
34
+ program.exitOverride();
35
+ updateCommand.exitOverride();
36
+ }
37
+ updateCommand
38
+ .description('Updates the codecov.yml with information from lerna.json file')
39
+ .requiredOption('-l, --lerna <path>', 'path to lerna root folder', resolvePath)
40
+ .requiredOption('-c, --codecov <path>', 'path to codecov.yml', resolvePath)
41
+ .usage('-c <codecov file path> -l <lerna root folder>')
42
+ .action(async (opts: IUpdateOptions, cmd: Command): Promise<void> => {
43
+ await update(opts.lerna, opts.codecov);
44
+ })
45
+ .addHelpText('after', '\nExamples:\n update -l ./path/to/lerna -c codecov.yml');
46
+ program.addCommand(updateCommand);
47
+ return program;
48
+ }
@@ -0,0 +1,60 @@
1
+ /*
2
+ * Package @donmahallem/lerna2codecov
3
+ * Source https://github.com/donmahallem/js-libs/tree/master/packages/lerna2codecov
4
+ */
5
+
6
+ import { Package } from '@lerna/package';
7
+ import { Project } from '@lerna/project';
8
+ import deepmerge from 'deepmerge';
9
+ import { relative } from 'path';
10
+ import { CodecovProjects, ICodecovConfig } from './codecov-config';
11
+
12
+ export interface IUpdateOptions {
13
+ stripScope?: boolean;
14
+ }
15
+
16
+ /**
17
+ * Removes potential scopes from the package name
18
+ *
19
+ * @param {Package|string} packageName Package Name
20
+ * @returns {string} the striped package name
21
+ */
22
+ function stripScope(packageName: string | Package): string {
23
+ if (packageName instanceof Package) {
24
+ return stripScope(packageName.get('name'));
25
+ }
26
+ const sliced: string[] = packageName.split('/');
27
+ return sliced.length > 1 ? sliced.slice(1).join('/') : packageName;
28
+ }
29
+
30
+ /**
31
+ * @param {Project} project Lerna Project
32
+ * @param {import('./codecov-config').ICodecovConfig} codecovCfg parsed codecov config
33
+ * @param {IUpdateOptions} opts Options
34
+ * @returns {Promise<ICodecovConfig>} a promise which resolves with the updated Codecov config
35
+ */
36
+ export async function updateConfig(project: Project, codecovCfg: ICodecovConfig, opts?: IUpdateOptions): Promise<ICodecovConfig> {
37
+ const stripScopeInName: boolean = opts?.stripScope || true;
38
+ const packages: Package[] = await project.getPackages();
39
+ if (packages.length === 0) {
40
+ return codecovCfg;
41
+ }
42
+ const codecovProjects: CodecovProjects = {};
43
+ const sourcePackages: CodecovProjects = codecovCfg?.coverage?.status?.project || {};
44
+ for (const pkg of packages) {
45
+ const stripedPackageName: string = stripScopeInName ? stripScope(pkg) : pkg.get('name');
46
+ if (stripedPackageName in sourcePackages) {
47
+ continue;
48
+ }
49
+ codecovProjects[stripedPackageName] = {
50
+ paths: [relative(project.rootPath, pkg.location)],
51
+ };
52
+ }
53
+ return deepmerge(codecovCfg, {
54
+ coverage: {
55
+ status: {
56
+ project: codecovProjects,
57
+ },
58
+ },
59
+ });
60
+ }
package/src/update.ts ADDED
@@ -0,0 +1,28 @@
1
+ /*
2
+ * Package @donmahallem/lerna2codecov
3
+ * Source https://github.com/donmahallem/js-libs/tree/master/packages/lerna2codecov
4
+ */
5
+
6
+ import { Project } from '@lerna/project';
7
+ import { promises as fsp } from 'fs';
8
+ import { parse, stringify } from 'yaml';
9
+ import { ICodecovConfig } from './codecov-config';
10
+ import { updateConfig } from './update-config';
11
+
12
+ /**
13
+ * @param {string} lernaRoot path to lerna project root
14
+ * @param {string} codecovFile path to codecov file
15
+ * @returns {Promise<void>} a Promise which resolves on success
16
+ */
17
+ export async function update(lernaRoot: string, codecovFile: string): Promise<void> {
18
+ let codecovSourceFile: string;
19
+ try {
20
+ codecovSourceFile = await fsp.readFile(codecovFile, 'utf-8');
21
+ } catch (err: unknown) {
22
+ codecovSourceFile = '';
23
+ }
24
+ const parsedCodecovSource: ICodecovConfig = parse(codecovSourceFile) as ICodecovConfig;
25
+ const updatedConfig: ICodecovConfig = await updateConfig(new Project(lernaRoot), parsedCodecovSource);
26
+ const outputCodecovConfig: string = stringify(updatedConfig);
27
+ return await fsp.writeFile(codecovFile, outputCodecovConfig, 'utf-8');
28
+ }