tailwindcss-patch 1.2.7 → 2.0.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/README.md CHANGED
@@ -1,6 +1,16 @@
1
1
  # tailwindcss-patch
2
2
 
3
- get tailwindcss context at runtime!
3
+ get tailwindcss context at runtime ! extract all class to json file!
4
+
5
+ - [tailwindcss-patch](#tailwindcss-patch)
6
+ - [Setup](#setup)
7
+ - [Usage](#usage)
8
+ - [Cli](#cli)
9
+ - [Init Config File](#init-config-file)
10
+ - [extract all class into a json](#extract-all-class-into-a-json)
11
+ - [Nodejs](#nodejs)
12
+ - [Migration form v1 to v2](#migration-form-v1-to-v2)
13
+ - [Notice](#notice)
4
14
 
5
15
  ## Setup
6
16
 
@@ -13,7 +23,7 @@ get tailwindcss context at runtime!
13
23
  2. Patch tailwindcss
14
24
 
15
25
  ```sh
16
- npx tw-patch
26
+ npx tw-patch install
17
27
  ```
18
28
 
19
29
  3. Add `prepare` script (keeps patch persisted after npm install)
@@ -24,19 +34,52 @@ npx tw-patch
24
34
  {
25
35
  /* ... */
26
36
  "scripts": {
27
- "prepare": "tw-patch"
37
+ "prepare": "tw-patch install"
28
38
  }
29
39
  }
30
40
  ```
31
41
 
32
42
  ## Usage
33
43
 
44
+ ## Cli
45
+
46
+ ### Init Config File
47
+
48
+ ```sh
49
+ tw-patch init
50
+ ```
51
+
52
+ Then there will be a ts file called `tailwindcss-patch.config.ts` exist in your `cwd`.
53
+
54
+ ### extract all class into a json
55
+
56
+ ```sh
57
+ tw-patch extract
58
+ ```
59
+
60
+ default there will be a json in `.tw-patch/tw-class-list.json` in your project.
61
+
62
+ you can custom this behavior by config `tailwindcss-patch.config.ts`
63
+
64
+ ### Nodejs
65
+
34
66
  ```js
35
- import { getContexts, getClassCacheSet } from 'tailwindcss-patch'
67
+ import { TailwindcssPatcher } from 'tailwindcss-patch'
68
+
69
+ const twPatcher = new TailwindcssPatcher(/* options */)
36
70
  // get all contexts at runtime
37
- getContexts()
71
+ twPatcher.getContexts()
38
72
  // get all class generated by tailwindcss utilities
39
- getClassCacheSet()
73
+ twPatcher.getClassCacheSet()
74
+ ```
75
+
76
+ ## Migration form v1 to v2
77
+
78
+ ```diff
79
+ {
80
+ - "tw-patch"
81
+ + "tw-patch install"
82
+ }
40
83
  ```
41
84
 
42
85
  ## Notice
package/bin/tw-patch.js CHANGED
@@ -1,7 +1,7 @@
1
- #!/usr/bin/env node
2
- const fs = require('fs')
3
- const path = require('path')
4
- const cliPath = path.resolve(__dirname, '../dist/cli.js')
5
- if (fs.existsSync(cliPath)) {
6
- require(cliPath)
7
- }
1
+ #!/usr/bin/env node
2
+ const fs = require('node:fs')
3
+ const path = require('node:path')
4
+ const cliPath = path.resolve(__dirname, '../dist/cli.cjs')
5
+ if (fs.existsSync(cliPath)) {
6
+ require(cliPath)
7
+ }
package/dist/cli.cjs ADDED
@@ -0,0 +1,118 @@
1
+ 'use strict';
2
+
3
+ const index = require('./index.cjs');
4
+ const path = require('node:path');
5
+ require('node:fs');
6
+ const fs = require('node:fs/promises');
7
+ require('resolve');
8
+ require('@babel/types');
9
+ require('@babel/generator');
10
+ require('@babel/traverse');
11
+ require('@babel/parser');
12
+ const cac = require('cac');
13
+ require('semver');
14
+ require('postcss');
15
+ require('postcss-load-config');
16
+ require('c12');
17
+
18
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
19
+
20
+ const path__default = /*#__PURE__*/_interopDefaultCompat(path);
21
+ const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
22
+ const cac__default = /*#__PURE__*/_interopDefaultCompat(cac);
23
+
24
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
25
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
26
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
28
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
29
+ const dedent = createDedent({});
30
+ function createDedent(options) {
31
+ dedent.withOptions = newOptions => createDedent(_objectSpread(_objectSpread({}, options), newOptions));
32
+ return dedent;
33
+ function dedent(strings, ...values) {
34
+ const raw = typeof strings === "string" ? [strings] : strings.raw;
35
+ const {
36
+ escapeSpecialCharacters = Array.isArray(strings)
37
+ } = options;
38
+
39
+ // first, perform interpolation
40
+ let result = "";
41
+ for (let i = 0; i < raw.length; i++) {
42
+ let next = raw[i];
43
+ if (escapeSpecialCharacters) {
44
+ // handle escaped newlines, backticks, and interpolation characters
45
+ next = next.replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`").replace(/\\\$/g, "$").replace(/\\{/g, "{");
46
+ }
47
+ result += next;
48
+ if (i < values.length) {
49
+ // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
50
+ result += values[i];
51
+ }
52
+ }
53
+
54
+ // now strip indentation
55
+ const lines = result.split("\n");
56
+ let mindent = null;
57
+ for (const l of lines) {
58
+ const m = l.match(/^(\s+)\S+/);
59
+ if (m) {
60
+ const indent = m[1].length;
61
+ if (!mindent) {
62
+ // this is the first indented line
63
+ mindent = indent;
64
+ } else {
65
+ mindent = Math.min(mindent, indent);
66
+ }
67
+ }
68
+ }
69
+ if (mindent !== null) {
70
+ const m = mindent; // appease TypeScript
71
+ result = lines
72
+ // https://github.com/typescript-eslint/typescript-eslint/issues/7140
73
+ // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
74
+ .map(l => l[0] === " " || l[0] === "\t" ? l.slice(m) : l).join("\n");
75
+ }
76
+ return result
77
+ // dedent eats leading and trailing whitespace too
78
+ .trim()
79
+ // handle escaped newlines at the end to ensure they don't get stripped too
80
+ .replace(/\\n/g, "\n");
81
+ }
82
+ }
83
+
84
+ function init() {
85
+ const cwd = process.cwd();
86
+ return fs__default.writeFile(
87
+ path__default.resolve(cwd, "tailwindcss-patch.config.ts"),
88
+ dedent`
89
+ import { defineConfig } from 'tailwindcss-patch'
90
+
91
+ export default defineConfig({})
92
+ `,
93
+ "utf8"
94
+ );
95
+ }
96
+ const cli = cac__default();
97
+ cli.command("install", "patch install").action(() => {
98
+ const opt = index.getPatchOptions();
99
+ const patch = index.createPatch(opt);
100
+ patch();
101
+ });
102
+ cli.command("init").action(async () => {
103
+ await init();
104
+ console.log("\u2728 tailwindcss-patch config initialized!");
105
+ });
106
+ cli.command("extract").action(async () => {
107
+ const { config } = await index.getConfig();
108
+ if (config?.output?.filename) {
109
+ const twPatcher = new index.TailwindcssPatcher();
110
+ await twPatcher.extract({
111
+ filename: config.output.filename,
112
+ configDir: config.postcss?.configDir,
113
+ loose: config.postcss?.loose
114
+ });
115
+ }
116
+ });
117
+ cli.help();
118
+ cli.parse();
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/cli.mjs ADDED
@@ -0,0 +1,110 @@
1
+ import { getPatchOptions, getConfig, TailwindcssPatcher, createPatch } from './index.mjs';
2
+ import path from 'node:path';
3
+ import 'node:fs';
4
+ import fs from 'node:fs/promises';
5
+ import 'resolve';
6
+ import '@babel/types';
7
+ import '@babel/generator';
8
+ import '@babel/traverse';
9
+ import '@babel/parser';
10
+ import cac from 'cac';
11
+ import 'semver';
12
+ import 'postcss';
13
+ import 'postcss-load-config';
14
+ import 'c12';
15
+
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
17
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
18
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
20
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
21
+ const dedent = createDedent({});
22
+ function createDedent(options) {
23
+ dedent.withOptions = newOptions => createDedent(_objectSpread(_objectSpread({}, options), newOptions));
24
+ return dedent;
25
+ function dedent(strings, ...values) {
26
+ const raw = typeof strings === "string" ? [strings] : strings.raw;
27
+ const {
28
+ escapeSpecialCharacters = Array.isArray(strings)
29
+ } = options;
30
+
31
+ // first, perform interpolation
32
+ let result = "";
33
+ for (let i = 0; i < raw.length; i++) {
34
+ let next = raw[i];
35
+ if (escapeSpecialCharacters) {
36
+ // handle escaped newlines, backticks, and interpolation characters
37
+ next = next.replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`").replace(/\\\$/g, "$").replace(/\\{/g, "{");
38
+ }
39
+ result += next;
40
+ if (i < values.length) {
41
+ // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
42
+ result += values[i];
43
+ }
44
+ }
45
+
46
+ // now strip indentation
47
+ const lines = result.split("\n");
48
+ let mindent = null;
49
+ for (const l of lines) {
50
+ const m = l.match(/^(\s+)\S+/);
51
+ if (m) {
52
+ const indent = m[1].length;
53
+ if (!mindent) {
54
+ // this is the first indented line
55
+ mindent = indent;
56
+ } else {
57
+ mindent = Math.min(mindent, indent);
58
+ }
59
+ }
60
+ }
61
+ if (mindent !== null) {
62
+ const m = mindent; // appease TypeScript
63
+ result = lines
64
+ // https://github.com/typescript-eslint/typescript-eslint/issues/7140
65
+ // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
66
+ .map(l => l[0] === " " || l[0] === "\t" ? l.slice(m) : l).join("\n");
67
+ }
68
+ return result
69
+ // dedent eats leading and trailing whitespace too
70
+ .trim()
71
+ // handle escaped newlines at the end to ensure they don't get stripped too
72
+ .replace(/\\n/g, "\n");
73
+ }
74
+ }
75
+
76
+ function init() {
77
+ const cwd = process.cwd();
78
+ return fs.writeFile(
79
+ path.resolve(cwd, "tailwindcss-patch.config.ts"),
80
+ dedent`
81
+ import { defineConfig } from 'tailwindcss-patch'
82
+
83
+ export default defineConfig({})
84
+ `,
85
+ "utf8"
86
+ );
87
+ }
88
+ const cli = cac();
89
+ cli.command("install", "patch install").action(() => {
90
+ const opt = getPatchOptions();
91
+ const patch = createPatch(opt);
92
+ patch();
93
+ });
94
+ cli.command("init").action(async () => {
95
+ await init();
96
+ console.log("\u2728 tailwindcss-patch config initialized!");
97
+ });
98
+ cli.command("extract").action(async () => {
99
+ const { config } = await getConfig();
100
+ if (config?.output?.filename) {
101
+ const twPatcher = new TailwindcssPatcher();
102
+ await twPatcher.extract({
103
+ filename: config.output.filename,
104
+ configDir: config.postcss?.configDir,
105
+ loose: config.postcss?.loose
106
+ });
107
+ }
108
+ });
109
+ cli.help();
110
+ cli.parse();