Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,16 @@
],
"production": ["default", "!{projectRoot}/src/test-setup.[jt]s"]
},
"plugins": [
{
"plugin": "@jscutlery/semver",
"options": {
"npmPublish": true,
"githubRelease": true,
"noVerify": true,
"commitMessageFormat": "release({projectName}): 🎸 cut release to {version}"
}
}
],
"parallel": 1
}
1 change: 1 addition & 0 deletions packages/semver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"main": "src/index.js",
"executors": "./executors.json",
"generators": "./generators.json",
"private": false,
"nx-migrations": {
"migrations": "./migrations.json"
},
Expand Down
23 changes: 0 additions & 23 deletions packages/semver/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,6 @@
"projectType": "library",
"generators": {},
"targets": {
"version": {
"executor": "./dist/packages/semver:version",
"options": {
"push": true,
"noVerify": true,
"postTargets": ["build", "publish", "github"],
"commitMessageFormat": "release({projectName}): 🎸 cut release to {version}"
}
},
"github": {
"executor": "./dist/packages/semver:github",
"options": {
"tag": "{tag}",
"notes": "{notes}"
}
},
"publish": {
"executor": "ngx-deploy-npm:deploy",
"options": {
"access": "public",
"distFolderPath": "dist/packages/semver"
}
},
"lint": {
"executor": "@nx/linter:eslint",
"options": {
Expand Down
1 change: 1 addition & 0 deletions packages/semver/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { createNodes } from './plugin';
90 changes: 90 additions & 0 deletions packages/semver/src/plugin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import {
CreateNodes,
ProjectConfiguration,
TargetConfiguration,
readJsonFile,
} from '@nx/devkit';
import { dirname, resolve } from 'path';

interface Options {
buildTarget?: string;
npmPublish?: boolean;
githubRelease?: boolean;
noVerify?: boolean;
commitMessageFormat?: string;
}

export const createNodes: CreateNodes<Options> = [
'**/package.json',
(packageJsonPath, opts) => {
opts ??= {};
opts.buildTarget ??= 'build';
opts.npmPublish ??= true;
opts.githubRelease ??= true;

const projectRoot = dirname(packageJsonPath);
const projectConfig = readJsonFile<ProjectConfiguration>(
resolve(projectRoot, 'project.json'),
);
const outputPath: string | undefined =
projectConfig.targets?.[opts.buildTarget]?.options?.outputPath;

if (!outputPath) {
throw new Error(
`The project "${projectRoot}" does not have a build target.`,
);
}

const targets: [target: string, config: TargetConfiguration][] = [
[
'version',
{
executor: '@jscutlery/semver:version',
options: {
...(opts.githubRelease ? { push: true } : {}),
...(opts.noVerify ? { noVerify: opts.noVerify } : {}),
...(opts.commitMessageFormat
? { commitMessageFormat: opts.commitMessageFormat }
: {}),
postTargets: [
...(opts.npmPublish ? [opts.buildTarget, 'npm'] : []),
...(opts.githubRelease ? ['github'] : []),
],
},
},
],
];

if (opts.npmPublish) {
targets.push([
'npm',
{
command: `npm publish ${outputPath}`,
},
]);
}

if (opts.githubRelease) {
targets.push([
'github',
{
executor: '@jscutlery/semver:github',
options: {
notes: '{notes}',
tag: '{tag}',
},
},
]);
}

return {
projects: {
[projectRoot]: {
targets: targets.reduce((acc, [target, config]) => {
return { ...acc, [target]: config };
}, {}),
},
},
};
},
];