@chakra-ui/cli
Advanced tools
Comparing version 1.3.1 to 1.4.0
# @chakra-ui/cli | ||
## 1.4.0 | ||
### Minor Changes | ||
- [`fe2557584`](https://github.com/chakra-ui/chakra-ui/commit/fe255758437b04740e1a0d8c8549afefe7dc71ce) | ||
[#4067](https://github.com/chakra-ui/chakra-ui/pull/4067) Thanks | ||
[@jrolfs](https://github.com/jrolfs)! - The `tokens` command now supports | ||
generating theme token type definitions from a Chakra UI theme published as a | ||
package: | ||
```sh | ||
npx @chakra-ui/cli tokens <@your-org/chakra-theme-package> | ||
``` | ||
A published theme package should export a theme object as either the `default` | ||
export or an export named `theme`. | ||
```jsx | ||
// chakra-theme-package/src/index.js | ||
import { extendTheme } from "@chakra-ui/react" | ||
const theme = extendTheme({}) | ||
// as default export | ||
export default theme | ||
// as named export | ||
export { theme } | ||
``` | ||
## 1.3.1 | ||
@@ -4,0 +33,0 @@ |
@@ -7,2 +7,4 @@ "use strict"; | ||
var _fs = _interopRequireDefault(require("fs")); | ||
var _tsNode = require("ts-node"); | ||
@@ -26,15 +28,15 @@ | ||
function readTheme(_x) { | ||
return _readTheme.apply(this, arguments); | ||
var bold = function bold(text) { | ||
return "\x1B[1m" + text + "\x1B[22m"; | ||
}; | ||
function importTheme(_x) { | ||
return _importTheme.apply(this, arguments); | ||
} | ||
/** | ||
* Reads the theme file, generates the typings interface and prints it to stdout | ||
*/ | ||
function _readTheme() { | ||
_readTheme = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(themeFilePath) { | ||
function _importTheme() { | ||
_importTheme = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(path) { | ||
var _module$default; | ||
var absoluteThemePath, module; | ||
var module, theme; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
@@ -44,17 +46,22 @@ while (1) { | ||
case 0: | ||
absoluteThemePath = _path["default"].join(process.cwd(), themeFilePath); | ||
(0, _tsNode.register)({ | ||
project: _path["default"].join(__dirname, "..", "..", "bin", "tsconfig.json"), | ||
dir: _path["default"].basename(absoluteThemePath) | ||
}); | ||
_context.next = 4; | ||
return Promise.resolve("" + absoluteThemePath).then(function (s) { | ||
_context.next = 2; | ||
return Promise.resolve("" + path).then(function (s) { | ||
return _interopRequireWildcard(require(s)); | ||
}); | ||
case 4: | ||
case 2: | ||
module = _context.sent; | ||
return _context.abrupt("return", (_module$default = module["default"]) != null ? _module$default : module.theme); | ||
theme = (_module$default = module["default"]) != null ? _module$default : module.theme; | ||
if (theme) { | ||
_context.next = 6; | ||
break; | ||
} | ||
throw new Error("\n Theme export not found in module: '" + path + "'.\n\n A theme should have a " + bold("default") + " export or a " + bold("theme") + " named export.\n Found the following exports: " + bold(Object.keys(module).join(", ")) + "\n "); | ||
case 6: | ||
return _context.abrupt("return", theme); | ||
case 7: | ||
case "end": | ||
@@ -66,5 +73,55 @@ return _context.stop(); | ||
})); | ||
return _importTheme.apply(this, arguments); | ||
} | ||
function readTheme(_x2) { | ||
return _readTheme.apply(this, arguments); | ||
} | ||
/** | ||
* Reads the theme file, generates the typings interface and prints it to stdout | ||
*/ | ||
function _readTheme() { | ||
_readTheme = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(themeFilePath) { | ||
var cwd, absoluteThemePath; | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
cwd = process.cwd(); | ||
absoluteThemePath = _path["default"].join(cwd, themeFilePath); | ||
(0, _tsNode.register)({ | ||
project: _path["default"].join(__dirname, "..", "..", "bin", "tsconfig.json") | ||
}); | ||
_context2.prev = 3; | ||
_context2.next = 6; | ||
return _fs["default"].promises.stat(absoluteThemePath); | ||
case 6: | ||
return _context2.abrupt("return", importTheme(absoluteThemePath)); | ||
case 9: | ||
_context2.prev = 9; | ||
_context2.t0 = _context2["catch"](3); | ||
_context2.prev = 11; | ||
return _context2.abrupt("return", importTheme(require.resolve(themeFilePath, { | ||
paths: [cwd] | ||
}))); | ||
case 15: | ||
_context2.prev = 15; | ||
_context2.t1 = _context2["catch"](11); | ||
throw new Error("Theme file or package not found \n" + _context2.t0 + " \n" + _context2.t1); | ||
case 18: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, null, [[3, 9], [11, 15]]); | ||
})); | ||
return _readTheme.apply(this, arguments); | ||
} | ||
function run() { | ||
@@ -75,7 +132,7 @@ return _run.apply(this, arguments); | ||
function _run() { | ||
_run = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() { | ||
_run = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() { | ||
var themeFile, theme, template; | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
return regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
@@ -85,3 +142,3 @@ themeFile = process.argv[2]; | ||
if (themeFile) { | ||
_context2.next = 3; | ||
_context3.next = 3; | ||
break; | ||
@@ -93,10 +150,10 @@ } | ||
case 3: | ||
_context2.next = 5; | ||
_context3.next = 5; | ||
return readTheme(themeFile); | ||
case 5: | ||
theme = _context2.sent; | ||
theme = _context3.sent; | ||
if ((0, _utils.isObject)(theme)) { | ||
_context2.next = 8; | ||
_context3.next = 8; | ||
break; | ||
@@ -108,3 +165,3 @@ } | ||
case 8: | ||
_context2.next = 10; | ||
_context3.next = 10; | ||
return (0, _createThemeTypingsInterface.createThemeTypingsInterface)(theme, { | ||
@@ -115,3 +172,3 @@ config: _config.themeKeyConfiguration | ||
case 10: | ||
template = _context2.sent; | ||
template = _context3.sent; | ||
@@ -126,6 +183,6 @@ if (process.send) { | ||
case "end": | ||
return _context2.stop(); | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee2); | ||
}, _callee3); | ||
})); | ||
@@ -132,0 +189,0 @@ return _run.apply(this, arguments); |
{ | ||
"name": "@chakra-ui/cli", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "Generate theme typings for autocomplete", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -11,3 +11,9 @@ # @chakra-ui/cli | ||
or | ||
```sh | ||
npx @chakra-ui/cli tokens <@your-org/chakra-theme-package> | ||
``` | ||
```sh | ||
$ npx @chakra-ui/cli --help | ||
@@ -14,0 +20,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
74801
804
43
5