Skip to content

Commit

Permalink
version 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikzogg committed Jan 3, 2025
1 parent 3884022 commit 9f2b2d5
Show file tree
Hide file tree
Showing 15 changed files with 178 additions and 131 deletions.
9 changes: 0 additions & 9 deletions .eslintrc.cjs

This file was deleted.

51 changes: 51 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: CI

on:
push:
pull_request:
branches:
- master
schedule:
- cron: '0 0 * * *'

jobs:
node18:
name: Node 18
runs-on: ubuntu-24.04
steps:
- name: checkout
uses: actions/checkout@v4
- name: checkout node
uses: actions/setup-node@v4
with:
node-version: '18'
- run: npm install
node20:
name: Node 20
runs-on: ubuntu-24.04
steps:
- name: checkout
uses: actions/checkout@v4
- name: checkout node
uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm install
node22:
name: Node 22
runs-on: ubuntu-24.04
steps:
- name: checkout
uses: actions/checkout@v4
- name: checkout node
uses: actions/setup-node@v4
with:
node-version: '22'
- run: npm install
- run: npm run lint
- run: npm run cs
- name: sonarcloud.io
uses: sonarsource/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist
node_modules
package-lock.json
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ Packaging helper

## Requirements

* node: 16
* node: 18

## Installation

Through [NPM](https://www.npmjs.com) as [@chubbyts/chubbyts-packaging][1].

```ts
npm i -D @chubbyts/chubbyts-packaging@^2.0.6
npm i -D @chubbyts/chubbyts-packaging@^3.0.0
```

### package.json

```json
"type": "module",
"scripts": {
"build": "node ./build.js",
"build": "node ./build.mjs",
...
},
"exports": {
Expand All @@ -37,15 +37,12 @@ npm i -D @chubbyts/chubbyts-packaging@^2.0.6
### Symlinks

```sh
ln -sf node_modules/@chubbyts/chubbyts-packaging/build.js .
ln -sf node_modules/@chubbyts/chubbyts-packaging/tsconfig.cjs.json .
ln -sf node_modules/@chubbyts/chubbyts-packaging/tsconfig.esm.json .
ln -sf node_modules/@chubbyts/chubbyts-packaging/dist/build.mjs .
ln -sf node_modules/@chubbyts/chubbyts-packaging/tsconfig.json .
ln -sf node_modules/@chubbyts/chubbyts-packaging/tsconfig.types.json .
```

## Copyright

2024 Dominik Zogg
2025 Dominik Zogg

[1]: https://www.npmjs.com/package/@chubbyts/chubbyts-packaging
78 changes: 0 additions & 78 deletions build.js

This file was deleted.

1 change: 1 addition & 0 deletions build.ts
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@chubbyts/chubbyts-eslint/eslint.config';
36 changes: 23 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@chubbyts/chubbyts-packaging",
"type": "module",
"version": "2.0.7",
"version": "3.0.0",
"description": "Packaging helper",
"keywords": [
"chubbyts",
Expand All @@ -12,10 +12,12 @@
"license": "MIT",
"repository": "chubbyts/chubbyts-packaging",
"scripts": {
"cs-fix": "prettier --write build.js",
"cs": "prettier --check build.js",
"lint-fix": "eslint build.js --fix",
"lint": "eslint build.js"
"build": "tsx build.ts",
"cs-fix": "prettier --write src eslint.config.mjs",
"cs": "prettier --check src eslint.config.mjs",
"lint-fix": "eslint src eslint.config.mjs --fix",
"lint": "eslint src",
"prepare": "npm run build"
},
"prettier": {
"printWidth": 120,
Expand All @@ -24,18 +26,26 @@
"trailingComma": "all"
},
"files": [
"build.js",
"tsconfig.cjs.json",
"tsconfig.esm.json",
"tsconfig.json",
"tsconfig.types.json"
"dist",
"tsconfig.json"
],
"exports": {
"./*": {
"types": "./*.d.ts",
"require": "./*.cjs",
"import": "./*.mjs",
"default": "./*.mjs"
}
},
"engines": {
"node": ">=16"
"node": ">=18"
},
"devDependencies": {
"@chubbyts/chubbyts-eslint": "^2.0.7",
"prettier": "^3.2.5"
"@chubbyts/chubbyts-eslint": "^3.0.0",
"@types/node": "^22.10.5",
"prettier": "^3.4.2",
"tsx": "^4.19.2",
"typescript": "^5.7.2"
},
"publishConfig": {
"access": "public"
Expand Down
7 changes: 7 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sonar.organization=chubbyts
sonar.projectKey=chubbyts_chubbyts-packaging
sonar.projectName=chubbyts-packaging

sonar.sources=src
sonar.language=typescript
sonar.sourceEncoding=UTF-8
80 changes: 80 additions & 0 deletions src/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { execSync } from 'child_process';
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'fs';
import { dirname, basename } from 'path';

const getAllFiles = (path: string): Array<string> => {
return readdirSync(path)
.map((file) => {
const filePath = path + '/' + file;
if (statSync(filePath).isDirectory()) {
return getAllFiles(filePath);
}

return [filePath];
})
.flat();
};

const distDir = './dist';
const commonJsDistDir = distDir + '/cjs';
const moduleDistDir = distDir + '/esm';

rmSync(distDir, { recursive: true, force: true });

try {
execSync(`./node_modules/.bin/tsc --module commonjs --outDir ${commonJsDistDir}`);
execSync(`./node_modules/.bin/tsc --module esnext --outDir ${moduleDistDir}`);
execSync(`./node_modules/.bin/tsc --declaration --emitDeclarationOnly --outDir ${distDir}`);
} catch (e) {
console.log(e?.toString());

process.exit(1);
}

getAllFiles(commonJsDistDir).map((file) => {
const name = basename(file);
const fromFolder = dirname(file);
const toFolder = distDir + fromFolder.substring(commonJsDistDir.length);

if (!name.match(/\.js$/)) {
return;
}

if (!existsSync(toFolder)) {
mkdirSync(toFolder, { recursive: true });
}

const fromPath = fromFolder + '/' + name;
const toPath = toFolder + '/' + name.replace(/\.js$/, '.cjs');

writeFileSync(
toPath,
readFileSync(fromPath, { encoding: 'utf8', flag: 'r' }).replace(/require\("\.([^"]+)"\)/g, 'require(".$1.cjs")'),
);
});

rmSync(commonJsDistDir, { recursive: true, force: true });

getAllFiles(moduleDistDir).map((file) => {
const name = basename(file);
const fromFolder = dirname(file);
const toFolder = distDir + fromFolder.substring(moduleDistDir.length);

if (!name.match(/\.js$/)) {
return;
}

if (!existsSync(toFolder)) {
mkdirSync(toFolder, { recursive: true });
}

const fromPath = fromFolder + '/' + name;
const toPath = toFolder + '/' + name.replace(/\.js$/, '.mjs');

writeFileSync(
toPath,
readFileSync(fromPath, { encoding: 'utf8', flag: 'r' }).replace(/from '\.([^']+)'/g, "from '.$1.mjs'"),
);
});

rmSync(moduleDistDir, { recursive: true, force: true });
7 changes: 0 additions & 7 deletions tsconfig.cjs.json

This file was deleted.

7 changes: 7 additions & 0 deletions tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"include": [
"eslint.config.mjs",
"src"
],
}
7 changes: 0 additions & 7 deletions tsconfig.esm.json

This file was deleted.

3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"jsx": "react",
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "node",
"skipLibCheck": true,
"strict": true,
Expand Down
8 changes: 0 additions & 8 deletions tsconfig.types.json

This file was deleted.

0 comments on commit 9f2b2d5

Please sign in to comment.