tailwindcss-patch 2.0.4 → 2.0.5-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/dist/index.mjs CHANGED
@@ -1,523 +1,64 @@
1
- import fs$1 from 'node:fs/promises';
2
- import path, { dirname } from 'node:path';
3
- import fs from 'node:fs';
4
- import pkg from 'resolve';
5
- import { gte } from 'semver';
6
- import * as t from '@babel/types';
7
- import generate from '@babel/generator';
8
- import traverse from '@babel/traverse';
9
- import { parse } from '@babel/parser';
10
- import postcss from 'postcss';
11
- import { lilconfig } from 'lilconfig';
12
- import createJiti from 'jiti';
1
+ import {
2
+ CacheManager,
3
+ TailwindcssPatcher,
4
+ __export,
5
+ __reExport,
6
+ core_exports,
7
+ createPatch,
8
+ ensureDir,
9
+ ensureFileContent,
10
+ getCacheOptions,
11
+ getClassCacheSet,
12
+ getClassCaches,
13
+ getContexts,
14
+ getInstalledPkgJsonPath,
15
+ getPatchOptions,
16
+ getTailwindcssEntry,
17
+ inspectPostcssPlugin,
18
+ inspectProcessTailwindFeaturesReturnContext,
19
+ internalPatch,
20
+ monkeyPatchForExposingContext,
21
+ requireResolve
22
+ } from "./chunk-W6X43COS.mjs";
13
23
 
14
-
15
- // -- Unbuild CommonJS Shims --
16
- import __cjs_url__ from 'url';
17
- import __cjs_path__ from 'path';
18
- import __cjs_mod__ from 'module';
19
- const __filename = __cjs_url__.fileURLToPath(import.meta.url);
20
- const __dirname = __cjs_path__.dirname(__filename);
21
- const require = __cjs_mod__.createRequire(import.meta.url);
22
- export * from '@tailwindcss-mangle/config';
23
-
24
- const { sync } = pkg;
25
- function ensureFileContent(filepaths) {
26
- if (typeof filepaths === "string") {
27
- filepaths = [filepaths];
28
- }
29
- let content;
30
- for (const filepath of filepaths) {
31
- if (fs.existsSync(filepath)) {
32
- content = fs.readFileSync(filepath, {
33
- encoding: "utf8"
34
- });
35
- break;
36
- }
37
- }
38
- return content;
39
- }
40
- function requireResolve(id, opts) {
41
- return sync(id, opts);
42
- }
43
- async function ensureDir(p) {
44
- try {
45
- await fs$1.access(p);
46
- } catch {
47
- await fs$1.mkdir(p, {
48
- recursive: true
49
- });
50
- }
51
- }
52
-
53
- function getTailwindcssEntry(basedir = process.cwd()) {
54
- return requireResolve("tailwindcss");
55
- }
56
- function getContexts(basedir) {
57
- const twPath = getTailwindcssEntry(basedir);
58
- const distPath = path.dirname(twPath);
59
- let injectFilePath = path.join(distPath, "plugin.js");
60
- if (!fs.existsSync(injectFilePath)) {
61
- injectFilePath = path.join(distPath, "index.js");
62
- }
63
- const mo = require(injectFilePath);
64
- if (mo.contextRef) {
65
- return mo.contextRef.value;
66
- }
67
- return [];
68
- }
69
- function getClassCaches(basedir) {
70
- const contexts = getContexts(basedir);
71
- return contexts.map((x) => x.classCache);
72
- }
73
- function getClassCacheSet(basedir, options) {
74
- const classCaches = getClassCaches(basedir);
75
- const classSet = /* @__PURE__ */ new Set();
76
- for (const classCacheMap of classCaches) {
77
- const keys = classCacheMap.keys();
78
- for (const key of keys) {
79
- const v = key.toString();
80
- if (options?.removeUniversalSelector && v === "*") {
81
- continue;
82
- }
83
- classSet.add(v);
84
- }
85
- }
86
- return classSet;
87
- }
88
-
89
- const pkgName = "tailwindcss-patch";
90
-
91
- function log(message, ...optionalParams) {
92
- return console.log(`[${pkgName}]:` + message, ...optionalParams);
93
- }
94
-
95
- function getCacheOptions(options) {
96
- let cache;
97
- switch (typeof options) {
98
- case "undefined": {
99
- cache = {
100
- enable: false
101
- };
102
- break;
103
- }
104
- case "boolean": {
105
- cache = {
106
- enable: options
107
- };
108
- break;
109
- }
110
- case "object": {
111
- cache = { ...options, enable: true };
112
- break;
113
- }
114
- }
115
- return cache;
116
- }
117
- class CacheManager {
118
- constructor(options = {}) {
119
- this.options = this.getOptions(options);
120
- }
121
- mkdir(cacheDirectory) {
122
- const exists = fs.existsSync(cacheDirectory);
123
- if (!exists) {
124
- fs.mkdirSync(cacheDirectory, {
125
- recursive: true
126
- });
127
- }
128
- return cacheDirectory;
129
- }
130
- getOptions(options = {}) {
131
- const cwd = options.cwd ?? process.cwd();
132
- const dir = options.dir ?? path.resolve(cwd, "node_modules/.cache", pkgName);
133
- const file = options.file ?? "index.json";
134
- const filename = path.resolve(dir, file);
135
- return {
136
- cwd,
137
- dir,
138
- file,
139
- filename,
140
- strategy: "merge"
141
- };
142
- }
143
- write(data) {
144
- try {
145
- const { dir, filename } = this.options;
146
- this.mkdir(dir);
147
- fs.writeFileSync(filename, JSON.stringify([...data], void 0, 2), "utf8");
148
- return filename;
149
- } catch {
150
- log("write cache file fail!");
151
- }
152
- }
153
- read() {
154
- const { filename } = this.options;
155
- try {
156
- if (fs.existsSync(filename)) {
157
- const data = fs.readFileSync(filename, "utf8");
158
- return new Set(JSON.parse(data));
159
- }
160
- } catch {
161
- log("parse cache content fail! path:" + filename);
162
- try {
163
- fs.unlinkSync(filename);
164
- } catch {
165
- log("delete cache file fail! path:" + filename);
166
- }
167
- }
168
- }
169
- }
170
-
171
- function isObject(value) {
172
- return value !== null && typeof value === "object";
173
- }
174
- function _defu(baseObject, defaults, namespace = ".", merger) {
175
- if (!isObject(defaults)) {
176
- return _defu(baseObject, {}, namespace, merger);
177
- }
178
- const object = Object.assign({}, defaults);
179
- for (const key in baseObject) {
180
- if (key === "__proto__" || key === "constructor") {
181
- continue;
182
- }
183
- const value = baseObject[key];
184
- if (value === null || value === void 0) {
185
- continue;
186
- }
187
- if (merger && merger(object, key, value, namespace)) {
188
- continue;
189
- }
190
- if (Array.isArray(value) && Array.isArray(object[key])) {
191
- object[key] = [...value, ...object[key]];
192
- } else if (isObject(value) && isObject(object[key])) {
193
- object[key] = _defu(
194
- value,
195
- object[key],
196
- (namespace ? `${namespace}.` : "") + key.toString(),
197
- merger
198
- );
199
- } else {
200
- object[key] = value;
201
- }
202
- }
203
- return object;
204
- }
205
- function createDefu(merger) {
206
- return (...arguments_) => (
207
- // eslint-disable-next-line unicorn/no-array-reduce
208
- arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
209
- );
210
- }
211
- const defu = createDefu();
212
-
213
- function inspectProcessTailwindFeaturesReturnContext(content) {
214
- const ast = parse(content);
215
- let hasPatched = false;
216
- traverse(ast, {
217
- FunctionDeclaration(p) {
218
- const n = p.node;
219
- if (n.id?.name === "processTailwindFeatures" && n.body.body.length === 1 && t.isReturnStatement(n.body.body[0])) {
220
- const rts = n.body.body[0];
221
- if (t.isFunctionExpression(rts.argument)) {
222
- const body = rts.argument.body.body;
223
- const lastStatement = body.at(-1);
224
- hasPatched = t.isReturnStatement(lastStatement) && t.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context";
225
- if (!hasPatched) {
226
- const rts2 = t.returnStatement(t.identifier("context"));
227
- body.push(rts2);
228
- }
229
- }
230
- }
231
- }
232
- });
233
- return {
234
- code: hasPatched ? content : generate(ast).code,
235
- hasPatched
236
- };
237
- }
238
- function inspectPostcssPlugin(content) {
239
- const ast = parse(content);
240
- const exportKey = "contextRef";
241
- const variableName = "contextRef";
242
- const valueKey = "value";
243
- let hasPatched = false;
244
- traverse(ast, {
245
- Program(p) {
246
- const n = p.node;
247
- const idx = n.body.findIndex((x) => {
248
- return t.isExpressionStatement(x) && t.isAssignmentExpression(x.expression) && t.isMemberExpression(x.expression.left) && t.isFunctionExpression(x.expression.right) && x.expression.right.id?.name === "tailwindcss";
249
- });
250
- if (idx > -1) {
251
- const prevStatement = n.body[idx - 1];
252
- const lastStatement = n.body.at(-1);
253
- const hasPatchedCondition0 = prevStatement && t.isVariableDeclaration(prevStatement) && prevStatement.declarations.length === 1 && t.isIdentifier(prevStatement.declarations[0].id) && prevStatement.declarations[0].id.name === variableName;
254
- const hasPatchedCondition1 = t.isExpressionStatement(lastStatement) && t.isAssignmentExpression(lastStatement.expression) && t.isIdentifier(lastStatement.expression.right) && lastStatement.expression.right.name === variableName;
255
- hasPatched = hasPatchedCondition0 || hasPatchedCondition1;
256
- if (!hasPatched) {
257
- const statement = t.variableDeclaration("const", [
258
- t.variableDeclarator(t.identifier(variableName), t.objectExpression([t.objectProperty(t.identifier(valueKey), t.arrayExpression())]))
259
- ]);
260
- n.body.splice(idx, 0, statement);
261
- n.body.push(
262
- t.expressionStatement(
263
- t.assignmentExpression(
264
- "=",
265
- t.memberExpression(t.memberExpression(t.identifier("module"), t.identifier("exports")), t.identifier(exportKey)),
266
- t.identifier(variableName)
267
- )
268
- )
269
- );
270
- }
271
- }
272
- },
273
- FunctionExpression(p) {
274
- if (hasPatched) {
275
- return;
276
- }
277
- const n = p.node;
278
- if (n.id?.name === "tailwindcss" && n.body.body.length === 1 && t.isReturnStatement(n.body.body[0])) {
279
- const returnStatement = n.body.body[0];
280
- if (t.isObjectExpression(returnStatement.argument) && returnStatement.argument.properties.length === 2) {
281
- const properties = returnStatement.argument.properties;
282
- if (t.isObjectProperty(properties[0]) && t.isObjectProperty(properties[1])) {
283
- const keyMatched = t.isIdentifier(properties[0].key) && properties[0].key.name === "postcssPlugin";
284
- const pluginsMatched = t.isIdentifier(properties[1].key) && properties[1].key.name === "plugins";
285
- if (pluginsMatched && keyMatched && t.isCallExpression(properties[1].value) && t.isMemberExpression(properties[1].value.callee) && t.isArrayExpression(properties[1].value.callee.object)) {
286
- const pluginsCode = properties[1].value.callee.object.elements;
287
- if (pluginsCode[1] && t.isFunctionExpression(pluginsCode[1])) {
288
- const targetBlockStatement = pluginsCode[1].body;
289
- const lastStatement = targetBlockStatement.body.at(-1);
290
- if (t.isExpressionStatement(lastStatement)) {
291
- const newExpressionStatement = t.expressionStatement(
292
- t.callExpression(
293
- t.memberExpression(
294
- t.memberExpression(t.identifier(variableName), t.identifier("value")),
295
- t.identifier("push")
296
- ),
297
- [lastStatement.expression]
298
- )
299
- );
300
- targetBlockStatement.body[targetBlockStatement.body.length - 1] = newExpressionStatement;
301
- }
302
- const ifIdx = targetBlockStatement.body.findIndex((x) => t.isIfStatement(x));
303
- if (ifIdx > -1) {
304
- const ifRoot = targetBlockStatement.body[ifIdx];
305
- if (t.isBlockStatement(ifRoot.consequent) && ifRoot.consequent.body[1] && t.isForOfStatement(ifRoot.consequent.body[1])) {
306
- const forOf = ifRoot.consequent.body[1];
307
- if (t.isBlockStatement(forOf.body) && forOf.body.body.length === 1 && t.isIfStatement(forOf.body.body[0])) {
308
- const if2 = forOf.body.body[0];
309
- if (t.isBlockStatement(if2.consequent) && if2.consequent.body.length === 1 && t.isExpressionStatement(if2.consequent.body[0])) {
310
- const target = if2.consequent.body[0];
311
- const newExpressionStatement = t.expressionStatement(
312
- t.callExpression(t.memberExpression(t.memberExpression(t.identifier(variableName), t.identifier("value")), t.identifier("push")), [target.expression])
313
- );
314
- if2.consequent.body[0] = newExpressionStatement;
315
- }
316
- }
317
- }
318
- }
319
- targetBlockStatement.body.unshift(
320
- // contentRef.value = []
321
- // t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.arrayExpression()))
322
- // contentRef.value.length = 0
323
- t.expressionStatement(
324
- t.assignmentExpression(
325
- "=",
326
- t.memberExpression(t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.identifier("length")),
327
- t.numericLiteral(0)
328
- )
329
- )
330
- );
331
- }
332
- }
333
- }
334
- }
335
- }
336
- }
337
- // BlockStatement(p) {
338
- // const n = p.node
339
- // if (start && p.parent.type === 'FunctionExpression' && !p.parent.id) {
340
- // n.body.unshift(t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(variableName), t.identifier(valueKey)), t.arrayExpression())))
341
- // }
342
- // }
343
- });
344
- return {
345
- code: hasPatched ? content : generate(ast).code,
346
- hasPatched
347
- };
348
- }
349
-
350
- function getDefaultPatchOptions() {
351
- return {
352
- overwrite: true
353
- };
354
- }
355
-
356
- function getInstalledPkgJsonPath(options = {}) {
357
- try {
358
- const tmpJsonPath = requireResolve(`tailwindcss/package.json`, {
359
- paths: options.paths
360
- });
361
- return tmpJsonPath;
362
- } catch (error) {
363
- if (error.code === "MODULE_NOT_FOUND") {
364
- console.warn("Can't find npm pkg: `tailwindcss`, Please ensure it has been installed!");
365
- }
366
- }
367
- }
368
- function getPatchOptions(options = {}) {
369
- return defu(
370
- options,
371
- {
372
- basedir: process.cwd()
373
- },
374
- getDefaultPatchOptions()
375
- );
376
- }
377
- function createPatch(opt) {
378
- return () => {
379
- try {
380
- const pkgJsonPath = getInstalledPkgJsonPath(opt);
381
- return internalPatch(pkgJsonPath, opt);
382
- } catch (error) {
383
- console.warn(`patch tailwindcss failed:` + error.message);
384
- }
385
- };
386
- }
387
- function monkeyPatchForExposingContext(twDir, opt) {
388
- const processTailwindFeaturesFilePath = path.resolve(twDir, "lib/processTailwindFeatures.js");
389
- const processTailwindFeaturesContent = ensureFileContent(processTailwindFeaturesFilePath);
390
- const result = {};
391
- if (processTailwindFeaturesContent) {
392
- const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext(processTailwindFeaturesContent);
393
- if (!hasPatched && opt.overwrite) {
394
- fs.writeFileSync(processTailwindFeaturesFilePath, code, {
395
- encoding: "utf8"
396
- });
397
- console.log("patch tailwindcss processTailwindFeatures for return content successfully!");
398
- }
399
- result.processTailwindFeatures = code;
400
- }
401
- const pluginFilePath = path.resolve(twDir, "lib/plugin.js");
402
- const indexFilePath = path.resolve(twDir, "lib/index.js");
403
- const pluginContent = ensureFileContent([pluginFilePath, indexFilePath]);
404
- if (pluginContent) {
405
- const { code, hasPatched } = inspectPostcssPlugin(pluginContent);
406
- if (!hasPatched && opt.overwrite) {
407
- fs.writeFileSync(pluginFilePath, code, {
408
- encoding: "utf8"
409
- });
410
- console.log("patch tailwindcss for expose runtime content successfully!");
411
- }
412
- result.plugin = code;
413
- }
414
- opt.custom && typeof opt.custom === "function" && opt.custom(twDir, result);
415
- return result;
416
- }
417
- function internalPatch(pkgJsonPath, options) {
418
- if (pkgJsonPath) {
419
- const pkgJson = require(pkgJsonPath);
420
- const twDir = path.dirname(pkgJsonPath);
421
- if (gte(pkgJson.version, "3.0.0")) {
422
- options.version = pkgJson.version;
423
- const result = monkeyPatchForExposingContext(twDir, options);
424
- return result;
425
- }
426
- }
427
- }
428
-
429
- const jiti = createJiti(__filename);
430
- async function processTailwindcss(options) {
431
- options.cwd = options.cwd ?? process.cwd();
432
- let config = options.config;
433
- if (!(typeof options.config === "string" && path.isAbsolute(options.config))) {
434
- const moduleName = "tailwind";
435
- const result = await lilconfig("tailwindcss", {
436
- searchPlaces: [`${moduleName}.config.js`, `${moduleName}.config.cjs`],
437
- loaders: {
438
- // 默认支持 js 和 cjs 2种格式
439
- ".js": jiti,
440
- ".cjs": jiti,
441
- ".ts": jiti,
442
- ".mjs": jiti
443
- }
444
- }).search(options.cwd);
445
- if (!result) {
446
- throw new Error(`No TailwindCSS Config found in: ${options.cwd}`);
447
- }
448
- config = result.filepath;
449
- }
450
- return await postcss([
451
- require("tailwindcss")({
452
- config
453
- })
454
- ]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
455
- from: void 0
456
- });
457
- }
458
-
459
- class TailwindcssPatcher {
460
- constructor(options = {}) {
461
- this.rawOptions = options;
462
- this.cacheOptions = getCacheOptions(options.cache);
463
- this.patchOptions = getPatchOptions(options.patch);
464
- this.patch = createPatch(this.patchOptions);
465
- this.cacheManager = new CacheManager(this.cacheOptions);
466
- }
467
- getPkgEntry(basedir) {
468
- return getTailwindcssEntry(basedir);
469
- }
470
- setCache(set) {
471
- if (this.cacheOptions.enable) {
472
- return this.cacheManager.write(set);
473
- }
474
- }
475
- getCache() {
476
- return this.cacheManager.read();
477
- }
478
- /**
479
- * @description 在多个 tailwindcss 上下文时,这个方法将被执行多次,所以策略上应该使用 append
480
- * 详见 taro weapp-tailwindcss 独立分包
481
- * @param basedir
482
- * @returns
483
- */
484
- getClassSet(options) {
485
- const { basedir, cacheStrategy = this.cacheOptions.strategy ?? "merge", removeUniversalSelector = true } = options ?? {};
486
- const set = getClassCacheSet(basedir, {
487
- removeUniversalSelector
488
- });
489
- if (cacheStrategy === "overwrite") {
490
- set.size > 0 && this.setCache(set);
491
- } else if (cacheStrategy === "merge") {
492
- const cacheSet = this.getCache();
493
- if (cacheSet) {
494
- for (const x of cacheSet) {
495
- set.add(x);
496
- }
497
- }
498
- this.setCache(set);
499
- }
500
- return set;
501
- }
502
- getContexts(basedir) {
503
- return getContexts(basedir);
504
- }
505
- async extract(options) {
506
- const { output, tailwindcss } = options ?? {};
507
- if (output && tailwindcss) {
508
- const { removeUniversalSelector, filename, loose } = output;
509
- await processTailwindcss(tailwindcss);
510
- const set = this.getClassSet({
511
- removeUniversalSelector
512
- });
513
- if (filename) {
514
- await ensureDir(dirname(filename));
515
- const classList = [...set];
516
- await fs$1.writeFile(filename, JSON.stringify(classList, null, loose ? 2 : void 0), "utf8");
517
- return filename;
518
- }
519
- }
520
- }
521
- }
522
-
523
- export { CacheManager, TailwindcssPatcher, createPatch, ensureDir, ensureFileContent, getCacheOptions, getClassCacheSet, getClassCaches, getContexts, getInstalledPkgJsonPath, getPatchOptions, getTailwindcssEntry, inspectPostcssPlugin, inspectProcessTailwindFeaturesReturnContext, internalPatch, monkeyPatchForExposingContext, requireResolve };
24
+ // src/index.ts
25
+ var src_exports = {};
26
+ __export(src_exports, {
27
+ CacheManager: () => CacheManager,
28
+ TailwindcssPatcher: () => TailwindcssPatcher,
29
+ createPatch: () => createPatch,
30
+ ensureDir: () => ensureDir,
31
+ ensureFileContent: () => ensureFileContent,
32
+ getCacheOptions: () => getCacheOptions,
33
+ getClassCacheSet: () => getClassCacheSet,
34
+ getClassCaches: () => getClassCaches,
35
+ getContexts: () => getContexts,
36
+ getInstalledPkgJsonPath: () => getInstalledPkgJsonPath,
37
+ getPatchOptions: () => getPatchOptions,
38
+ getTailwindcssEntry: () => getTailwindcssEntry,
39
+ inspectPostcssPlugin: () => inspectPostcssPlugin,
40
+ inspectProcessTailwindFeaturesReturnContext: () => inspectProcessTailwindFeaturesReturnContext,
41
+ internalPatch: () => internalPatch,
42
+ monkeyPatchForExposingContext: () => monkeyPatchForExposingContext,
43
+ requireResolve: () => requireResolve
44
+ });
45
+ __reExport(src_exports, core_exports);
46
+ export {
47
+ CacheManager,
48
+ TailwindcssPatcher,
49
+ createPatch,
50
+ ensureDir,
51
+ ensureFileContent,
52
+ getCacheOptions,
53
+ getClassCacheSet,
54
+ getClassCaches,
55
+ getContexts,
56
+ getInstalledPkgJsonPath,
57
+ getPatchOptions,
58
+ getTailwindcssEntry,
59
+ inspectPostcssPlugin,
60
+ inspectProcessTailwindFeaturesReturnContext,
61
+ internalPatch,
62
+ monkeyPatchForExposingContext,
63
+ requireResolve
64
+ };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "tailwindcss-patch",
3
- "version": "2.0.4",
3
+ "version": "2.0.5-alpha.0",
4
4
  "description": "patch tailwindcss for exposing context and extract classes",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
8
8
  "import": "./dist/index.mjs",
9
- "require": "./dist/index.cjs"
9
+ "require": "./dist/index.js"
10
10
  }
11
11
  },
12
12
  "typesVersions": {
@@ -17,7 +17,7 @@
17
17
  ]
18
18
  }
19
19
  },
20
- "main": "./dist/index.cjs",
20
+ "main": "./dist/index.js",
21
21
  "module": "./dist/index.mjs",
22
22
  "types": "./dist/index.d.ts",
23
23
  "bin": {
@@ -81,7 +81,7 @@
81
81
  "test": "test"
82
82
  },
83
83
  "scripts": {
84
- "build": "unbuild",
84
+ "build": "tsup",
85
85
  "test": "vitest run --coverage.enabled",
86
86
  "test:dev": "vitest",
87
87
  "patch": "node bin/tw-patch.js install"
package/dist/cli.cjs DELETED
@@ -1,46 +0,0 @@
1
- 'use strict';
2
-
3
- const cac = require('cac');
4
- const index = require('./index.cjs');
5
- require('node:path');
6
- require('node:fs');
7
- require('node:fs/promises');
8
- require('resolve');
9
- require('@babel/types');
10
- require('@babel/generator');
11
- require('@babel/traverse');
12
- require('@babel/parser');
13
- const config = require('@tailwindcss-mangle/config');
14
- require('semver');
15
- require('postcss');
16
- require('lilconfig');
17
- require('jiti');
18
-
19
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
20
-
21
- const cac__default = /*#__PURE__*/_interopDefaultCompat(cac);
22
-
23
- function init() {
24
- const cwd = process.cwd();
25
- return config.initConfig(cwd);
26
- }
27
- const cli = cac__default();
28
- cli.command("install", "patch install").action(() => {
29
- const opt = index.getPatchOptions();
30
- const patch = index.createPatch(opt);
31
- patch();
32
- });
33
- cli.command("init").action(async () => {
34
- await init();
35
- console.log(`\u2728 ${config.configName}.config.ts initialized!`);
36
- });
37
- cli.command("extract").action(async () => {
38
- const { config: config$1 } = await config.getConfig();
39
- if (config$1) {
40
- const twPatcher = new index.TailwindcssPatcher();
41
- const p = await twPatcher.extract(config$1.patch);
42
- console.log("\u2728 tailwindcss-patch extract success! file path:\n" + p);
43
- }
44
- });
45
- cli.help();
46
- cli.parse();