| [9af201e] | 1 | // @ts-check
|
|---|
| 2 | "use strict";
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | Object.defineProperty(exports, "init", {
|
|---|
| 7 | enumerable: true,
|
|---|
| 8 | get: function() {
|
|---|
| 9 | return init;
|
|---|
| 10 | }
|
|---|
| 11 | });
|
|---|
| 12 | const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|---|
| 13 | const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|---|
| 14 | function _interop_require_default(obj) {
|
|---|
| 15 | return obj && obj.__esModule ? obj : {
|
|---|
| 16 | default: obj
|
|---|
| 17 | };
|
|---|
| 18 | }
|
|---|
| 19 | function isESM() {
|
|---|
| 20 | const pkgPath = _path.default.resolve("./package.json");
|
|---|
| 21 | try {
|
|---|
| 22 | let pkg = JSON.parse(_fs.default.readFileSync(pkgPath, "utf8"));
|
|---|
| 23 | return pkg.type && pkg.type === "module";
|
|---|
| 24 | } catch (err) {
|
|---|
| 25 | return false;
|
|---|
| 26 | }
|
|---|
| 27 | }
|
|---|
| 28 | function init(args) {
|
|---|
| 29 | let messages = [];
|
|---|
| 30 | let isProjectESM = args["--ts"] || args["--esm"] || isESM();
|
|---|
| 31 | let syntax = args["--ts"] ? "ts" : isProjectESM ? "js" : "cjs";
|
|---|
| 32 | let extension = args["--ts"] ? "ts" : "js";
|
|---|
| 33 | var _args___;
|
|---|
| 34 | let tailwindConfigLocation = _path.default.resolve((_args___ = args["_"][1]) !== null && _args___ !== void 0 ? _args___ : `./tailwind.config.${extension}`);
|
|---|
| 35 | if (_fs.default.existsSync(tailwindConfigLocation)) {
|
|---|
| 36 | messages.push(`${_path.default.basename(tailwindConfigLocation)} already exists.`);
|
|---|
| 37 | } else {
|
|---|
| 38 | let stubContentsFile = _fs.default.readFileSync(args["--full"] ? _path.default.resolve(__dirname, "../../../stubs/config.full.js") : _path.default.resolve(__dirname, "../../../stubs/config.simple.js"), "utf8");
|
|---|
| 39 | let stubFile = _fs.default.readFileSync(_path.default.resolve(__dirname, `../../../stubs/tailwind.config.${syntax}`), "utf8");
|
|---|
| 40 | // Change colors import
|
|---|
| 41 | stubContentsFile = stubContentsFile.replace("../colors", "tailwindcss/colors");
|
|---|
| 42 | // Replace contents of {ts,js,cjs} file with the stub {simple,full}.
|
|---|
| 43 | stubFile = stubFile.replace("__CONFIG__", stubContentsFile.replace("module.exports =", "").trim()).trim() + "\n\n";
|
|---|
| 44 | _fs.default.writeFileSync(tailwindConfigLocation, stubFile, "utf8");
|
|---|
| 45 | messages.push(`Created Tailwind CSS config file: ${_path.default.basename(tailwindConfigLocation)}`);
|
|---|
| 46 | }
|
|---|
| 47 | if (args["--postcss"]) {
|
|---|
| 48 | let postcssConfigLocation = _path.default.resolve("./postcss.config.js");
|
|---|
| 49 | if (_fs.default.existsSync(postcssConfigLocation)) {
|
|---|
| 50 | messages.push(`${_path.default.basename(postcssConfigLocation)} already exists.`);
|
|---|
| 51 | } else {
|
|---|
| 52 | let stubFile = _fs.default.readFileSync(isProjectESM ? _path.default.resolve(__dirname, "../../../stubs/postcss.config.js") : _path.default.resolve(__dirname, "../../../stubs/postcss.config.cjs"), "utf8");
|
|---|
| 53 | _fs.default.writeFileSync(postcssConfigLocation, stubFile, "utf8");
|
|---|
| 54 | messages.push(`Created PostCSS config file: ${_path.default.basename(postcssConfigLocation)}`);
|
|---|
| 55 | }
|
|---|
| 56 | }
|
|---|
| 57 | if (messages.length > 0) {
|
|---|
| 58 | console.log();
|
|---|
| 59 | for (let message of messages){
|
|---|
| 60 | console.log(message);
|
|---|
| 61 | }
|
|---|
| 62 | }
|
|---|
| 63 | }
|
|---|