Skip to content

Commit 4148254

Browse files
author
eugene yevhen andruszczenko
committed
build: 0.0.2
0 parents  commit 4148254

15 files changed

+1828
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.github/.DS_Store

6 KB
Binary file not shown.

.github/FUNDING.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github: [32teeth]
2+
buy_me_a_coffee: 32teeth

.github/ISSUE_TEMPLATE/bug_report.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
5+
---
6+
7+
**Describe the bug**
8+
A clear and concise description of what the bug is.
9+
10+
**To Reproduce**
11+
Steps to reproduce the behavior:
12+
1. Go to '...'
13+
2. Click on '....'
14+
3. Scroll down to '....'
15+
4. See error
16+
17+
**Expected behavior**
18+
A clear and concise description of what you expected to happen.
19+
20+
**Screenshots**
21+
If applicable, add screenshots to help explain your problem.
22+
23+
**Desktop (please complete the following information):**
24+
- OS: [e.g. iOS]
25+
- Browser [e.g. chrome, safari]
26+
- Version [e.g. 22]
27+
28+
**Smartphone (please complete the following information):**
29+
- Device: [e.g. iPhone6]
30+
- OS: [e.g. iOS8.1]
31+
- Browser [e.g. stock browser, safari]
32+
- Version [e.g. 22]
33+
34+
**Additional context**
35+
Add any other context about the problem here.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
5+
---
6+
7+
**Is your feature request related to a problem? Please describe.**
8+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
9+
10+
**Describe the solution you'd like**
11+
A clear and concise description of what you want to happen.
12+
13+
**Describe alternatives you've considered**
14+
A clear and concise description of any alternative solutions or features you've considered.
15+
16+
**Additional context**
17+
Add any other context or screenshots about the feature request here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Node.js Package
2+
3+
on:
4+
workflow_dispatch:
5+
release:
6+
types: [created]
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: 20
16+
- run: npm i
17+
- run: npm test
18+
19+
publish:
20+
needs: build
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
packages: write
25+
outputs:
26+
publish_status: ${{ steps.publish-step.outputs.publish_status }}
27+
steps:
28+
- uses: actions/checkout@v4
29+
- uses: actions/setup-node@v4
30+
with:
31+
node-version: 20
32+
registry-url: https://npm.pkg.github.com/
33+
- run: npm i
34+
- id: publish-step
35+
run: |
36+
set +e
37+
npm publish 2> publish_error.log || ERROR=$?
38+
set -e
39+
if [ "$ERROR" == "1" ]; then
40+
ERROR_MESSAGE=$(cat publish_error.log)
41+
echo "Publishing failed due to existing version conflict."
42+
# Post the error message to a GitHub issue
43+
curl -X POST \
44+
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
45+
-H "Accept: application/vnd.github.v3+json" \
46+
https://api.github.com/repos/${{ github.repository }}/issues \
47+
-d "{\"title\": \"Publish Conflict\", \"body\": \"Attempted to publish over an existing version. Error details: \\n\\n$ERROR_MESSAGE\"}"
48+
echo "::set-output name=publish_status::skipped"
49+
else
50+
echo "::set-output name=publish_status::success"
51+
fi
52+
env:
53+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
55+
notify:
56+
needs: publish
57+
runs-on: ubuntu-latest
58+
if: ${{ needs.publish.outputs.publish_status == 'skipped' }}
59+
steps:
60+
- run: echo "The publish step was skipped due to a version conflict."

.gitignore

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# Snowpack dependency directory (https://snowpack.dev/)
46+
web_modules/
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Optional stylelint cache
58+
.stylelintcache
59+
60+
# Microbundle cache
61+
.rpt2_cache/
62+
.rts2_cache_cjs/
63+
.rts2_cache_es/
64+
.rts2_cache_umd/
65+
66+
# Optional REPL history
67+
.node_repl_history
68+
69+
# Output of 'npm pack'
70+
*.tgz
71+
72+
# Yarn Integrity file
73+
.yarn-integrity
74+
75+
# dotenv environment variable files
76+
.env
77+
.env.development.local
78+
.env.test.local
79+
.env.production.local
80+
.env.local
81+
82+
# parcel-bundler cache (https://parceljs.org/)
83+
.cache
84+
.parcel-cache
85+
86+
# Next.js build output
87+
.next
88+
out
89+
90+
# Nuxt.js build / generate output
91+
.nuxt
92+
dist
93+
94+
# Gatsby files
95+
.cache/
96+
# Comment in the public line in if your project uses Gatsby and not Next.js
97+
# https://nextjs.org/blog/next-9-1#public-directory-support
98+
# public
99+
100+
# vuepress build output
101+
.vuepress/dist
102+
103+
# vuepress v2.x temp and cache directory
104+
.temp
105+
.cache
106+
107+
# Docusaurus cache and generated files
108+
.docusaurus
109+
110+
# Serverless directories
111+
.serverless/
112+
113+
# FuseBox cache
114+
.fusebox/
115+
116+
# DynamoDB Local files
117+
.dynamodb/
118+
119+
# TernJS port file
120+
.tern-port
121+
122+
# Stores VSCode versions used for testing VSCode extensions
123+
.vscode-test
124+
125+
# yarn v2
126+
.yarn/cache
127+
.yarn/unplugged
128+
.yarn/build-state.yml
129+
.yarn/install-state.gz
130+
.pnp.*

.npmrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#@32teeth:registry=https://npm.pkg.github.com/
2+
#registry=https://registry.npmjs.com/
3+
20
4+
#loglevel=silent

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog
2+
3+
### 0.0.2
4+
5+
Changes in this version:
6+
7+
8+
9+

bin/minify-css-map.mjs

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import { fileURLToPath } from 'node:url';
4+
5+
const DIRECTORY_META_NAME = fileURLToPath(new URL('.', import.meta.url));
6+
7+
// Get the directory to process from command-line arguments
8+
const targetDirectory = process.argv[2] || DIRECTORY_META_NAME;
9+
10+
/**
11+
* Minifies a CSS string by removing whitespace and comments.
12+
* @param {string} css - The CSS content to minify.
13+
* @returns {string} - The minified CSS.
14+
*/
15+
function minifyCss(css) {
16+
return css
17+
.replace(/\/\*[\s\S]*?\*\//g, '') // Remove comments
18+
.replace(/\s+/g, ' ') // Replace multiple spaces with a single space
19+
.replace(/\s*([{}:;])\s*/g, '$1') // Remove spaces around {}, :, and ;
20+
.replace(/;}/g, '}'); // Remove unnecessary semicolons before }
21+
}
22+
23+
/**
24+
* Generates a CSS source map.
25+
* @param {string} cssContent - The original CSS content.
26+
* @param {string} cssFileName - The name of the CSS file.
27+
* @returns {object} - The source map object.
28+
*/
29+
function generateSourceMap(cssContent, cssFileName) {
30+
const lines = cssContent.split('\n');
31+
const mapEntries = lines.map((line, index) => ({
32+
original: line,
33+
generated: `${index + 1}:0`, // Line number and column
34+
}));
35+
36+
return {
37+
version: 3,
38+
file: cssFileName,
39+
sources: [cssFileName], // Name of the original CSS file
40+
mappings: mapEntries,
41+
};
42+
}
43+
44+
/**
45+
* Minifies a CSS file and creates a .min.css and a .css.map file.
46+
* @param {string} cssFilePath - The path to the CSS file to minify.
47+
*/
48+
function minifyCssFile(cssFilePath) {
49+
const cssContent = fs.readFileSync(cssFilePath, 'utf-8');
50+
51+
// Minify the CSS content
52+
const minifiedCss = minifyCss(cssContent);
53+
54+
// Generate output paths
55+
const cssDir = path.dirname(cssFilePath);
56+
const baseFileName = path.basename(cssFilePath, '.css');
57+
const minCssFilePath = path.join(cssDir, `${baseFileName}.min.css`);
58+
const mapFilePath = path.join(cssDir, `${baseFileName}.css.map`);
59+
60+
// Write the minified CSS file
61+
fs.writeFileSync(minCssFilePath, minifiedCss);
62+
63+
// Generate and write the source map
64+
const sourceMap = generateSourceMap(cssContent, `${baseFileName}.css`);
65+
fs.writeFileSync(mapFilePath, JSON.stringify(sourceMap, null, 2));
66+
67+
console.log(`Minified ${cssFilePath} -> ${minCssFilePath}`);
68+
}
69+
70+
/**
71+
* Recursively processes the project directory to find and minify CSS files.
72+
* @param {string} dirPath - The base directory path.
73+
*/
74+
function processDirectory(dirPath) {
75+
const files = fs.readdirSync(dirPath);
76+
77+
files.forEach(file => {
78+
const filePath = path.join(dirPath, file);
79+
const stat = fs.statSync(filePath);
80+
81+
if (stat.isDirectory()) {
82+
processDirectory(filePath);
83+
} else if (file.endsWith('.css') && !file.endsWith('.min.css')) {
84+
// Minify and create .min.css and .css.map
85+
minifyCssFile(filePath);
86+
}
87+
});
88+
}
89+
90+
/**
91+
* Starts the minification process.
92+
*/
93+
function startMinification() {
94+
const rootDirectory = targetDirectory;
95+
console.log('Starting CSS minification in:', rootDirectory);
96+
97+
// Ensure the target directory exists before processing
98+
if (!fs.existsSync(rootDirectory)) {
99+
console.error('Target directory does not exist:', rootDirectory);
100+
return;
101+
}
102+
103+
// Process the entire directory
104+
processDirectory(rootDirectory);
105+
106+
console.log('CSS minification completed.');
107+
}
108+
109+
// Run the script
110+
startMinification();

0 commit comments

Comments
 (0)