Skip to content
Merged
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
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

40 changes: 40 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Run tests

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [22.x, 24.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "yarn"
- name: Install
run: |
yarn install --ignore-engines
- name: Build
run: yarn build
- name: Test
run: yarn test
- name: Coverage
run: yarn coverage
Comment on lines +30 to +35
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: nextcss/color-tools
Comment on lines +36 to +40
28 changes: 0 additions & 28 deletions .github/workflows/node.js.yml

This file was deleted.

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

on:
release:
types: [published]

permissions:
contents: write
id-token: write

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "24.x"
cache: "yarn"

- name: Install dependencies
run: yarn install --ignore-engines

- name: Build
run: yarn build

- name: Create dist archive
run: |
mkdir release-package
cp -r dist release-package/
cp package.json release-package/
cp README.md release-package/
cp LICENSE release-package/ 2>/dev/null || :
cd release-package
zip -r ../Release.zip .
cd ..

- name: Upload dist to release
uses: softprops/action-gh-release@v1
with:
files: Release.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish to npm with Trusted Publishing
env:
NPM_CONFIG_PROVENANCE: true
run: npm publish --access public
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules/
dist/
coverage/
*.js.txt

*.log
yarn-error.log
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![GitHub License](https://img.shields.io/github/license/nextcss/color-tools?style=flat)](https://github.com/nextcss/color-tools/blob/main/LICENSE)
[![npm](https://img.shields.io/npm/v/@nextcss/color-tools?style=flat&color=red)](https://www.npmjs.com/package/@nextcss/color-tools)
[![GitHub Repo stars](https://img.shields.io/github/stars/nextcss/color-tools?color=DAAA3F)](https://github.com/nextcss/color-tools/stargazers)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/nextcss/color-tools/node.js.yml?branch=main)](https://github.com/nextcss/color-tools/actions/workflows/node.js.yml)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/nextcss/color-tools/main.yml?branch=main)](https://github.com/nextcss/color-tools/actions/workflows/main.yml)
[![Codecov](https://img.shields.io/codecov/c/github/nextcss/color-tools?style=flat)](https://app.codecov.io/github/nextcss/color-tools)
[![Sponsor](https://img.shields.io/static/v1?label=sponsor&message=❤&color=ff69b4)](https://github.com/sponsors/toviszsolt)

Expand Down
95 changes: 95 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import esbuild from "esbuild";
import fs, { readdirSync, readFileSync, statSync, writeFileSync } from "fs";
import path from "path/posix";

const pathSrc = "src";
const pathOutput = "dist";
const withWatch = process.argv.includes("--watch");
const commonConfig = { bundle: true, minify: true, sourcemap: false };

const cleanBuild = () => {
if (fs.existsSync(pathOutput)) {
fs.rmSync(pathOutput, { recursive: true, force: true });
}

fs.mkdirSync(pathOutput);
console.log(`[Build] Clean directory: ${path.sep}${pathOutput}`);
};

const runBuild = async (config) => {
if (withWatch) {
const ctx = await esbuild.context(config);
await ctx.watch();
console.log(
`[Build] Watching: ${path.sep}${config.outfile || config.entryPoints}`,
);
} else {
console.log(
`[Build] Building: ${path.sep}${config.outfile || config.entryPoints}`,
);
await esbuild.build(config);
}
};

const createLLMBundle = () => {
const getFiles = (dir, files = []) => {
readdirSync(dir).forEach((f) => {
const filePath = path.join(dir, f);
statSync(filePath).isDirectory()
? getFiles(filePath, files)
: f.endsWith(".js") && files.push(filePath);
});
return files;
};

const bundleFileName = "bundle-llm.js.txt";
const bundle = getFiles(pathSrc)
.map((f) => `// ${f}\n${readFileSync(f, "utf-8")}`)
.join("\n\n");

writeFileSync(bundleFileName, bundle, "utf-8");
console.log(`[Build] Building: ${path.sep}${bundleFileName}`);
};

const copyTypeDefinitions = () => {
const defFiles = ["index.d.ts"];

for (const defFile of defFiles) {
const src = path.join(pathSrc, defFile);
const dest = path.join(pathOutput, defFile);
fs.mkdirSync(path.dirname(dest), { recursive: true });
fs.copyFileSync(src, dest);
console.log(`[Build] Copy definitions: ${path.sep}${dest}`);
}
};

try {
if (!withWatch) {
cleanBuild();
copyTypeDefinitions();
createLLMBundle();
}
Comment on lines +66 to +71

const entryPoints = ["src/index.js"];

for (const entryPoint of entryPoints) {
const entryPointName = path.basename(entryPoint, ".js");
const dirname = path.dirname(entryPoint).replace(pathSrc, "");

for (const format of ["esm", "cjs"]) {
const basename =
format === "esm" ? `${entryPointName}.js` : `${entryPointName}.cjs`;
await runBuild({
...commonConfig,
entryPoints: [entryPoint],
outfile: path.join(pathOutput, dirname, basename),
format: format,
platform: "node",
legalComments: "none",
});
}
}
} catch (err) {
console.error("[Build] Failed:", err);
process.exit(1);
}
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
coverageProvider: "v8",
transform: {
"\\.[jt]sx?$": ["jest-esbuild", { minify: false, sourcemap: true }],
},
};
4 changes: 4 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"verbose": true,
"ignore": ["**/data*/**", "coverage", "dist", "node_modules", "test"]
}
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nextcss/color-tools",
"version": "1.0.10",
"version": "1.0.11",
"description": "Color tools for browser and node.",
"keywords": [
"color",
Expand All @@ -19,10 +19,11 @@
],
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"main": "./dist/index.cjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs"
}
Expand All @@ -31,7 +32,8 @@
"dist/*"
],
"publishConfig": {
"access": "public"
"access": "public",
"provenance": true
},
"author": {
"name": "Zsolt Tovis",
Expand All @@ -48,19 +50,17 @@
},
"homepage": "https://nextcss.com",
"scripts": {
"watch": "rollup -c -w",
"build": "jest --verbose && rollup -c",
"test": "jest --watch",
"coverage": "jest --collect-coverage"
"watch": "node build.js --watch",
"test": "jest --verbose",
"build": "jest --verbose && node build.js",
"coverage": "jest --collect-coverage",
"coverage:open": "(start ./coverage/lcov-report/index.html || open ./coverage/lcov-report/index.html || xdg-open ./coverage/lcov-report/index.html)"
},
"dependencies": {},
"devDependencies": {
"@babel/preset-env": "^7.28.5",
"@rollup/plugin-commonjs": "^29.0.0",
"@rollup/plugin-node-resolve": "^16.0.3",
"jest": "^30.2.0",
"rollup": "^4.53.3",
"rollup-plugin-copy": "^3.5.0",
"rollup-plugin-terser": "^7.0.2"
"@types/jest": "^30.0.0",
"esbuild": "^0.28.1",
"jest": "^30.4.2",
"jest-esbuild": "^0.4.0"
}
}
25 changes: 0 additions & 25 deletions rollup.config.js

This file was deleted.

Loading
Loading