mirror of
https://github.com/penpot/penpot-plugins.git
synced 2025-01-02 04:40:11 -05:00
feat: new publish script
This commit is contained in:
parent
451419f356
commit
5114e78c94
13 changed files with 1018 additions and 201 deletions
|
@ -1,94 +1,64 @@
|
|||
# Publishing Packages
|
||||
|
||||
- DEPRECATED -
|
||||
|
||||
## Introduction
|
||||
|
||||
This guide details the process of publishing `plugin-types` and `plugins-styles` packages, which are essential for plugin development. To facilitate testing and distribution, we leverage npm for publishing and Verdaccio for setting up a local registry. Below is a walkthrough for publishing these packages, setting up a local registry, and managing releases.
|
||||
|
||||
## Setting Up a Local Registry with Verdaccio
|
||||
|
||||
Setting up a local registry is for testing plugins in isolation from the monorepo. We utilize Verdaccio, a npm proxy registry, for this purpose.
|
||||
|
||||
**Launch the Registry**: Initiate the Verdaccio registry by executing the command:
|
||||
|
||||
```shell
|
||||
npm run registry
|
||||
```
|
||||
This guide details the process of publishing `plugin-types` and `plugins-styles` packages, which are essential for plugin development. Below is a walkthrough for publishing these packages and managing releases.
|
||||
|
||||
## Publishing Libraries
|
||||
|
||||
Publishing packages allows you to distribute your libraries to other developers and environments. Follow the steps below for both automated and manual publishing processes.
|
||||
Publishing packages enables the distribution of types and styles libraries. Currently, all packages share the same version, meaning some releases might not contain updates but will still increment the version. Follow the steps below for the automated publishing processes.
|
||||
|
||||
### Automated Publishing:
|
||||
### Previewing a Release
|
||||
|
||||
To publish the libraries automatically, use the command:
|
||||
To generate a preview of the release to check if everything is as expected, run the following command:
|
||||
|
||||
```shell
|
||||
npm run publish -- --version 0.1.0 --tag 0.1.0 --registry http://localhost:4873
|
||||
npm run release
|
||||
```
|
||||
|
||||
### Manual Publishing:
|
||||
### Generating a Real Release
|
||||
|
||||
For manual publication, navigate to the library directory and execute:
|
||||
To create an actual release, disable the dry-run option:
|
||||
|
||||
```shell
|
||||
npm publish --registry http://localhost:4873
|
||||
npm run release -- --dry-run false
|
||||
```
|
||||
|
||||
### Independent Publishing:
|
||||
This command will:
|
||||
|
||||
To publish libraries independently, specify the package name along with version and tag:
|
||||
- Update the `CHANGELOG.md`
|
||||
- Update libraries `package.json` file version
|
||||
- Generate a commit
|
||||
- Create a new git tag
|
||||
- Publish to NPM with the `latest` tag
|
||||
|
||||
For detailed information, refer to the [Nx Release Documentation](https://nx.dev/recipes/nx-release/get-started-with-nx-release).
|
||||
|
||||
### Creating a Preview Version
|
||||
|
||||
To generate a preview version and avoid publishing it as the latest release, use:
|
||||
|
||||
```shell
|
||||
npx nx publish plugin-types -- --version 0.1.0 --tag 0.1.0
|
||||
npx nx publish plugins-styles -- --version 0.1.0 --tag 0.1.0
|
||||
npm run release -- --dry-run false --latest false --preid next
|
||||
```
|
||||
|
||||
### Create the tag in git
|
||||
For example, if the current version is `0.8.0` and you select the `prepatch` option as a version specifier, it will generate the version `0.8.1-next.0` and publish it with the next tag on npm.
|
||||
|
||||
### Help
|
||||
|
||||
To see more options, run:
|
||||
|
||||
```shell
|
||||
git tag -a 0.1.0
|
||||
git push origin 0.1.0
|
||||
npm run release -- --help
|
||||
```
|
||||
|
||||
### Installing Libraries:
|
||||
|
||||
When installing the library, ensure to specify the registry:
|
||||
|
||||
```shell
|
||||
npm i --registry http://localhost:4873
|
||||
```
|
||||
|
||||
**Note**: For direct npm publication, omit the `--registry` flag.
|
||||
|
||||
## Managing Releases
|
||||
|
||||
### Generating a Release:
|
||||
|
||||
For regular releases, execute:
|
||||
|
||||
```shell
|
||||
npx nx release
|
||||
```
|
||||
|
||||
For the initial release, use the `--first-release` flag:
|
||||
|
||||
```shell
|
||||
npx nx release --first-release
|
||||
```
|
||||
|
||||
Refer to the [Nx Release Documentation](https://nx.dev/recipes/nx-release/publish-in-ci-cd) for detailed information.
|
||||
|
||||
## Important Reminders
|
||||
|
||||
Ensure to update the [penpot-plugin-starter-template](https://github.com/penpot/penpot-plugin-starter-template) with every release to provide developers with the latest configuration and features.
|
||||
|
||||
## Relevant Files and Scripts
|
||||
|
||||
- **Verdaccio Configuration**: `./project.json`
|
||||
- **CSS Build Script**: `./tools/scripts/build-css.mjs`
|
||||
- **Types Build Script**: `./tools/scripts/build-types.mjs`
|
||||
- **Publish Script**: `./tools/scripts/publish.mjs`
|
||||
|
||||
This improved documentation aims to streamline the package publishing process, making it more accessible and understandable for developers.
|
||||
- **Release Script**: `./tools/scripts/publish.ts`
|
||||
- **Publish config**: `./nx.json`
|
||||
|
|
|
@ -12,10 +12,6 @@
|
|||
"options": {
|
||||
"outputPath": "dist/plugin-types"
|
||||
}
|
||||
},
|
||||
"publish": {
|
||||
"command": "node tools/scripts/publish.mjs plugin-types {args.ver} {args.tag}",
|
||||
"dependsOn": ["build"]
|
||||
}
|
||||
},
|
||||
"tags": ["type:ui"]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@penpot/plugins-runtime",
|
||||
"version": "0.6.0",
|
||||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"@penpot/plugin-types": "^0.8.0",
|
||||
"ses": "^1.1.0",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "@penpot/plugin-styles",
|
||||
"version": "0.6.0",
|
||||
"version": "0.8.0",
|
||||
"dependencies": {}
|
||||
}
|
||||
|
|
|
@ -10,10 +10,6 @@
|
|||
"outputPath": "dist/plugins-styles"
|
||||
}
|
||||
},
|
||||
"publish": {
|
||||
"command": "node tools/scripts/publish.mjs plugins-styles {args.ver} {args.tag}",
|
||||
"dependsOn": ["build"]
|
||||
},
|
||||
"lint": {
|
||||
"command": "echo 0"
|
||||
}
|
||||
|
|
8
nx.json
8
nx.json
|
@ -4,9 +4,17 @@
|
|||
"analyzeSourceFiles": true
|
||||
}
|
||||
},
|
||||
"release": {
|
||||
"projects": ["libs/plugins-styles", "libs/plugin-types"]
|
||||
},
|
||||
"extends": "nx/presets/npm.json",
|
||||
"$schema": "./node_modules/nx/schemas/nx-schema.json",
|
||||
"targetDefaults": {
|
||||
"nx-release-publish": {
|
||||
"options": {
|
||||
"packageRoot": "dist/{projectName}"
|
||||
}
|
||||
},
|
||||
"@nx/vite:build": {
|
||||
"cache": true,
|
||||
"dependsOn": ["^build"],
|
||||
|
|
894
package-lock.json
generated
894
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -21,10 +21,10 @@
|
|||
"lint": "nx run-many --all --target=lint --parallel",
|
||||
"lint:affected": "npx nx affected --target=lint",
|
||||
"test": "nx run-many -t test --parallel -p plugins-runtime lorem-ipsum-plugin",
|
||||
"publish": "nx run-many -t publish -p plugins-styles plugin-types --parallel=false --",
|
||||
"registry": "nx local-registry",
|
||||
"prepare": "husky",
|
||||
"create:api-docs": "npx typedoc --tsconfig libs/plugins-runtime/tsconfig.lib.json --options typedoc.json"
|
||||
"create:api-docs": "npx typedoc --tsconfig libs/plugins-runtime/tsconfig.lib.json --options typedoc.json",
|
||||
"release": "npx tsx ./tools/scripts/publish.ts"
|
||||
},
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
|
@ -73,10 +73,9 @@
|
|||
"nx": "19.1.1",
|
||||
"prettier": "^2.6.2",
|
||||
"swc-loader": "0.1.15",
|
||||
"ts-node": "10.9.1",
|
||||
"tsx": "^4.16.2",
|
||||
"typedoc": "^0.25.13",
|
||||
"typescript": "~5.4.5",
|
||||
"verdaccio": "^5.0.4",
|
||||
"vite": "^5.0.0",
|
||||
"vite-plugin-checker": "^0.6.4",
|
||||
"vite-plugin-dts": "~2.3.0",
|
||||
|
|
12
project.json
12
project.json
|
@ -1,15 +1,5 @@
|
|||
{
|
||||
"name": "penpot-plugins",
|
||||
"$schema": "node_modules/nx/schemas/project-schema.json",
|
||||
"targets": {
|
||||
"local-registry": {
|
||||
"executor": "@nx/js:verdaccio",
|
||||
"options": {
|
||||
"port": 4873,
|
||||
"config": ".verdaccio/config.yml",
|
||||
"storage": "tmp/local-registry/storage",
|
||||
"clear": false
|
||||
}
|
||||
}
|
||||
}
|
||||
"targets":{}
|
||||
}
|
||||
|
|
21
tools/eslint.config.js
Normal file
21
tools/eslint.config.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
import baseConfig from '../../eslint.config.js';
|
||||
import jsoncParser from 'jsonc-eslint-parser';
|
||||
import globals from 'globals';
|
||||
|
||||
export default [
|
||||
...baseConfig,
|
||||
{
|
||||
files: ['**/*.ts'],
|
||||
rules: {},
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: './tsconfig.*?.json',
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
globals: {
|
||||
...globals.node,
|
||||
PluginConfig: 'readonly',
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
|
@ -1,65 +0,0 @@
|
|||
/**
|
||||
* This is a minimal script to publish your package to "npm".
|
||||
* This is meant to be used as-is or customize as you see fit.
|
||||
*
|
||||
* This script is executed on "dist/path/to/library" as "cwd" by default.
|
||||
*
|
||||
* You might need to authenticate with NPM before running this script.
|
||||
*/
|
||||
|
||||
import { execSync } from 'child_process';
|
||||
import { readFileSync, writeFileSync } from 'fs';
|
||||
|
||||
import devkit from '@nx/devkit';
|
||||
const { readCachedProjectGraph } = devkit;
|
||||
|
||||
function invariant(condition, message) {
|
||||
if (!condition) {
|
||||
console.error(message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Executing publish script: node path/to/publish.mjs {name} --version {version} --tag {tag}
|
||||
// Default "tag" to "next" so we won't publish the "latest" tag by accident.
|
||||
const [, , name, version, tag = 'next', registry] = process.argv;
|
||||
|
||||
// A simple SemVer validation to validate the version
|
||||
const validVersion = /^\d+\.\d+\.\d+(-\w+\.\d+)?/;
|
||||
invariant(
|
||||
version && validVersion.test(version),
|
||||
`No version provided or version did not match Semantic Versioning, expected: #.#.#-tag.# or #.#.#, got ${version}.`
|
||||
);
|
||||
|
||||
const graph = readCachedProjectGraph();
|
||||
const project = graph.nodes[name];
|
||||
|
||||
invariant(
|
||||
project,
|
||||
`Could not find project "${name}" in the workspace. Is the project.json configured correctly?`
|
||||
);
|
||||
|
||||
const outputPath = project.data?.targets?.build?.options?.outputPath;
|
||||
invariant(
|
||||
outputPath,
|
||||
`Could not find "build.options.outputPath" of project "${name}". Is project.json configured correctly?`
|
||||
);
|
||||
|
||||
process.chdir(outputPath);
|
||||
|
||||
// Updating the version in "package.json" before publishing
|
||||
try {
|
||||
const json = JSON.parse(readFileSync(`package.json`).toString());
|
||||
json.version = version;
|
||||
writeFileSync(`package.json`, JSON.stringify(json, null, 2));
|
||||
} catch (e) {
|
||||
console.error(`Error reading package.json file from library build output.`);
|
||||
}
|
||||
|
||||
// Execute "npm publish" to publish
|
||||
let command = `npm publish --access public --tag ${tag}`;
|
||||
if (registry) {
|
||||
command += ` --registry ${registry}`;
|
||||
}
|
||||
execSync(command);
|
||||
|
92
tools/scripts/publish.ts
Normal file
92
tools/scripts/publish.ts
Normal file
|
@ -0,0 +1,92 @@
|
|||
import { execSync } from 'child_process';
|
||||
import { releaseChangelog, releasePublish, releaseVersion } from 'nx/release';
|
||||
import yargs from 'yargs';
|
||||
import { hideBin } from 'yargs/helpers';
|
||||
|
||||
const determineArgs = async () => {
|
||||
return await yargs(hideBin(process.argv))
|
||||
.version(false)
|
||||
.option('dryRun', {
|
||||
alias: 'd',
|
||||
description:
|
||||
'Whether or not to perform a dry-run of the release process, defaults to true',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
})
|
||||
.option('verbose', {
|
||||
description:
|
||||
'Whether or not to enable verbose logging, defaults to false',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
})
|
||||
.option('version', {
|
||||
description:
|
||||
'Explicit version specifier to use, if overriding conventional commits',
|
||||
type: 'string',
|
||||
default: undefined,
|
||||
})
|
||||
.option('skip-publish', {
|
||||
description: 'Skip publishing the package to the registry',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
})
|
||||
.option('preid', {
|
||||
description: 'The prerelease identifier to use',
|
||||
type: 'string',
|
||||
default: undefined,
|
||||
})
|
||||
.option('latest', {
|
||||
description: 'Publish the package with the latest tag',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
})
|
||||
.option('first-release', {
|
||||
description: 'Whether or not this is the first release',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
})
|
||||
.parseAsync();
|
||||
};
|
||||
|
||||
(async () => {
|
||||
const args = await determineArgs();
|
||||
|
||||
const result = await releaseVersion({
|
||||
dryRun: args.dryRun,
|
||||
specifier: args.version,
|
||||
gitCommit: false,
|
||||
gitTag: false,
|
||||
stageChanges: true,
|
||||
verbose: args.verbose,
|
||||
preid: args.preid,
|
||||
});
|
||||
|
||||
execSync(
|
||||
'npx nx run-many -t build -p plugins-styles plugin-types --parallel',
|
||||
{
|
||||
cwd: process.cwd(),
|
||||
stdio: 'inherit',
|
||||
}
|
||||
);
|
||||
|
||||
await releaseChangelog({
|
||||
dryRun: args.dryRun,
|
||||
versionData: result.projectsVersionData,
|
||||
version: result.workspaceVersion,
|
||||
gitCommitMessage: `chore(release): publish ${result.workspaceVersion} [skip ci]`,
|
||||
gitCommit: true,
|
||||
gitTag: true,
|
||||
verbose: args.verbose,
|
||||
firstRelease: args.firstRelease,
|
||||
});
|
||||
|
||||
if (!args.skipPublish) {
|
||||
await releasePublish({
|
||||
dryRun: args.dryRun,
|
||||
verbose: args.verbose,
|
||||
tag: args.latest ? 'latest' : 'next',
|
||||
});
|
||||
}
|
||||
|
||||
process.exit(0);
|
||||
})();
|
20
tools/tsconfig.json
Normal file
20
tools/tsconfig.json
Normal file
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"extends": "../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"module": "ESNext",
|
||||
"lib": ["ESNext"],
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"noImplicitOverride": true,
|
||||
"noPropertyAccessFromIndexSignature": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"types": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"files": [],
|
||||
"include": [
|
||||
"**/*.ts",
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue