Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/editor-js/utils
Browse files Browse the repository at this point in the history
  • Loading branch information
e11sy committed Aug 22, 2024
2 parents b89cf2f + 55a8924 commit 6c23899
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 107 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ jobs:
- name: Install dependencies
run: yarn install

- name: Create .npmrc and publish packages
- name: Create .yarnrc.yml and publish packages
run: |
echo "npmAuthToken: ${{ secrets.NPM_TOKEN }}" >> .yarnrc.yml
yarn publish:ci
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
<<<<<<< HEAD
<<<<<<< Updated upstream

notify:
Expand All @@ -58,3 +59,5 @@ jobs:
=======
NOTIFY_WEBHOOK: ${{ secrets.CODEX_BOT_NOTIFY_EDITORJS_PUBLIC_CHAT }}
>>>>>>> Stashed changes
=======
>>>>>>> 55a8924eb663ee76836f0c6661758fd4cb72f1b5
Binary file modified .yarn/install-state.gz
Binary file not shown.
4 changes: 3 additions & 1 deletion packages/caret/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "@editorjs/caret",
"description": "Utils useful for work with caret for Editor.js tools development",
"version": "0.0.7",
"repository": "https://github.com/editor-js/utils/tree/main/packages/caret",
"link": "https://github.com/editor-js/utils/tree/main/packages/caret",
"version": "0.0.8",
"main": "dist/index.js",
"license": "MIT",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion packages/dom/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "@editorjs/dom",
"description": "Utils useful for work with dom for Editor.js tools development",
"version": "0.0.7",
"repository": "https://github.com/editor-js/utils/tree/main/packages/dom",
"link": "https://github.com/editor-js/utils/tree/main/packages/dom",
"version": "0.0.8",
"main": "dist/index.js",
"license": "MIT",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion packages/helpers/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "@editorjs/helpers",
"description": "Utils useful for Editor.js tools development",
"version": "0.0.7",
"repository": "https://github.com/editor-js/utils/tree/main/packages/helpers",
"link": "https://github.com/editor-js/utils/tree/main/packages/helpers",
"version": "0.0.8",
"main": "dist/index.js",
"license": "MIT",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion packages/keyboard/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "@editorjs/keyboard",
"description": "Utils useful for work with keyboard for Editor.js tools development",
"version": "0.0.7",
"repository": "https://github.com/editor-js/utils/tree/main/packages/keyboard",
"link": "https://github.com/editor-js/utils/tree/main/packages/keyboard",
"version": "0.0.8",
"main": "dist/index.js",
"license": "MIT",
"scripts": {
Expand Down
57 changes: 51 additions & 6 deletions scripts/publish.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
import { execSync } from 'child_process';
import * as process from 'process';
import * as path from 'path';
import { pathExistsSync, statSync, readdirSync } from 'fs-extra';
import { pathExistsSync, statSync, readdirSync, readJsonSync } from 'fs-extra';

const packagesDir = path.join(__dirname, '..', 'packages');

/**
* Interface that represents package.json used data
*/
interface Package {
/**
* Name of the package
*/
name: string;

/**
* Version of the package
*/
version: string;

/**
* Link to the published npm package
*/
link: string;
}

/**
* Function that returns names of all packages in /packages directory
*/
function getPackages(): string[] {
function getPackages(): Package[] {
const directories = readdirSync(packagesDir).filter((dir) => {
/**
* Actutal path to the package in project
Expand All @@ -21,7 +42,11 @@ function getPackages(): string[] {
return statSync(pathToPackage).isDirectory() && pathExistsSync(path.join(pathToPackage, 'package.json'));
});

return directories;
const packages: Package[] = directories.map((dir) => {
return readJsonSync(path.join('packages', dir, 'package.json')) as Package;
});

return packages;
}

execSync('npm run build', { stdio: 'inherit' });
Expand All @@ -33,7 +58,27 @@ const packages = getPackages();
/**
* For each package run yarn npm publish
*/
for (const name of packages) {
execSync(command, { stdio: 'inherit',
cwd: path.join('packages', name) });
for (const { name, version, link } of packages) {
const response = execSync(command, { cwd: path.join('packages', name.replace('@editorjs/', '')),
encoding: 'utf8' });

/**
* If version of any package was updated, then notify, otherwise pass
*/
if (!response.includes('Registry already knows about version') && process.env.NOTIFY_WEBHOOK !== undefined) {
/**
* Use notification webhook from workflow (script will not work fro)
*/
fetch(process.env.NOTIFY_WEBHOOK, {
method: 'POST',
headers: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
message: `📦 (${name})[${link}] ${version} was published`,
}),
})
.catch(error => console.error('Error:', error));
}
}
Loading

0 comments on commit 6c23899

Please sign in to comment.