@rollipop/common 0.0.0 → 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +1 -1
- package/dist/index.cjs +290 -0
- package/dist/index.d.cts +91 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.js +242 -0
- package/package.json +47 -2
- package/.editorconfig +0 -10
- package/.gitattributes +0 -4
package/CHANGELOG.md
ADDED
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
# rollipop
|
|
1
|
+
# @rollipop/common
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
let chalk = require("chalk");
|
|
29
|
+
chalk = __toESM(chalk);
|
|
30
|
+
let gradient_string = require("gradient-string");
|
|
31
|
+
gradient_string = __toESM(gradient_string);
|
|
32
|
+
let dayjs = require("dayjs");
|
|
33
|
+
dayjs = __toESM(dayjs);
|
|
34
|
+
let es_toolkit = require("es-toolkit");
|
|
35
|
+
let node_fs = require("node:fs");
|
|
36
|
+
node_fs = __toESM(node_fs);
|
|
37
|
+
let node_path = require("node:path");
|
|
38
|
+
node_path = __toESM(node_path);
|
|
39
|
+
|
|
40
|
+
//#region src/logo.ts
|
|
41
|
+
const CANDY = `
|
|
42
|
+
_....._
|
|
43
|
+
.' _..._ '.
|
|
44
|
+
/ /\` __ \`\\ \\
|
|
45
|
+
; ; /\` \\ | ;
|
|
46
|
+
| | | (_/ ; |
|
|
47
|
+
; ; \\_ _.' .;
|
|
48
|
+
\\ '. \`\` _.'/
|
|
49
|
+
'._\`"'"\`_.'`;
|
|
50
|
+
const STICK = `
|
|
51
|
+
/ /\`\`
|
|
52
|
+
/ /
|
|
53
|
+
/__/`;
|
|
54
|
+
const DESCRIPTIONS = [
|
|
55
|
+
"Rollipop",
|
|
56
|
+
"Modern build toolkit for React Native",
|
|
57
|
+
"Powered by Rolldown"
|
|
58
|
+
];
|
|
59
|
+
const PRIMARY_COLOR = "#42A5F5";
|
|
60
|
+
const BASE_GRADIENT_COLORS = [PRIMARY_COLOR, "#BBDEFB"];
|
|
61
|
+
const PADDING = 20;
|
|
62
|
+
function printLogo() {
|
|
63
|
+
let maxLogoWidth = 0;
|
|
64
|
+
const padding = " ".repeat(PADDING);
|
|
65
|
+
const gradientColors = [...BASE_GRADIENT_COLORS];
|
|
66
|
+
const styledCandy = CANDY.split("\n").map((line) => {
|
|
67
|
+
maxLogoWidth = Math.max(line.length, maxLogoWidth);
|
|
68
|
+
return (0, gradient_string.default)(gradientColors.reverse())(line);
|
|
69
|
+
}).join("\n") + STICK;
|
|
70
|
+
console.log(styledCandy.split("\n").map((line) => padding + line).join("\n"));
|
|
71
|
+
console.log("");
|
|
72
|
+
DESCRIPTIONS.forEach((description, index) => {
|
|
73
|
+
const descriptionHalfLength = description.length / 2;
|
|
74
|
+
const logoHalfWidth = maxLogoWidth / 2;
|
|
75
|
+
const padding$1 = " ".repeat(PADDING - descriptionHalfLength + logoHalfWidth);
|
|
76
|
+
if (index === 0) console.log(padding$1 + chalk.default.bold.hex(PRIMARY_COLOR)(description));
|
|
77
|
+
else console.log(padding$1 + description);
|
|
78
|
+
});
|
|
79
|
+
console.log("");
|
|
80
|
+
}
|
|
81
|
+
let _printed = false;
|
|
82
|
+
const Logo = {
|
|
83
|
+
print: printLogo,
|
|
84
|
+
printOnce: () => {
|
|
85
|
+
if (_printed) return;
|
|
86
|
+
_printed = true;
|
|
87
|
+
printLogo();
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/constants.ts
|
|
93
|
+
const DEBUG_KEY = "rollipop";
|
|
94
|
+
const SHARED_DATA_PATH = ".rollipop";
|
|
95
|
+
const DEV_SERVER_ASSET_PATH = "assets";
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/debug.ts
|
|
99
|
+
const TRUTHY_VALUES = [
|
|
100
|
+
"yes",
|
|
101
|
+
"on",
|
|
102
|
+
"true",
|
|
103
|
+
"enabled"
|
|
104
|
+
];
|
|
105
|
+
const FALSY_VALUES = [
|
|
106
|
+
"no",
|
|
107
|
+
"off",
|
|
108
|
+
"false",
|
|
109
|
+
"disabled"
|
|
110
|
+
];
|
|
111
|
+
function parseDebugKeys() {
|
|
112
|
+
return Object.keys(process.env).filter((key) => /^debug_/i.test(key)).reduce((acc, key) => {
|
|
113
|
+
const prop = key.slice(6).toLowerCase().replace(/_([a-z])/g, (_, key$1) => key$1.toUpperCase());
|
|
114
|
+
let value = process.env[key];
|
|
115
|
+
const lowerCase = typeof value === "string" ? value.toLowerCase() : value.toString();
|
|
116
|
+
if (TRUTHY_VALUES.includes(lowerCase)) value = true;
|
|
117
|
+
else if (FALSY_VALUES.includes(lowerCase)) value = false;
|
|
118
|
+
else value = Boolean(Number(value));
|
|
119
|
+
acc[prop] = value;
|
|
120
|
+
return acc;
|
|
121
|
+
}, {});
|
|
122
|
+
}
|
|
123
|
+
let debugKeys = null;
|
|
124
|
+
function isDebugEnabled() {
|
|
125
|
+
if (debugKeys == null) debugKeys = parseDebugKeys();
|
|
126
|
+
return debugKeys[DEBUG_KEY] ?? false;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/logger.ts
|
|
131
|
+
var Logger = class Logger {
|
|
132
|
+
static blocked = false;
|
|
133
|
+
static queuedMessages = [];
|
|
134
|
+
static Colors = {
|
|
135
|
+
trace: chalk.default.gray,
|
|
136
|
+
debug: chalk.default.blue,
|
|
137
|
+
log: chalk.default.green,
|
|
138
|
+
info: chalk.default.cyan,
|
|
139
|
+
warn: chalk.default.yellow,
|
|
140
|
+
error: chalk.default.red
|
|
141
|
+
};
|
|
142
|
+
format = "HH:mm:ss.SSS";
|
|
143
|
+
debugEnabled;
|
|
144
|
+
static block() {
|
|
145
|
+
this.blocked = true;
|
|
146
|
+
}
|
|
147
|
+
static unblock(flush = true) {
|
|
148
|
+
this.blocked = false;
|
|
149
|
+
if (flush) for (const args of Logger.queuedMessages) console.log(...args);
|
|
150
|
+
Logger.queuedMessages.length = 0;
|
|
151
|
+
}
|
|
152
|
+
constructor(scope) {
|
|
153
|
+
this.scope = scope;
|
|
154
|
+
this.debugEnabled = isDebugEnabled();
|
|
155
|
+
}
|
|
156
|
+
getFormat() {
|
|
157
|
+
return this.format;
|
|
158
|
+
}
|
|
159
|
+
setFormat(format) {
|
|
160
|
+
this.format = format;
|
|
161
|
+
}
|
|
162
|
+
getTimestamp() {
|
|
163
|
+
return (0, dayjs.default)().format(this.getFormat());
|
|
164
|
+
}
|
|
165
|
+
print(logLevel, ...args) {
|
|
166
|
+
const timestamp = chalk.default.gray(this.getTimestamp());
|
|
167
|
+
const level = Logger.Colors[logLevel](logLevel);
|
|
168
|
+
if (this.scope) args = [
|
|
169
|
+
timestamp,
|
|
170
|
+
level,
|
|
171
|
+
chalk.default.magenta(this.scope),
|
|
172
|
+
...args
|
|
173
|
+
];
|
|
174
|
+
else args = [
|
|
175
|
+
timestamp,
|
|
176
|
+
level,
|
|
177
|
+
...args
|
|
178
|
+
];
|
|
179
|
+
if (Logger.blocked) Logger.queuedMessages.push(args);
|
|
180
|
+
else console.log(...args);
|
|
181
|
+
}
|
|
182
|
+
trace(...args) {
|
|
183
|
+
this.debugEnabled && this.print("trace", ...args);
|
|
184
|
+
}
|
|
185
|
+
debug(...args) {
|
|
186
|
+
this.debugEnabled && this.print("debug", ...args);
|
|
187
|
+
}
|
|
188
|
+
log(...args) {
|
|
189
|
+
this.print("log", ...args);
|
|
190
|
+
}
|
|
191
|
+
info(...args) {
|
|
192
|
+
this.print("info", ...args);
|
|
193
|
+
}
|
|
194
|
+
warn(...args) {
|
|
195
|
+
this.print("warn", ...args);
|
|
196
|
+
}
|
|
197
|
+
error(...args) {
|
|
198
|
+
this.print("error", ...args);
|
|
199
|
+
}
|
|
200
|
+
child(scope) {
|
|
201
|
+
(0, es_toolkit.invariant)(this.scope, "Logger must have a scope to create a child logger");
|
|
202
|
+
return new Logger(`${this.scope}:${scope}`);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
function loggerFilter(logger, options) {
|
|
206
|
+
const originalLog = logger[options.level];
|
|
207
|
+
logger[options.level] = (...args) => {
|
|
208
|
+
const filteredArgs = options.filter(args);
|
|
209
|
+
if (filteredArgs.length === 0) return;
|
|
210
|
+
originalLog(...filteredArgs);
|
|
211
|
+
};
|
|
212
|
+
return logger;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region src/fs.ts
|
|
217
|
+
function getSharedDataPath(basePath) {
|
|
218
|
+
return node_path.default.join(basePath, SHARED_DATA_PATH);
|
|
219
|
+
}
|
|
220
|
+
function ensureSharedDataPath(basePath) {
|
|
221
|
+
const sharedDataPath = getSharedDataPath(basePath);
|
|
222
|
+
if (!node_fs.default.existsSync(sharedDataPath)) node_fs.default.mkdirSync(sharedDataPath, { recursive: true });
|
|
223
|
+
return sharedDataPath;
|
|
224
|
+
}
|
|
225
|
+
function getSettingsPath(basePath) {
|
|
226
|
+
return node_path.default.join(getSharedDataPath(basePath), "settings.json");
|
|
227
|
+
}
|
|
228
|
+
function loadSettings(basePath) {
|
|
229
|
+
const settingsPath = getSettingsPath(basePath);
|
|
230
|
+
if (!node_fs.default.existsSync(settingsPath)) return {};
|
|
231
|
+
return JSON.parse(node_fs.default.readFileSync(settingsPath, "utf-8"));
|
|
232
|
+
}
|
|
233
|
+
function saveSettings(basePath, settings) {
|
|
234
|
+
const newSettings = (0, es_toolkit.merge)(loadSettings(basePath), settings);
|
|
235
|
+
node_fs.default.writeFileSync(getSettingsPath(basePath), JSON.stringify(newSettings, null, 2));
|
|
236
|
+
}
|
|
237
|
+
function getCachePath(basePath) {
|
|
238
|
+
return node_path.default.join(getSharedDataPath(basePath), "cache");
|
|
239
|
+
}
|
|
240
|
+
function resetCache(basePath) {
|
|
241
|
+
node_fs.default.rmSync(getCachePath(basePath), {
|
|
242
|
+
recursive: true,
|
|
243
|
+
force: true
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region src/storage.ts
|
|
249
|
+
const DEFAULT_DATA = { build: {} };
|
|
250
|
+
var FileStorage = class FileStorage {
|
|
251
|
+
static instance = null;
|
|
252
|
+
dataFilePath;
|
|
253
|
+
data;
|
|
254
|
+
static getInstance(basePath) {
|
|
255
|
+
if (FileStorage.instance == null) FileStorage.instance = new FileStorage(basePath);
|
|
256
|
+
return new FileStorage(basePath);
|
|
257
|
+
}
|
|
258
|
+
constructor(basePath) {
|
|
259
|
+
this.basePath = basePath;
|
|
260
|
+
this.dataFilePath = node_path.default.join(getSharedDataPath(basePath), "rollipop.json");
|
|
261
|
+
if (node_fs.default.existsSync(this.dataFilePath)) this.data = JSON.parse(node_fs.default.readFileSync(this.dataFilePath, "utf-8"));
|
|
262
|
+
else this.data = DEFAULT_DATA;
|
|
263
|
+
}
|
|
264
|
+
get() {
|
|
265
|
+
return this.data;
|
|
266
|
+
}
|
|
267
|
+
set(data) {
|
|
268
|
+
this.data = (0, es_toolkit.merge)(this.data, data);
|
|
269
|
+
node_fs.default.writeFileSync(this.dataFilePath, JSON.stringify(this.data, null, 2));
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
//#endregion
|
|
274
|
+
exports.DEBUG_KEY = DEBUG_KEY;
|
|
275
|
+
exports.DEV_SERVER_ASSET_PATH = DEV_SERVER_ASSET_PATH;
|
|
276
|
+
exports.FileStorage = FileStorage;
|
|
277
|
+
exports.Logger = Logger;
|
|
278
|
+
exports.Logo = Logo;
|
|
279
|
+
exports.SHARED_DATA_PATH = SHARED_DATA_PATH;
|
|
280
|
+
exports.chalk = chalk.default;
|
|
281
|
+
exports.ensureSharedDataPath = ensureSharedDataPath;
|
|
282
|
+
exports.getCachePath = getCachePath;
|
|
283
|
+
exports.getSettingsPath = getSettingsPath;
|
|
284
|
+
exports.getSharedDataPath = getSharedDataPath;
|
|
285
|
+
exports.isDebugEnabled = isDebugEnabled;
|
|
286
|
+
exports.loadSettings = loadSettings;
|
|
287
|
+
exports.loggerFilter = loggerFilter;
|
|
288
|
+
exports.parseDebugKeys = parseDebugKeys;
|
|
289
|
+
exports.resetCache = resetCache;
|
|
290
|
+
exports.saveSettings = saveSettings;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import chalk, { ChalkInstance } from "chalk";
|
|
2
|
+
|
|
3
|
+
//#region src/logo.d.ts
|
|
4
|
+
declare function printLogo(): void;
|
|
5
|
+
declare const Logo: {
|
|
6
|
+
print: typeof printLogo;
|
|
7
|
+
printOnce: () => void;
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/logger.d.ts
|
|
11
|
+
type LogLevel = 'trace' | 'debug' | 'log' | 'info' | 'warn' | 'error';
|
|
12
|
+
declare class Logger {
|
|
13
|
+
private readonly scope?;
|
|
14
|
+
private static blocked;
|
|
15
|
+
private static queuedMessages;
|
|
16
|
+
static Colors: {
|
|
17
|
+
trace: ChalkInstance;
|
|
18
|
+
debug: ChalkInstance;
|
|
19
|
+
log: ChalkInstance;
|
|
20
|
+
info: ChalkInstance;
|
|
21
|
+
warn: ChalkInstance;
|
|
22
|
+
error: ChalkInstance;
|
|
23
|
+
};
|
|
24
|
+
private format;
|
|
25
|
+
private debugEnabled;
|
|
26
|
+
static block(): void;
|
|
27
|
+
static unblock(flush?: boolean): void;
|
|
28
|
+
constructor(scope?: string | undefined);
|
|
29
|
+
getFormat(): string;
|
|
30
|
+
setFormat(format: string): void;
|
|
31
|
+
private getTimestamp;
|
|
32
|
+
private print;
|
|
33
|
+
trace(...args: unknown[]): void;
|
|
34
|
+
debug(...args: unknown[]): void;
|
|
35
|
+
log(...args: unknown[]): void;
|
|
36
|
+
info(...args: unknown[]): void;
|
|
37
|
+
warn(...args: unknown[]): void;
|
|
38
|
+
error(...args: unknown[]): void;
|
|
39
|
+
child(scope: string): Logger;
|
|
40
|
+
}
|
|
41
|
+
interface LoggerFilterOptions {
|
|
42
|
+
level: LogLevel;
|
|
43
|
+
filter: (args: unknown[]) => unknown[];
|
|
44
|
+
}
|
|
45
|
+
declare function loggerFilter(logger: Logger, options: LoggerFilterOptions): Logger;
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/constants.d.ts
|
|
48
|
+
declare const DEBUG_KEY = "rollipop";
|
|
49
|
+
declare const SHARED_DATA_PATH = ".rollipop";
|
|
50
|
+
declare const DEV_SERVER_ASSET_PATH = "assets";
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/types.d.ts
|
|
53
|
+
interface FileStorageData {
|
|
54
|
+
build: {
|
|
55
|
+
[buildHash: string]: {
|
|
56
|
+
totalModules: number;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
interface Settings {
|
|
61
|
+
devtools?: {
|
|
62
|
+
autoOpen?: boolean;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/fs.d.ts
|
|
67
|
+
declare function getSharedDataPath(basePath: string): string;
|
|
68
|
+
declare function ensureSharedDataPath(basePath: string): string;
|
|
69
|
+
declare function getSettingsPath(basePath: string): string;
|
|
70
|
+
declare function loadSettings(basePath: string): Settings;
|
|
71
|
+
declare function saveSettings(basePath: string, settings: Partial<Settings>): void;
|
|
72
|
+
declare function getCachePath(basePath: string): string;
|
|
73
|
+
declare function resetCache(basePath: string): void;
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/debug.d.ts
|
|
76
|
+
declare function parseDebugKeys(): Record<string, boolean>;
|
|
77
|
+
declare function isDebugEnabled(): boolean;
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/storage.d.ts
|
|
80
|
+
declare class FileStorage {
|
|
81
|
+
private readonly basePath;
|
|
82
|
+
private static instance;
|
|
83
|
+
private dataFilePath;
|
|
84
|
+
private data;
|
|
85
|
+
static getInstance(basePath: string): FileStorage;
|
|
86
|
+
private constructor();
|
|
87
|
+
get(): FileStorageData;
|
|
88
|
+
set(data: Partial<FileStorageData>): void;
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
export { DEBUG_KEY, DEV_SERVER_ASSET_PATH, FileStorage, FileStorageData, LogLevel, Logger, LoggerFilterOptions, Logo, SHARED_DATA_PATH, Settings, chalk, ensureSharedDataPath, getCachePath, getSettingsPath, getSharedDataPath, isDebugEnabled, loadSettings, loggerFilter, parseDebugKeys, resetCache, saveSettings };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import chalk, { ChalkInstance } from "chalk";
|
|
2
|
+
|
|
3
|
+
//#region src/logo.d.ts
|
|
4
|
+
declare function printLogo(): void;
|
|
5
|
+
declare const Logo: {
|
|
6
|
+
print: typeof printLogo;
|
|
7
|
+
printOnce: () => void;
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/logger.d.ts
|
|
11
|
+
type LogLevel = 'trace' | 'debug' | 'log' | 'info' | 'warn' | 'error';
|
|
12
|
+
declare class Logger {
|
|
13
|
+
private readonly scope?;
|
|
14
|
+
private static blocked;
|
|
15
|
+
private static queuedMessages;
|
|
16
|
+
static Colors: {
|
|
17
|
+
trace: ChalkInstance;
|
|
18
|
+
debug: ChalkInstance;
|
|
19
|
+
log: ChalkInstance;
|
|
20
|
+
info: ChalkInstance;
|
|
21
|
+
warn: ChalkInstance;
|
|
22
|
+
error: ChalkInstance;
|
|
23
|
+
};
|
|
24
|
+
private format;
|
|
25
|
+
private debugEnabled;
|
|
26
|
+
static block(): void;
|
|
27
|
+
static unblock(flush?: boolean): void;
|
|
28
|
+
constructor(scope?: string | undefined);
|
|
29
|
+
getFormat(): string;
|
|
30
|
+
setFormat(format: string): void;
|
|
31
|
+
private getTimestamp;
|
|
32
|
+
private print;
|
|
33
|
+
trace(...args: unknown[]): void;
|
|
34
|
+
debug(...args: unknown[]): void;
|
|
35
|
+
log(...args: unknown[]): void;
|
|
36
|
+
info(...args: unknown[]): void;
|
|
37
|
+
warn(...args: unknown[]): void;
|
|
38
|
+
error(...args: unknown[]): void;
|
|
39
|
+
child(scope: string): Logger;
|
|
40
|
+
}
|
|
41
|
+
interface LoggerFilterOptions {
|
|
42
|
+
level: LogLevel;
|
|
43
|
+
filter: (args: unknown[]) => unknown[];
|
|
44
|
+
}
|
|
45
|
+
declare function loggerFilter(logger: Logger, options: LoggerFilterOptions): Logger;
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/constants.d.ts
|
|
48
|
+
declare const DEBUG_KEY = "rollipop";
|
|
49
|
+
declare const SHARED_DATA_PATH = ".rollipop";
|
|
50
|
+
declare const DEV_SERVER_ASSET_PATH = "assets";
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/types.d.ts
|
|
53
|
+
interface FileStorageData {
|
|
54
|
+
build: {
|
|
55
|
+
[buildHash: string]: {
|
|
56
|
+
totalModules: number;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
interface Settings {
|
|
61
|
+
devtools?: {
|
|
62
|
+
autoOpen?: boolean;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/fs.d.ts
|
|
67
|
+
declare function getSharedDataPath(basePath: string): string;
|
|
68
|
+
declare function ensureSharedDataPath(basePath: string): string;
|
|
69
|
+
declare function getSettingsPath(basePath: string): string;
|
|
70
|
+
declare function loadSettings(basePath: string): Settings;
|
|
71
|
+
declare function saveSettings(basePath: string, settings: Partial<Settings>): void;
|
|
72
|
+
declare function getCachePath(basePath: string): string;
|
|
73
|
+
declare function resetCache(basePath: string): void;
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/debug.d.ts
|
|
76
|
+
declare function parseDebugKeys(): Record<string, boolean>;
|
|
77
|
+
declare function isDebugEnabled(): boolean;
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/storage.d.ts
|
|
80
|
+
declare class FileStorage {
|
|
81
|
+
private readonly basePath;
|
|
82
|
+
private static instance;
|
|
83
|
+
private dataFilePath;
|
|
84
|
+
private data;
|
|
85
|
+
static getInstance(basePath: string): FileStorage;
|
|
86
|
+
private constructor();
|
|
87
|
+
get(): FileStorageData;
|
|
88
|
+
set(data: Partial<FileStorageData>): void;
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
export { DEBUG_KEY, DEV_SERVER_ASSET_PATH, FileStorage, FileStorageData, LogLevel, Logger, LoggerFilterOptions, Logo, SHARED_DATA_PATH, Settings, chalk, ensureSharedDataPath, getCachePath, getSettingsPath, getSharedDataPath, isDebugEnabled, loadSettings, loggerFilter, parseDebugKeys, resetCache, saveSettings };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import chalk, { default as chalk$1 } from "chalk";
|
|
2
|
+
import gradient from "gradient-string";
|
|
3
|
+
import dayjs from "dayjs";
|
|
4
|
+
import { invariant, merge } from "es-toolkit";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
|
|
8
|
+
//#region src/logo.ts
|
|
9
|
+
const CANDY = `
|
|
10
|
+
_....._
|
|
11
|
+
.' _..._ '.
|
|
12
|
+
/ /\` __ \`\\ \\
|
|
13
|
+
; ; /\` \\ | ;
|
|
14
|
+
| | | (_/ ; |
|
|
15
|
+
; ; \\_ _.' .;
|
|
16
|
+
\\ '. \`\` _.'/
|
|
17
|
+
'._\`"'"\`_.'`;
|
|
18
|
+
const STICK = `
|
|
19
|
+
/ /\`\`
|
|
20
|
+
/ /
|
|
21
|
+
/__/`;
|
|
22
|
+
const DESCRIPTIONS = [
|
|
23
|
+
"Rollipop",
|
|
24
|
+
"Modern build toolkit for React Native",
|
|
25
|
+
"Powered by Rolldown"
|
|
26
|
+
];
|
|
27
|
+
const PRIMARY_COLOR = "#42A5F5";
|
|
28
|
+
const BASE_GRADIENT_COLORS = [PRIMARY_COLOR, "#BBDEFB"];
|
|
29
|
+
const PADDING = 20;
|
|
30
|
+
function printLogo() {
|
|
31
|
+
let maxLogoWidth = 0;
|
|
32
|
+
const padding = " ".repeat(PADDING);
|
|
33
|
+
const gradientColors = [...BASE_GRADIENT_COLORS];
|
|
34
|
+
const styledCandy = CANDY.split("\n").map((line) => {
|
|
35
|
+
maxLogoWidth = Math.max(line.length, maxLogoWidth);
|
|
36
|
+
return gradient(gradientColors.reverse())(line);
|
|
37
|
+
}).join("\n") + STICK;
|
|
38
|
+
console.log(styledCandy.split("\n").map((line) => padding + line).join("\n"));
|
|
39
|
+
console.log("");
|
|
40
|
+
DESCRIPTIONS.forEach((description, index) => {
|
|
41
|
+
const descriptionHalfLength = description.length / 2;
|
|
42
|
+
const logoHalfWidth = maxLogoWidth / 2;
|
|
43
|
+
const padding$1 = " ".repeat(PADDING - descriptionHalfLength + logoHalfWidth);
|
|
44
|
+
if (index === 0) console.log(padding$1 + chalk$1.bold.hex(PRIMARY_COLOR)(description));
|
|
45
|
+
else console.log(padding$1 + description);
|
|
46
|
+
});
|
|
47
|
+
console.log("");
|
|
48
|
+
}
|
|
49
|
+
let _printed = false;
|
|
50
|
+
const Logo = {
|
|
51
|
+
print: printLogo,
|
|
52
|
+
printOnce: () => {
|
|
53
|
+
if (_printed) return;
|
|
54
|
+
_printed = true;
|
|
55
|
+
printLogo();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/constants.ts
|
|
61
|
+
const DEBUG_KEY = "rollipop";
|
|
62
|
+
const SHARED_DATA_PATH = ".rollipop";
|
|
63
|
+
const DEV_SERVER_ASSET_PATH = "assets";
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/debug.ts
|
|
67
|
+
const TRUTHY_VALUES = [
|
|
68
|
+
"yes",
|
|
69
|
+
"on",
|
|
70
|
+
"true",
|
|
71
|
+
"enabled"
|
|
72
|
+
];
|
|
73
|
+
const FALSY_VALUES = [
|
|
74
|
+
"no",
|
|
75
|
+
"off",
|
|
76
|
+
"false",
|
|
77
|
+
"disabled"
|
|
78
|
+
];
|
|
79
|
+
function parseDebugKeys() {
|
|
80
|
+
return Object.keys(process.env).filter((key) => /^debug_/i.test(key)).reduce((acc, key) => {
|
|
81
|
+
const prop = key.slice(6).toLowerCase().replace(/_([a-z])/g, (_, key$1) => key$1.toUpperCase());
|
|
82
|
+
let value = process.env[key];
|
|
83
|
+
const lowerCase = typeof value === "string" ? value.toLowerCase() : value.toString();
|
|
84
|
+
if (TRUTHY_VALUES.includes(lowerCase)) value = true;
|
|
85
|
+
else if (FALSY_VALUES.includes(lowerCase)) value = false;
|
|
86
|
+
else value = Boolean(Number(value));
|
|
87
|
+
acc[prop] = value;
|
|
88
|
+
return acc;
|
|
89
|
+
}, {});
|
|
90
|
+
}
|
|
91
|
+
let debugKeys = null;
|
|
92
|
+
function isDebugEnabled() {
|
|
93
|
+
if (debugKeys == null) debugKeys = parseDebugKeys();
|
|
94
|
+
return debugKeys[DEBUG_KEY] ?? false;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/logger.ts
|
|
99
|
+
var Logger = class Logger {
|
|
100
|
+
static blocked = false;
|
|
101
|
+
static queuedMessages = [];
|
|
102
|
+
static Colors = {
|
|
103
|
+
trace: chalk$1.gray,
|
|
104
|
+
debug: chalk$1.blue,
|
|
105
|
+
log: chalk$1.green,
|
|
106
|
+
info: chalk$1.cyan,
|
|
107
|
+
warn: chalk$1.yellow,
|
|
108
|
+
error: chalk$1.red
|
|
109
|
+
};
|
|
110
|
+
format = "HH:mm:ss.SSS";
|
|
111
|
+
debugEnabled;
|
|
112
|
+
static block() {
|
|
113
|
+
this.blocked = true;
|
|
114
|
+
}
|
|
115
|
+
static unblock(flush = true) {
|
|
116
|
+
this.blocked = false;
|
|
117
|
+
if (flush) for (const args of Logger.queuedMessages) console.log(...args);
|
|
118
|
+
Logger.queuedMessages.length = 0;
|
|
119
|
+
}
|
|
120
|
+
constructor(scope) {
|
|
121
|
+
this.scope = scope;
|
|
122
|
+
this.debugEnabled = isDebugEnabled();
|
|
123
|
+
}
|
|
124
|
+
getFormat() {
|
|
125
|
+
return this.format;
|
|
126
|
+
}
|
|
127
|
+
setFormat(format) {
|
|
128
|
+
this.format = format;
|
|
129
|
+
}
|
|
130
|
+
getTimestamp() {
|
|
131
|
+
return dayjs().format(this.getFormat());
|
|
132
|
+
}
|
|
133
|
+
print(logLevel, ...args) {
|
|
134
|
+
const timestamp = chalk$1.gray(this.getTimestamp());
|
|
135
|
+
const level = Logger.Colors[logLevel](logLevel);
|
|
136
|
+
if (this.scope) args = [
|
|
137
|
+
timestamp,
|
|
138
|
+
level,
|
|
139
|
+
chalk$1.magenta(this.scope),
|
|
140
|
+
...args
|
|
141
|
+
];
|
|
142
|
+
else args = [
|
|
143
|
+
timestamp,
|
|
144
|
+
level,
|
|
145
|
+
...args
|
|
146
|
+
];
|
|
147
|
+
if (Logger.blocked) Logger.queuedMessages.push(args);
|
|
148
|
+
else console.log(...args);
|
|
149
|
+
}
|
|
150
|
+
trace(...args) {
|
|
151
|
+
this.debugEnabled && this.print("trace", ...args);
|
|
152
|
+
}
|
|
153
|
+
debug(...args) {
|
|
154
|
+
this.debugEnabled && this.print("debug", ...args);
|
|
155
|
+
}
|
|
156
|
+
log(...args) {
|
|
157
|
+
this.print("log", ...args);
|
|
158
|
+
}
|
|
159
|
+
info(...args) {
|
|
160
|
+
this.print("info", ...args);
|
|
161
|
+
}
|
|
162
|
+
warn(...args) {
|
|
163
|
+
this.print("warn", ...args);
|
|
164
|
+
}
|
|
165
|
+
error(...args) {
|
|
166
|
+
this.print("error", ...args);
|
|
167
|
+
}
|
|
168
|
+
child(scope) {
|
|
169
|
+
invariant(this.scope, "Logger must have a scope to create a child logger");
|
|
170
|
+
return new Logger(`${this.scope}:${scope}`);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
function loggerFilter(logger, options) {
|
|
174
|
+
const originalLog = logger[options.level];
|
|
175
|
+
logger[options.level] = (...args) => {
|
|
176
|
+
const filteredArgs = options.filter(args);
|
|
177
|
+
if (filteredArgs.length === 0) return;
|
|
178
|
+
originalLog(...filteredArgs);
|
|
179
|
+
};
|
|
180
|
+
return logger;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/fs.ts
|
|
185
|
+
function getSharedDataPath(basePath) {
|
|
186
|
+
return path.join(basePath, SHARED_DATA_PATH);
|
|
187
|
+
}
|
|
188
|
+
function ensureSharedDataPath(basePath) {
|
|
189
|
+
const sharedDataPath = getSharedDataPath(basePath);
|
|
190
|
+
if (!fs.existsSync(sharedDataPath)) fs.mkdirSync(sharedDataPath, { recursive: true });
|
|
191
|
+
return sharedDataPath;
|
|
192
|
+
}
|
|
193
|
+
function getSettingsPath(basePath) {
|
|
194
|
+
return path.join(getSharedDataPath(basePath), "settings.json");
|
|
195
|
+
}
|
|
196
|
+
function loadSettings(basePath) {
|
|
197
|
+
const settingsPath = getSettingsPath(basePath);
|
|
198
|
+
if (!fs.existsSync(settingsPath)) return {};
|
|
199
|
+
return JSON.parse(fs.readFileSync(settingsPath, "utf-8"));
|
|
200
|
+
}
|
|
201
|
+
function saveSettings(basePath, settings) {
|
|
202
|
+
const newSettings = merge(loadSettings(basePath), settings);
|
|
203
|
+
fs.writeFileSync(getSettingsPath(basePath), JSON.stringify(newSettings, null, 2));
|
|
204
|
+
}
|
|
205
|
+
function getCachePath(basePath) {
|
|
206
|
+
return path.join(getSharedDataPath(basePath), "cache");
|
|
207
|
+
}
|
|
208
|
+
function resetCache(basePath) {
|
|
209
|
+
fs.rmSync(getCachePath(basePath), {
|
|
210
|
+
recursive: true,
|
|
211
|
+
force: true
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region src/storage.ts
|
|
217
|
+
const DEFAULT_DATA = { build: {} };
|
|
218
|
+
var FileStorage = class FileStorage {
|
|
219
|
+
static instance = null;
|
|
220
|
+
dataFilePath;
|
|
221
|
+
data;
|
|
222
|
+
static getInstance(basePath) {
|
|
223
|
+
if (FileStorage.instance == null) FileStorage.instance = new FileStorage(basePath);
|
|
224
|
+
return new FileStorage(basePath);
|
|
225
|
+
}
|
|
226
|
+
constructor(basePath) {
|
|
227
|
+
this.basePath = basePath;
|
|
228
|
+
this.dataFilePath = path.join(getSharedDataPath(basePath), "rollipop.json");
|
|
229
|
+
if (fs.existsSync(this.dataFilePath)) this.data = JSON.parse(fs.readFileSync(this.dataFilePath, "utf-8"));
|
|
230
|
+
else this.data = DEFAULT_DATA;
|
|
231
|
+
}
|
|
232
|
+
get() {
|
|
233
|
+
return this.data;
|
|
234
|
+
}
|
|
235
|
+
set(data) {
|
|
236
|
+
this.data = merge(this.data, data);
|
|
237
|
+
fs.writeFileSync(this.dataFilePath, JSON.stringify(this.data, null, 2));
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
//#endregion
|
|
242
|
+
export { DEBUG_KEY, DEV_SERVER_ASSET_PATH, FileStorage, Logger, Logo, SHARED_DATA_PATH, chalk, ensureSharedDataPath, getCachePath, getSettingsPath, getSharedDataPath, isDebugEnabled, loadSettings, loggerFilter, parseDebugKeys, resetCache, saveSettings };
|
package/package.json
CHANGED
|
@@ -1,4 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rollipop/common",
|
|
3
|
-
"version": "0.0.0"
|
|
4
|
-
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"import": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"default": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"require": {
|
|
12
|
+
"types": "./dist/index.d.cts",
|
|
13
|
+
"default": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/leegeunhyeok/rollipop.git",
|
|
24
|
+
"directory": "packages/common"
|
|
25
|
+
},
|
|
26
|
+
"author": "leegeunhyeok <dev.ghlee@gmail.com> (https://github.com/leegeunhyeok)",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/leegeunhyeok/rollipop/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/leegeunhyeok/rollipop#readme",
|
|
32
|
+
"scripts": {
|
|
33
|
+
"prepack": "yarn build",
|
|
34
|
+
"typecheck": "tsc --noEmit",
|
|
35
|
+
"test": "vitest --run",
|
|
36
|
+
"build": "tsdown"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"tsdown": "0.18.1",
|
|
40
|
+
"typescript": "5.9.3",
|
|
41
|
+
"vitest": "4.0.16"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"chalk": "^5.6.2",
|
|
45
|
+
"dayjs": "^1.11.19",
|
|
46
|
+
"es-toolkit": "1.43.0",
|
|
47
|
+
"gradient-string": "^3.0.0"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/.editorconfig
DELETED
package/.gitattributes
DELETED