Skip to content

Commit fa4181f

Browse files
committed
intial setup
1 parent a076444 commit fa4181f

File tree

14 files changed

+5356
-0
lines changed

14 files changed

+5356
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

bin/cli.ts

Whitespace-only changes.

configLoader.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { existsSync, readFileSync } from "fs";
2+
import { join } from "path";
3+
import { ConfigurationOptions } from "./lib/options";
4+
const CONFIG_FILE_NAME = "div.c.json";
5+
6+
const projectConfigFile = join(process.cwd(), CONFIG_FILE_NAME);
7+
const projectHasConfig = existsSync(projectConfigFile);
8+
9+
let projectConfig: ConfigurationOptions = {} as ConfigurationOptions;
10+
let defaultConfig: ConfigurationOptions = {} as ConfigurationOptions;
11+
12+
if (projectHasConfig) {
13+
//load project config
14+
try {
15+
projectConfig = JSON.parse(
16+
readFileSync(projectConfigFile, { encoding: "utf8" })
17+
);
18+
} catch (err) {
19+
if (err instanceof SyntaxError) {
20+
console.log(
21+
"Error: Check configuration file if there any syntax mistake"
22+
);
23+
} else {
24+
console.log("Unexpected Error while loading settings");
25+
}
26+
process.exit(1);
27+
}
28+
}
29+
//load default configuration
30+
defaultConfig = JSON.parse(
31+
readFileSync(join(__dirname, CONFIG_FILE_NAME), { encoding: "utf8" })
32+
);
33+
34+
const configurations: ConfigurationOptions = {
35+
...defaultConfig,
36+
...projectConfig,
37+
};
38+
39+
export default configurations;

div.c.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"screenSizes": {
3+
"1X": 600,
4+
"2X": 1080,
5+
"3X": 1920,
6+
"4X": 2560,
7+
"5X": 3840
8+
}
9+
}

lib/options.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type screenCats = "1X" | "2X" | "3X" | "4X" | "5X" | "6X" | "7X";
2+
3+
export interface ConfigurationOptions {
4+
screenSizes: Partial<Record<screenCats, number>>;
5+
}

lib/utils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export async function batchProcess(
2+
promises: (() => Promise<any>)[],
3+
batchSize: number
4+
): Promise<any[]> {
5+
const promiseBatches: (() => Promise<any>)[][] = [];
6+
7+
for (let i: number = 0; i < promises.length; i += batchSize) {
8+
promiseBatches.push(promises.slice(i, batchSize));
9+
}
10+
11+
const results: any[] = [];
12+
13+
for (const batch of promiseBatches) {
14+
const activatedBatch: Promise<any>[] = batch.map((func) => func());
15+
16+
const currentResults: any[] = await Promise.all(activatedBatch);
17+
18+
results.push(...currentResults);
19+
}
20+
21+
return results;
22+
}

package.json

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"name": "div-js",
3+
"displayName": "Div.js",
4+
"version": "0.0.1",
5+
"description": "Div.js is a tool designed to enhance web performance by splitting CSS into multiple files tailored for different devices. By delivering device-specific CSS files, Div.js minimizes network overhead, reduces network costs, and achieves faster load times.",
6+
"main": "./dist/div.js",
7+
"types": "./dist/types/div.d.ts",
8+
"exports": {
9+
"import": "./dist/div.js",
10+
"require": "./dist/div.js",
11+
"types": "./dist/types/div.d.ts"
12+
},
13+
"files": [
14+
"dist"
15+
],
16+
"preferGlobal": true,
17+
"bin": {
18+
"div": "./dist/bin/cli.js"
19+
},
20+
"repository": {
21+
"url": "https://github.com/iamspdarsan/div.js"
22+
},
23+
"bugs": {
24+
"url": "https://github.com/iamspdarsan/div.js/issues"
25+
},
26+
"homepage": "https://github.com/iamspdarsan/div.js",
27+
"author": "DARSAN <darsan@cresteem.com>",
28+
"maintainers": [
29+
"DARSAN <darsan@cresteem.com>"
30+
],
31+
"license": "Apache-2.0",
32+
"private": false,
33+
"scripts": {
34+
"dev": "cls && rimraf dist && tsc -p tscdev.json && ncp ./div.config.json ./dist/div.config.json",
35+
"dr": "yarn dev && yarn rp",
36+
"rp": "node ./dist/div.js",
37+
"test": "jest",
38+
"build": "cls && rimraf dist && tsc -p tsconfig.json && ncp ./div.config.json ./dist/div.config.json",
39+
"clean": "cls && rimraf dist",
40+
"deploy": "yarn test && yarn build && yarn publish --access public && git push"
41+
},
42+
"keywords": [
43+
"CSS",
44+
"split",
45+
"device-specific",
46+
"performance",
47+
"optimization",
48+
"web performance",
49+
"load time",
50+
"network overhead",
51+
"bandwidth",
52+
"responsive design",
53+
"front-end",
54+
"web development",
55+
"web optimization",
56+
"resource management",
57+
"Div.js",
58+
"CSS delivery",
59+
"fast loading",
60+
"scalable",
61+
"efficiency",
62+
"mobile optimization"
63+
],
64+
"dependencies": {
65+
"cheerio": "1.0.0-rc.12",
66+
"commander": "12.1.0",
67+
"css": "3.0.0",
68+
"css-mediaquery": "^0.1.2",
69+
"glob": "11.0.0",
70+
"lodash": "4.17.21"
71+
},
72+
"devDependencies": {
73+
"@types/css": "latest",
74+
"@types/css-mediaquery": "^0.1.4",
75+
"@types/lodash": "^4.17.7",
76+
"@types/node": "latest",
77+
"ncp": "latest",
78+
"rimraf": "latest",
79+
"ts-node": "latest",
80+
"typescript": "latest"
81+
}
82+
}

0 commit comments

Comments
 (0)