@digigov/cli-build-tailwind 1.0.2-rc.21 → 2.0.0-834daea4

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.
@@ -1,8 +1,9 @@
1
1
  {
2
- "../../tooling/cli-build-tailwind": "../../tooling/cli-build-tailwind:TTBeE63Q5gXUhngfrrpRCMToNU01pJPhTvZdIOef2Uk=:",
2
+ "../../tooling/cli-build-tailwind": "../../tooling/cli-build-tailwind:5YK6s5xAPyA8Dxx+04KMWLmQvo8zMTQEV0qfBu6MJzU=:",
3
3
  "/fs-extra@11.2.0": "Missing shrinkwrap entry!",
4
- "/glob@7.1.6": "Missing shrinkwrap entry!",
4
+ "/globby@11.0.0": "Missing shrinkwrap entry!",
5
5
  "/postcss-js@4.0.0(postcss@8.4.4)": "Missing shrinkwrap entry!",
6
- "/postcss-load-config@3.1.4(postcss@8.4.4)(ts-node@10.9.2(@types/node@18.19.0)(typescript@5.6.2))": "Missing shrinkwrap entry!",
7
- "/postcss@8.4.4": "Missing shrinkwrap entry!"
6
+ "/postcss-load-config@3.1.4(postcss@8.4.4)(ts-node@10.9.2(@types/node@22.7.5)(typescript@5.6.2))": "Missing shrinkwrap entry!",
7
+ "/postcss@8.4.4": "Missing shrinkwrap entry!",
8
+ "/publint@0.1.8": "Missing shrinkwrap entry!"
8
9
  }
package/build.js CHANGED
@@ -1,92 +1,142 @@
1
- const postcss = require('postcss');
2
- const postcssrc = require('postcss-load-config');
3
- const postcssJs = require('postcss-js');
4
- const fs = require('fs-extra');
5
- const path = require('path');
6
- const glob = require('glob');
1
+ import postcss from "postcss";
2
+ import postcssrc from "postcss-load-config";
3
+ import postcssJs from "postcss-js";
4
+ import fs from "fs-extra";
5
+ import path from "path";
6
+ import glob from "globby";
7
+ import { logger } from "@digigov/cli/lib";
7
8
 
9
+ /**
10
+ * Build the CSS files of a project
11
+ *
12
+ * @param {object} options - The options
13
+ * @param {string} [options.cwd=process.cwd()] - The current working directory
14
+ * @param {string} [options.distFolder='dist'] - The distribution folder
15
+ * @param {string} [options.bundleFileName='index'] - The bundle file name
16
+ * @param {boolean} [options.allFiles=false] - Whether to build all files
17
+ * @param {object} options.replace - Object defining the replacements to be made
18
+ *
19
+ */
20
+ export async function build({
21
+ cwd = process.cwd(),
22
+ distFolder = "dist",
23
+ allFiles = false,
24
+ bundleFileName = "index",
25
+ replace,
26
+ }) {
27
+ if (allFiles) logger.log("All files:", allFiles);
28
+ logger.log(`Removing dist folder ${path.join(cwd, distFolder)}`);
29
+ fs.rmSync(path.join(cwd, distFolder), {
30
+ recursive: true,
31
+ force: true,
32
+ });
33
+ const subfolders = ["utilities", "components", "base"];
34
+ const cssParts = [];
35
+ for (const subfolder of subfolders) {
36
+ logger.time(`build ${subfolder}`);
37
+ let css = "";
38
+ if (allFiles) {
39
+ for (const subpart of glob.sync(
40
+ path.join(cwd, "src", subfolder, "*.css"),
41
+ )) {
42
+ const fileName = path.basename(subpart);
43
+ if (fileName !== "index.css") {
44
+ css +=
45
+ "\n" +
46
+ (await buildDir({
47
+ dir: subfolder,
48
+ file: fileName,
49
+ cwd,
50
+ distFolder,
51
+ replace,
52
+ }));
53
+ } else {
54
+ await buildDir({
55
+ dir: subfolder,
56
+ file: fileName,
57
+ cwd,
58
+ distFolder,
59
+ replace,
60
+ });
61
+ }
62
+ }
63
+ } else {
64
+ css = await buildDir({
65
+ dir: subfolder,
66
+ file: "index.css",
67
+ cwd,
68
+ distFolder,
69
+ replace,
70
+ });
71
+ }
72
+ cssParts.unshift(css);
73
+ logger.timeEnd(`build ${subfolder}`);
74
+ }
75
+ fs.outputFileSync(
76
+ path.join(cwd, `dist/${bundleFileName}.css`),
77
+ cssParts.join("\n"),
78
+ );
79
+ }
8
80
 
9
- const buildDir = async (dir, file = 'index.css', cwd = process.cwd(), distFolder, replace) => {
81
+ /**
82
+ * Build the CSS files for a directory
83
+ *
84
+ * @param {object} options - The options
85
+ * @param {string} options.dir - The directory
86
+ * @param {string} [options.file='index.css'] - The file
87
+ * @param {string} [options.cwd=process.cwd()] - The current working directory
88
+ * @param {string} options.distFolder - The distribution folder
89
+ * @param {object} options.replace - Object defining the replacements to be made
90
+ * @returns {Promise<string>} - The processed CSS
91
+ */
92
+ export async function buildDir({
93
+ dir,
94
+ file = "index.css",
95
+ cwd = process.cwd(),
96
+ distFolder,
97
+ replace,
98
+ }) {
10
99
  process.env["DIGIGOV_CSS_BUILD"] = "TRUE";
11
100
  const options = {
12
101
  cwd,
13
102
  options: {
14
- map: {inline: true},
103
+ map: { inline: true },
15
104
  },
16
105
  file: {
17
- dirname: path.join(cwd, 'src', dir),
106
+ dirname: path.join(cwd, "src", dir),
18
107
  basename: file,
19
- extname: '.css'
108
+ extname: ".css",
20
109
  },
21
- from: path.join(cwd, 'src', dir, file),
110
+ from: path.join(cwd, "src", dir, file),
22
111
  to: path.join(cwd, distFolder, dir, file),
23
112
  };
24
- const filePathPart = file === 'index.css' ? '' : `/${file.replace('.css', '')}`;
25
- console.log(`Building ${dir} ${file}...`);
113
+ const filePathPart =
114
+ file === "index.css" ? "" : `/${file.replace(".css", "")}`;
115
+ logger.log(`Building ${dir} ${file}...`);
26
116
  let css = fs.readFileSync(options.from, "utf8");
27
- const rc = await postcssrc(options, path.join(cwd, 'src', dir))
28
- .catch((err) => {
29
- if(!err.message.includes('No PostCSS Config found')) throw err;
30
- });
31
- const result = await postcss(rc.plugins)
32
- .process(css, options);
117
+ const rc = await postcssrc(options, path.join(cwd, "src", dir)).catch(
118
+ (err) => {
119
+ if (!err.message.includes("No PostCSS Config found")) throw err;
120
+ },
121
+ );
122
+ const result = await postcss.default(rc?.plugins).process(css, options);
33
123
  let processedCss = result.css;
34
124
  let cssJs = JSON.stringify(postcssJs.objectify(result.root));
35
- if(replace) {
36
- for(const from in replace) {
125
+ if (replace) {
126
+ for (const from in replace) {
37
127
  const to = replace[from];
38
- console.log(`Replace ${from} with ${to}`);
128
+ logger.log(`Replace ${from} with ${to}`);
129
+ if (!to) continue;
39
130
  processedCss = processedCss.replaceAll(from, to);
40
131
  cssJs = cssJs.replaceAll(from, to);
41
132
  }
42
133
  }
43
- if(options.to) {
134
+ if (options.to) {
44
135
  fs.outputFileSync(options.to, processedCss);
45
- fs.outputFileSync(path.join(cwd, distFolder, `${dir}${filePathPart}.js`), `module.exports = ${cssJs}`);
46
-
47
- } else process.stdout.write(processedCss, 'utf8');
136
+ fs.outputFileSync(
137
+ path.join(cwd, distFolder, `${dir}${filePathPart}.js`),
138
+ `module.exports = ${cssJs}`,
139
+ );
140
+ } else process.stdout.write(processedCss, "utf8");
48
141
  return processedCss;
49
- };
50
-
51
-
52
- const build = async ({cwd = process.cwd(), distFolder = 'dist', allFiles = false, bundleFileName = 'index', replace}) => {
53
- console.time('build');
54
- console.log('All files:', allFiles,);
55
- console.log(`Removing dist folder ${path.join(cwd, distFolder)}`);
56
- fs.rmSync(path.join(cwd, distFolder), {
57
- recursive: true, force: true
58
- });
59
- const subfolders = ['utilities', 'components', 'base'];
60
- const cssParts = [];
61
- for(const subfolder of subfolders) {
62
- console.time(`build ${subfolder}`);
63
- let css = '';
64
- if(allFiles) {
65
- for(const subpart of glob.sync(path.join(cwd, 'src', subfolder, "*.css"))) {
66
- const fileName = path.basename(subpart);
67
- if(fileName !== 'index.css') {
68
- css += "\n" + await buildDir(subfolder, fileName, cwd, distFolder, replace);
69
- } else {
70
- await buildDir(subfolder, fileName, cwd, distFolder, replace);
71
- }
72
- }
73
-
74
- } else {
75
- css = await buildDir(subfolder, 'index.css', cwd, distFolder, replace);
76
-
77
- }
78
- cssParts.unshift(css);
79
- console.timeEnd(`build ${subfolder}`);
80
- }
81
- fs.outputFileSync(path.join(cwd, `dist/${bundleFileName}.css`), cssParts.join('\n'));
82
- console.timeEnd('build');
83
- };
84
- if(typeof require !== 'undefined' && require.main === module) {
85
- build({});
86
142
  }
87
-
88
-
89
- module.exports = {
90
- buildDir,
91
- build
92
- };
package/index.js CHANGED
@@ -1,32 +1,35 @@
1
- const {flags} = require('@oclif/command');
2
- const {DigigovCommand} = require('@digigov/cli/lib');
3
- const {build} = require('./build');
4
- module.exports = class BuildTailwind extends DigigovCommand {
5
- static description = 'build digigov libraries';
6
- static id = 'build-tailwind';
7
- dirname = __dirname;
8
- static examples = [
9
- `$ digigov build-tailwind`,
10
- ];
11
- static strict = true;
12
- static flags = {
13
- allFiles: flags.boolean({char: '--all-files'}),
14
- bundle: flags.string({})
15
- };
16
- static load() {return BuildTailwind;}
17
- async run() {
18
- const {args, flags} = this.parse(BuildTailwind);
19
- try {
20
- await build({
21
- bundleFileName: flags.bundle,
22
- allFiles: flags.allFiles,
23
- replace: {
24
- 'border-color:reset': '',
25
- '"borderColor":"reset"':''
26
- }
27
- });
28
- } catch(err) {
29
- console.log(err);
30
- }
31
- }
32
- };
1
+ import { DigigovCommand } from "@digigov/cli/lib";
2
+ import { build } from "./build.js";
3
+
4
+ const command = new DigigovCommand("build-tailwind", import.meta.url);
5
+
6
+ command
7
+ .option("--all-files", "Build all files", false)
8
+ .option("--cwd <directory>", "Current working directory", process.cwd())
9
+ .option("--dist <distFolder>", "Distribution folder", "dist")
10
+ .option("--bundle <fileName>", "Bundle file name", "index")
11
+ .action(buildTailwind);
12
+
13
+ export default command;
14
+
15
+ /**
16
+ * @param {object} options - The options
17
+ * @param {string} options.cwd - The current working directory
18
+ * @param {string} options.dist - The distribution folder
19
+ * @param {string} options.bundle - The bundle file name
20
+ * @param {boolean} options.allFiles - Whether to build all files
21
+ * @param {string} options.replace - Replace
22
+ * @param {DigigovCommand} ctx - The command context
23
+ */
24
+ async function buildTailwind(options) {
25
+ await build({
26
+ cwd: options.cwd,
27
+ distFolder: options.dist,
28
+ bundleFileName: options.bundle,
29
+ allFiles: options.allFiles,
30
+ replace: {
31
+ "border-color:reset": "",
32
+ '"borderColor":"reset"': "",
33
+ },
34
+ });
35
+ }
package/package.json CHANGED
@@ -1,20 +1,27 @@
1
1
  {
2
2
  "name": "@digigov/cli-build-tailwind",
3
- "version": "1.0.2-rc.21",
3
+ "version": "2.0.0-834daea4",
4
4
  "description": "Build tailwind plugin for Digigov CLI",
5
5
  "main": "./index.js",
6
+ "type": "module",
6
7
  "author": "GRNET Devs <devs@lists.grnet.gr>",
7
8
  "license": "BSD-2-Clause",
8
9
  "private": false,
9
10
  "dependencies": {
10
11
  "fs-extra": "11.2.0",
11
- "glob": "7.1.6",
12
+ "globby": "11.0.0",
12
13
  "postcss": "8.4.4",
13
14
  "postcss-js": "4.0.0",
14
15
  "postcss-load-config": "3.1.4"
15
16
  },
17
+ "devDependencies": {
18
+ "publint": "0.1.8"
19
+ },
16
20
  "peerDependencies": {
17
- "@digigov/cli": "1.1.1-rc.21"
21
+ "@digigov/cli": "2.0.0-834daea4"
18
22
  },
19
- "scripts": {}
23
+ "scripts": {
24
+ "publint": "publint",
25
+ "lint": "echo 'no lint needed (yet)'"
26
+ }
20
27
  }