@modern-js/plugin-tailwindcss 1.4.0 → 1.5.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 +41 -0
- package/dist/js/modern/cli.js +120 -0
- package/dist/js/modern/design-token/cli/index.js +127 -0
- package/dist/js/modern/design-token/index.js +2 -0
- package/dist/js/modern/design-token/postcss-plugin/index.js +18 -0
- package/dist/js/modern/design-token/runtime/index.js +3 -0
- package/dist/js/modern/design-token/runtime/plugin.js +62 -0
- package/dist/js/modern/index.js +1 -0
- package/dist/js/modern/tailwind.js +43 -0
- package/dist/js/modern/utils.js +34 -0
- package/dist/js/node/cli.js +1 -1
- package/dist/js/node/design-token/cli/index.js +137 -0
- package/dist/js/node/design-token/index.js +30 -0
- package/dist/js/node/design-token/postcss-plugin/index.js +27 -0
- package/dist/js/node/design-token/runtime/index.js +28 -0
- package/dist/js/node/design-token/runtime/plugin.js +86 -0
- package/dist/js/treeshaking/cli.js +135 -0
- package/dist/js/treeshaking/design-token/cli/index.js +106 -0
- package/dist/js/treeshaking/design-token/index.js +2 -0
- package/dist/js/treeshaking/design-token/postcss-plugin/index.js +30 -0
- package/dist/js/treeshaking/design-token/runtime/index.js +3 -0
- package/dist/js/treeshaking/design-token/runtime/plugin.js +62 -0
- package/dist/js/treeshaking/index.js +1 -0
- package/dist/js/treeshaking/tailwind.js +51 -0
- package/dist/js/treeshaking/utils.js +56 -0
- package/dist/types/design-token/cli/index.d.ts +5 -0
- package/dist/types/design-token/index.d.ts +2 -0
- package/dist/types/design-token/postcss-plugin/index.d.ts +12 -0
- package/dist/types/design-token/runtime/index.d.ts +3 -0
- package/dist/types/design-token/runtime/plugin.d.ts +12 -0
- package/package.json +29 -8
@@ -0,0 +1,28 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
var _exportNames = {};
|
7
|
+
exports.default = void 0;
|
8
|
+
|
9
|
+
var _plugin = _interopRequireWildcard(require("./plugin"));
|
10
|
+
|
11
|
+
Object.keys(_plugin).forEach(function (key) {
|
12
|
+
if (key === "default" || key === "__esModule") return;
|
13
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
14
|
+
if (key in exports && exports[key] === _plugin[key]) return;
|
15
|
+
Object.defineProperty(exports, key, {
|
16
|
+
enumerable: true,
|
17
|
+
get: function () {
|
18
|
+
return _plugin[key];
|
19
|
+
}
|
20
|
+
});
|
21
|
+
});
|
22
|
+
|
23
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
24
|
+
|
25
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
26
|
+
|
27
|
+
var _default = _plugin.default;
|
28
|
+
exports.default = _default;
|
@@ -0,0 +1,86 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useDesignTokens = exports.default = exports.DesignTokenContext = void 0;
|
7
|
+
|
8
|
+
var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
|
9
|
+
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
11
|
+
|
12
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
13
|
+
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
15
|
+
|
16
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
17
|
+
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
|
+
|
20
|
+
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; }
|
21
|
+
|
22
|
+
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; }
|
23
|
+
|
24
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
25
|
+
|
26
|
+
const DesignTokenContext = /*#__PURE__*/_react.default.createContext({});
|
27
|
+
|
28
|
+
exports.DesignTokenContext = DesignTokenContext;
|
29
|
+
|
30
|
+
const useDesignTokens = () => (0, _react.useContext)(DesignTokenContext);
|
31
|
+
|
32
|
+
exports.useDesignTokens = useDesignTokens;
|
33
|
+
|
34
|
+
var _default = (options = {}) => ({
|
35
|
+
name: '@modern-js/plugin-design-token',
|
36
|
+
setup: () => ({
|
37
|
+
hoc({
|
38
|
+
App
|
39
|
+
}, next) {
|
40
|
+
const DesignTokenAppWrapper = props => {
|
41
|
+
const {
|
42
|
+
token = {},
|
43
|
+
useStyledComponentsThemeProvider = false,
|
44
|
+
useDesignTokenContext = false
|
45
|
+
} = options;
|
46
|
+
|
47
|
+
if (useStyledComponentsThemeProvider && useDesignTokenContext) {
|
48
|
+
const {
|
49
|
+
ThemeProvider
|
50
|
+
} = require('@modern-js/runtime/styled');
|
51
|
+
|
52
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(ThemeProvider, {
|
53
|
+
theme: token,
|
54
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(DesignTokenContext.Provider, {
|
55
|
+
value: token,
|
56
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(App, _objectSpread({}, props))
|
57
|
+
})
|
58
|
+
});
|
59
|
+
} else if (useStyledComponentsThemeProvider) {
|
60
|
+
const {
|
61
|
+
ThemeProvider
|
62
|
+
} = require('@modern-js/runtime/styled');
|
63
|
+
|
64
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(ThemeProvider, {
|
65
|
+
theme: token,
|
66
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(App, _objectSpread({}, props))
|
67
|
+
});
|
68
|
+
} else if (useDesignTokenContext) {
|
69
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(DesignTokenContext.Provider, {
|
70
|
+
value: token,
|
71
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(App, _objectSpread({}, props))
|
72
|
+
});
|
73
|
+
} else {
|
74
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(App, _objectSpread({}, props));
|
75
|
+
}
|
76
|
+
};
|
77
|
+
|
78
|
+
return next({
|
79
|
+
App: (0, _hoistNonReactStatics.default)(DesignTokenAppWrapper, App)
|
80
|
+
});
|
81
|
+
}
|
82
|
+
|
83
|
+
})
|
84
|
+
});
|
85
|
+
|
86
|
+
exports.default = _default;
|
@@ -0,0 +1,135 @@
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
3
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
4
|
+
import path from 'path';
|
5
|
+
import { PLUGIN_SCHEMAS, fs, CONFIG_CACHE_DIR, globby, nanoid, slash } from '@modern-js/utils';
|
6
|
+
import DesignTokenPlugin from "./design-token/cli";
|
7
|
+
import { getTailwindConfig } from "./tailwind";
|
8
|
+
import { template, checkTwinMacroNotExist } from "./utils";
|
9
|
+
var supportCssInJsLibrary = 'styled-components';
|
10
|
+
export var getRandomTwConfigFileName = function getRandomTwConfigFileName(internalDirectory) {
|
11
|
+
return slash(path.join(internalDirectory, "tailwind.config.".concat(Date.now(), ".").concat(nanoid(), ".js")));
|
12
|
+
};
|
13
|
+
export default (function () {
|
14
|
+
return {
|
15
|
+
name: '@modern-js/plugin-tailwindcss',
|
16
|
+
// support designSystem.supportStyledComponents
|
17
|
+
usePlugins: [DesignTokenPlugin()],
|
18
|
+
setup: function () {
|
19
|
+
var _setup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(api) {
|
20
|
+
var _api$useAppContext, appDirectory, internalDirectory, internalTwConfigPath, notHaveTwinMacro;
|
21
|
+
|
22
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
23
|
+
while (1) {
|
24
|
+
switch (_context.prev = _context.next) {
|
25
|
+
case 0:
|
26
|
+
_api$useAppContext = api.useAppContext(), appDirectory = _api$useAppContext.appDirectory, internalDirectory = _api$useAppContext.internalDirectory;
|
27
|
+
internalTwConfigPath = ''; // When reinstalling dependencies, most of the time the project will be restarted
|
28
|
+
|
29
|
+
_context.next = 4;
|
30
|
+
return checkTwinMacroNotExist(appDirectory);
|
31
|
+
|
32
|
+
case 4:
|
33
|
+
notHaveTwinMacro = _context.sent;
|
34
|
+
return _context.abrupt("return", {
|
35
|
+
prepare: function prepare() {
|
36
|
+
if (notHaveTwinMacro) {
|
37
|
+
return;
|
38
|
+
}
|
39
|
+
|
40
|
+
internalTwConfigPath = getRandomTwConfigFileName(internalDirectory);
|
41
|
+
var globPattern = slash(path.join(appDirectory, CONFIG_CACHE_DIR, '*.cjs'));
|
42
|
+
var files = globby.sync(globPattern, {
|
43
|
+
absolute: true
|
44
|
+
});
|
45
|
+
|
46
|
+
if (files.length > 0) {
|
47
|
+
fs.writeFileSync(internalTwConfigPath, template(files[files.length - 1]), 'utf-8');
|
48
|
+
}
|
49
|
+
},
|
50
|
+
validateSchema: function validateSchema() {
|
51
|
+
return PLUGIN_SCHEMAS['@modern-js/plugin-tailwindcss'];
|
52
|
+
},
|
53
|
+
config: function config() {
|
54
|
+
return {
|
55
|
+
tools: {
|
56
|
+
// TODO: Add interface about postcss config
|
57
|
+
// TODO: In module project, also is called, but should not be called.
|
58
|
+
postcss: function postcss(config) {
|
59
|
+
var modernConfig = api.useResolvedConfigContext();
|
60
|
+
var tailwindConfig = getTailwindConfig(modernConfig, {
|
61
|
+
pureConfig: {
|
62
|
+
content: ['./config/html/**/*.html', './config/html/**/*.ejs', './config/html/**/*.hbs', './src/**/*.js', './src/**/*.jsx', './src/**/*.ts', './src/**/*.tsx', // about storybook
|
63
|
+
'./storybook/**/*', './styles/**/*.less', './styles/**/*.css', './styles/**/*.sass', './styles/**/*.scss']
|
64
|
+
}
|
65
|
+
});
|
66
|
+
|
67
|
+
if (Array.isArray(config.postcssOptions.plugins)) {
|
68
|
+
config.postcssOptions.plugins.push(require('tailwindcss')(tailwindConfig));
|
69
|
+
} else {
|
70
|
+
config.postcssOptions.plugins = [require('tailwindcss')(tailwindConfig)];
|
71
|
+
}
|
72
|
+
},
|
73
|
+
babel: function babel(config) {
|
74
|
+
var _config$plugins;
|
75
|
+
|
76
|
+
if (notHaveTwinMacro) {
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
|
80
|
+
var twinConfig = {
|
81
|
+
twin: {
|
82
|
+
preset: supportCssInJsLibrary,
|
83
|
+
config: internalTwConfigPath
|
84
|
+
}
|
85
|
+
};
|
86
|
+
(_config$plugins = config.plugins) === null || _config$plugins === void 0 ? void 0 : _config$plugins.some(function (plugin) {
|
87
|
+
if (Array.isArray(plugin) && plugin[0]) {
|
88
|
+
var pluginTarget = plugin[0];
|
89
|
+
var pluginOptions = plugin[1];
|
90
|
+
|
91
|
+
if (typeof pluginTarget === 'string' && // TODO: use babel chain
|
92
|
+
slash(pluginTarget).includes('compiled/babel-plugin-macros')) {
|
93
|
+
if (pluginOptions) {
|
94
|
+
pluginOptions = _objectSpread(_objectSpread({}, pluginOptions), twinConfig);
|
95
|
+
} else {
|
96
|
+
plugin.push(twinConfig);
|
97
|
+
}
|
98
|
+
|
99
|
+
return true;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
return false;
|
104
|
+
});
|
105
|
+
}
|
106
|
+
}
|
107
|
+
};
|
108
|
+
},
|
109
|
+
moduleTailwindConfig: function moduleTailwindConfig() {
|
110
|
+
var modernConfig = api.useResolvedConfigContext();
|
111
|
+
var tailwindConfig = getTailwindConfig(modernConfig, {
|
112
|
+
pureConfig: {
|
113
|
+
content: ['./src/**/*.js', './src/**/*.jsx', './src/**/*.ts', './src/**/*.tsx', './src/**/*.less', './src/**/*.css', './src/**/*.sass', './src/**/*.scss', './styles/**/*.less', './styles/**/*.css', './styles/**/*.sass', './styles/**/*.scss']
|
114
|
+
}
|
115
|
+
});
|
116
|
+
return require('tailwindcss')(tailwindConfig);
|
117
|
+
}
|
118
|
+
});
|
119
|
+
|
120
|
+
case 6:
|
121
|
+
case "end":
|
122
|
+
return _context.stop();
|
123
|
+
}
|
124
|
+
}
|
125
|
+
}, _callee);
|
126
|
+
}));
|
127
|
+
|
128
|
+
function setup(_x) {
|
129
|
+
return _setup.apply(this, arguments);
|
130
|
+
}
|
131
|
+
|
132
|
+
return setup;
|
133
|
+
}()
|
134
|
+
};
|
135
|
+
});
|
@@ -0,0 +1,106 @@
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
3
|
+
import { lazyImport, PLUGIN_SCHEMAS, createRuntimeExportsUtils } from '@modern-js/utils';
|
4
|
+
export default (function () {
|
5
|
+
return {
|
6
|
+
name: '@modern-js/plugin-design-token',
|
7
|
+
setup: function setup(api) {
|
8
|
+
var pluginsExportsUtils;
|
9
|
+
var resolveConfig = lazyImport('tailwindcss/resolveConfig', require);
|
10
|
+
var PLUGIN_IDENTIFIER = 'designToken';
|
11
|
+
|
12
|
+
var getDesignTokens = function getDesignTokens(userConfig) {
|
13
|
+
var _ref = userConfig,
|
14
|
+
designSystem = _ref.source.designSystem; // TODO: Type to be filled
|
15
|
+
|
16
|
+
var tailwindcssConfig = {};
|
17
|
+
tailwindcssConfig.theme = designSystem ? _objectSpread({}, designSystem) : {}; // not use default design token when designToken.defaultTheme is false or theme is false
|
18
|
+
|
19
|
+
if (!designSystem) {
|
20
|
+
tailwindcssConfig.presets = [];
|
21
|
+
} // when only designSystem exist, need remove supportStyledComponents
|
22
|
+
|
23
|
+
|
24
|
+
if (designSystem) {
|
25
|
+
delete tailwindcssConfig.theme.supportStyledComponents;
|
26
|
+
}
|
27
|
+
|
28
|
+
return resolveConfig(tailwindcssConfig).theme || {};
|
29
|
+
};
|
30
|
+
|
31
|
+
return {
|
32
|
+
config: function config() {
|
33
|
+
var appContext = api.useAppContext();
|
34
|
+
pluginsExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, 'plugins');
|
35
|
+
return {
|
36
|
+
source: {
|
37
|
+
alias: {
|
38
|
+
'@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
|
39
|
+
}
|
40
|
+
},
|
41
|
+
tools: {// TODO: support less、scss、css vars
|
42
|
+
// less: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR166
|
43
|
+
// sass: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR229
|
44
|
+
// postcss: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR281
|
45
|
+
}
|
46
|
+
};
|
47
|
+
},
|
48
|
+
modifyEntryImports: function modifyEntryImports(_ref2) {
|
49
|
+
var entrypoint = _ref2.entrypoint,
|
50
|
+
imports = _ref2.imports;
|
51
|
+
var userConfig = api.useResolvedConfigContext();
|
52
|
+
var designSystem = userConfig.source.designSystem;
|
53
|
+
|
54
|
+
if (_typeof(designSystem) === 'object' && designSystem.supportStyledComponents) {
|
55
|
+
var designTokens = getDesignTokens(userConfig);
|
56
|
+
imports.push({
|
57
|
+
value: '@modern-js/runtime/plugins',
|
58
|
+
specifiers: [{
|
59
|
+
imported: PLUGIN_IDENTIFIER
|
60
|
+
}],
|
61
|
+
initialize: "\n const designTokens = ".concat(JSON.stringify(designTokens), ";\n ")
|
62
|
+
});
|
63
|
+
}
|
64
|
+
|
65
|
+
return {
|
66
|
+
entrypoint: entrypoint,
|
67
|
+
imports: imports
|
68
|
+
};
|
69
|
+
},
|
70
|
+
modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(_ref3) {
|
71
|
+
var entrypoint = _ref3.entrypoint,
|
72
|
+
plugins = _ref3.plugins;
|
73
|
+
|
74
|
+
var _ref4 = api.useResolvedConfigContext(),
|
75
|
+
designSystem = _ref4.source.designSystem;
|
76
|
+
|
77
|
+
var useSCThemeProvider = true;
|
78
|
+
|
79
|
+
if (designSystem) {
|
80
|
+
// when designSystem exist, designToken.styledComponents`s default value is false.
|
81
|
+
useSCThemeProvider = (designSystem === null || designSystem === void 0 ? void 0 : designSystem.supportStyledComponents) || false;
|
82
|
+
}
|
83
|
+
|
84
|
+
if (_typeof(designSystem) === 'object' && designSystem.supportStyledComponents) {
|
85
|
+
plugins.push({
|
86
|
+
name: PLUGIN_IDENTIFIER,
|
87
|
+
options: "{token: designTokens, useStyledComponentsThemeProvider: ".concat(useSCThemeProvider ? 'true' : 'false', ", useDesignTokenContext: false}")
|
88
|
+
});
|
89
|
+
}
|
90
|
+
|
91
|
+
return {
|
92
|
+
entrypoint: entrypoint,
|
93
|
+
plugins: plugins
|
94
|
+
};
|
95
|
+
},
|
96
|
+
validateSchema: function validateSchema() {
|
97
|
+
// add source.designSystem.supportStyledComponents config
|
98
|
+
return PLUGIN_SCHEMAS['@modern-js/plugin-design-token'];
|
99
|
+
},
|
100
|
+
addRuntimeExports: function addRuntimeExports() {
|
101
|
+
pluginsExportsUtils.addExport("export { default as designToken } from '@modern-js/plugin-tailwindcss/runtime-design-token'");
|
102
|
+
}
|
103
|
+
};
|
104
|
+
}
|
105
|
+
};
|
106
|
+
});
|
@@ -0,0 +1,30 @@
|
|
1
|
+
export default (function () {
|
2
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
3
|
+
_ref$cssVarsHash = _ref.cssVarsHash,
|
4
|
+
cssVarsHash = _ref$cssVarsHash === void 0 ? {} : _ref$cssVarsHash;
|
5
|
+
|
6
|
+
return {
|
7
|
+
postcssPlugin: 'postcss-replace-css-vars',
|
8
|
+
Declaration: function (_Declaration) {
|
9
|
+
function Declaration(_x) {
|
10
|
+
return _Declaration.apply(this, arguments);
|
11
|
+
}
|
12
|
+
|
13
|
+
Declaration.toString = function () {
|
14
|
+
return _Declaration.toString();
|
15
|
+
};
|
16
|
+
|
17
|
+
return Declaration;
|
18
|
+
}(function (decl) {
|
19
|
+
if (decl.value && typeof decl.value === 'string') {
|
20
|
+
decl.value = decl.value.replace(/--\S*/g, function (match) {
|
21
|
+
if (cssVarsHash[match]) {
|
22
|
+
return cssVarsHash[match];
|
23
|
+
}
|
24
|
+
|
25
|
+
return match;
|
26
|
+
});
|
27
|
+
}
|
28
|
+
})
|
29
|
+
};
|
30
|
+
});
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
2
|
+
import hoistNonReactStatics from 'hoist-non-react-statics';
|
3
|
+
import React, { useContext } from 'react';
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
5
|
+
export var DesignTokenContext = /*#__PURE__*/React.createContext({});
|
6
|
+
export var useDesignTokens = function useDesignTokens() {
|
7
|
+
return useContext(DesignTokenContext);
|
8
|
+
};
|
9
|
+
export default (function () {
|
10
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
11
|
+
return {
|
12
|
+
name: '@modern-js/plugin-design-token',
|
13
|
+
setup: function setup() {
|
14
|
+
return {
|
15
|
+
hoc: function hoc(_ref, next) {
|
16
|
+
var App = _ref.App;
|
17
|
+
|
18
|
+
var DesignTokenAppWrapper = function DesignTokenAppWrapper(props) {
|
19
|
+
var _options$token = options.token,
|
20
|
+
token = _options$token === void 0 ? {} : _options$token,
|
21
|
+
_options$useStyledCom = options.useStyledComponentsThemeProvider,
|
22
|
+
useStyledComponentsThemeProvider = _options$useStyledCom === void 0 ? false : _options$useStyledCom,
|
23
|
+
_options$useDesignTok = options.useDesignTokenContext,
|
24
|
+
useDesignTokenContext = _options$useDesignTok === void 0 ? false : _options$useDesignTok;
|
25
|
+
|
26
|
+
if (useStyledComponentsThemeProvider && useDesignTokenContext) {
|
27
|
+
var _require = require('@modern-js/runtime/styled'),
|
28
|
+
ThemeProvider = _require.ThemeProvider;
|
29
|
+
|
30
|
+
return /*#__PURE__*/_jsx(ThemeProvider, {
|
31
|
+
theme: token,
|
32
|
+
children: /*#__PURE__*/_jsx(DesignTokenContext.Provider, {
|
33
|
+
value: token,
|
34
|
+
children: /*#__PURE__*/_jsx(App, _objectSpread({}, props))
|
35
|
+
})
|
36
|
+
});
|
37
|
+
} else if (useStyledComponentsThemeProvider) {
|
38
|
+
var _require2 = require('@modern-js/runtime/styled'),
|
39
|
+
_ThemeProvider = _require2.ThemeProvider;
|
40
|
+
|
41
|
+
return /*#__PURE__*/_jsx(_ThemeProvider, {
|
42
|
+
theme: token,
|
43
|
+
children: /*#__PURE__*/_jsx(App, _objectSpread({}, props))
|
44
|
+
});
|
45
|
+
} else if (useDesignTokenContext) {
|
46
|
+
return /*#__PURE__*/_jsx(DesignTokenContext.Provider, {
|
47
|
+
value: token,
|
48
|
+
children: /*#__PURE__*/_jsx(App, _objectSpread({}, props))
|
49
|
+
});
|
50
|
+
} else {
|
51
|
+
return /*#__PURE__*/_jsx(App, _objectSpread({}, props));
|
52
|
+
}
|
53
|
+
};
|
54
|
+
|
55
|
+
return next({
|
56
|
+
App: hoistNonReactStatics(DesignTokenAppWrapper, App)
|
57
|
+
});
|
58
|
+
}
|
59
|
+
};
|
60
|
+
}
|
61
|
+
};
|
62
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default } from "./cli";
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
2
|
+
import { applyOptionsChain, logger } from '@modern-js/utils';
|
3
|
+
import { merge, cloneDeep } from '@modern-js/utils/lodash';
|
4
|
+
|
5
|
+
var checkIfExistNotAllowKeys = function checkIfExistNotAllowKeys(tailwindConfig) {
|
6
|
+
var notAllowExistKeys = ['theme'];
|
7
|
+
var notAllowKey = '';
|
8
|
+
var ret = Object.keys(tailwindConfig).some(function (key) {
|
9
|
+
return notAllowExistKeys.includes(key) && (notAllowKey = key);
|
10
|
+
});
|
11
|
+
return [ret, notAllowKey];
|
12
|
+
};
|
13
|
+
|
14
|
+
var getPureDesignSystemConfig = function getPureDesignSystemConfig(designSystemConfig) {
|
15
|
+
var pureDesignSystemConfig = cloneDeep(designSystemConfig);
|
16
|
+
delete pureDesignSystemConfig.supportStyledComponents;
|
17
|
+
return pureDesignSystemConfig;
|
18
|
+
};
|
19
|
+
|
20
|
+
var getTailwindConfig = function getTailwindConfig(config) {
|
21
|
+
var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
22
|
+
var purgeConfig = merge({
|
23
|
+
// TODO: how the operating environment is determined
|
24
|
+
enabled: process.env.NODE_ENV === 'production',
|
25
|
+
// TODO: Remove or not
|
26
|
+
layers: ['utilities'],
|
27
|
+
content: []
|
28
|
+
}, option.pureConfig || {});
|
29
|
+
var defaultTailwindConfig = {
|
30
|
+
purge: purgeConfig
|
31
|
+
};
|
32
|
+
var tailwindConfig = applyOptionsChain(defaultTailwindConfig, config.tools.tailwindcss || {});
|
33
|
+
var designSystem = getPureDesignSystemConfig(config.source.designSystem || {});
|
34
|
+
|
35
|
+
var _checkIfExistNotAllow = checkIfExistNotAllowKeys(tailwindConfig),
|
36
|
+
_checkIfExistNotAllow2 = _slicedToArray(_checkIfExistNotAllow, 2),
|
37
|
+
exist = _checkIfExistNotAllow2[0],
|
38
|
+
key = _checkIfExistNotAllow2[1];
|
39
|
+
|
40
|
+
if (exist) {
|
41
|
+
logger.error("should not exist '".concat(key, "' on tools.tailwindcss, please remove it")); // eslint-disable-next-line no-process-exit
|
42
|
+
|
43
|
+
process.exit(0);
|
44
|
+
} // Because there is no default theme configuration
|
45
|
+
|
46
|
+
|
47
|
+
tailwindConfig.theme = designSystem || {};
|
48
|
+
return tailwindConfig;
|
49
|
+
};
|
50
|
+
|
51
|
+
export { getTailwindConfig };
|
@@ -0,0 +1,56 @@
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
2
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
3
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
4
|
+
import path from 'path';
|
5
|
+
import { fs } from '@modern-js/utils';
|
6
|
+
export var template = function template(configPath) {
|
7
|
+
return "\nfunction _interopRequireDefault(obj) {\n return obj && obj.__esModule ? obj : { default: obj };\n}\nconst modernConfig = _interopRequireDefault(require('".concat(configPath, "')).default;\n\nconst theme =\n modernConfig && modernConfig.source && modernConfig.source.designSystem\n ? modernConfig.source.designSystem\n : {};\nconst tailwindcss =\n modernConfig && modernConfig.tools && modernConfig.tools.tailwindcss\n ? modernConfig.tools.tailwindcss\n : {};\n\nmodule.exports = {\n theme,\n ...tailwindcss,\n};\n");
|
8
|
+
};
|
9
|
+
export var checkTwinMacroNotExist = /*#__PURE__*/function () {
|
10
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(appDirectory) {
|
11
|
+
var depName, packageJson;
|
12
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
13
|
+
while (1) {
|
14
|
+
switch (_context.prev = _context.next) {
|
15
|
+
case 0:
|
16
|
+
depName = 'twin.macro';
|
17
|
+
_context.next = 3;
|
18
|
+
return fs.readJSON(path.join(appDirectory, 'package.json'), {
|
19
|
+
"throws": false
|
20
|
+
});
|
21
|
+
|
22
|
+
case 3:
|
23
|
+
_context.t0 = _context.sent;
|
24
|
+
|
25
|
+
if (_context.t0) {
|
26
|
+
_context.next = 6;
|
27
|
+
break;
|
28
|
+
}
|
29
|
+
|
30
|
+
_context.t0 = {};
|
31
|
+
|
32
|
+
case 6:
|
33
|
+
packageJson = _context.t0;
|
34
|
+
|
35
|
+
if (!(_typeof(packageJson.dependencies) === 'object' && packageJson.dependencies[depName] || _typeof(packageJson.devDependencies) === 'object' && packageJson.devDependencies[depName])) {
|
36
|
+
_context.next = 9;
|
37
|
+
break;
|
38
|
+
}
|
39
|
+
|
40
|
+
return _context.abrupt("return", false);
|
41
|
+
|
42
|
+
case 9:
|
43
|
+
return _context.abrupt("return", true);
|
44
|
+
|
45
|
+
case 10:
|
46
|
+
case "end":
|
47
|
+
return _context.stop();
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}, _callee);
|
51
|
+
}));
|
52
|
+
|
53
|
+
return function checkTwinMacroNotExist(_x) {
|
54
|
+
return _ref.apply(this, arguments);
|
55
|
+
};
|
56
|
+
}();
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { Declaration } from 'postcss';
|
2
|
+
|
3
|
+
declare const _default: ({
|
4
|
+
cssVarsHash
|
5
|
+
}?: {
|
6
|
+
cssVarsHash?: Record<string, string> | undefined;
|
7
|
+
}) => {
|
8
|
+
postcssPlugin: string;
|
9
|
+
Declaration(decl: Declaration): void;
|
10
|
+
};
|
11
|
+
|
12
|
+
export default _default;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { Plugin } from '@modern-js/runtime';
|
2
|
+
import React from 'react';
|
3
|
+
export declare const DesignTokenContext: React.Context<any>;
|
4
|
+
export declare const useDesignTokens: () => IDesignTokens;
|
5
|
+
|
6
|
+
declare const _default: (options?: {
|
7
|
+
token?: Record<string, any>;
|
8
|
+
useStyledComponentsThemeProvider?: boolean;
|
9
|
+
useDesignTokenContext?: boolean;
|
10
|
+
}) => Plugin;
|
11
|
+
|
12
|
+
export default _default;
|