piral-cli 1.1.0-beta.5790 → 1.1.0-beta.5795

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,6 +1,16 @@
1
1
  import { PiletRuleContext } from '../types';
2
- export type Options = 'suggest' | 'required' | 'ignore';
2
+ export type Options = number;
3
3
  /**
4
- * Checks if the pilet has some CSS rules that might conflict with other pilets.
4
+ * Checks if a pilet might cause a CSS conflict. A score of 100 means that
5
+ * there is the least chance of a CSS conflict, while a score of 0 means that
6
+ * a CSS conflict is most likely.
7
+ *
8
+ * Negative values yield a warning if the CSS score is below the given number.
9
+ *
10
+ * Positive values yield an error if the CSS score is below the given number.
11
+ *
12
+ * A value of 0 turns this validation off.
13
+ *
14
+ * By default, a pilet's stylesheet having a CSS score of below 50 will result in a warning.
5
15
  */
6
16
  export default function (context: PiletRuleContext, options?: Options): Promise<void>;
@@ -9,15 +9,62 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ const path_1 = require("path");
12
13
  const css_conflict_inspector_1 = require("css-conflict-inspector");
14
+ const common_1 = require("../common");
15
+ function getPiletCssPaths(main, baseDir) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const paths = [main, `dist/${main}`, `${main}/index.js`, `dist/${main}/index.js`, 'index.js', 'dist/index.js'];
18
+ for (const path of paths) {
19
+ const outDir = (0, path_1.dirname)((0, path_1.resolve)(baseDir, path));
20
+ const exists = yield (0, common_1.checkExists)(outDir);
21
+ if (exists) {
22
+ const files = yield (0, common_1.getFileNames)(outDir);
23
+ return files.filter((m) => m.endsWith('.css')).map((m) => (0, path_1.resolve)(outDir, m));
24
+ }
25
+ }
26
+ return [];
27
+ });
28
+ }
29
+ function getCssScore(dir, file) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const content = yield (0, common_1.readText)(dir, file);
32
+ const result = (0, css_conflict_inspector_1.analyzeCss)(content);
33
+ return result.score;
34
+ });
35
+ }
13
36
  /**
14
- * Checks if the pilet has some CSS rules that might conflict with other pilets.
37
+ * Checks if a pilet might cause a CSS conflict. A score of 100 means that
38
+ * there is the least chance of a CSS conflict, while a score of 0 means that
39
+ * a CSS conflict is most likely.
40
+ *
41
+ * Negative values yield a warning if the CSS score is below the given number.
42
+ *
43
+ * Positive values yield an error if the CSS score is below the given number.
44
+ *
45
+ * A value of 0 turns this validation off.
46
+ *
47
+ * By default, a pilet's stylesheet having a CSS score of below 50 will result in a warning.
15
48
  */
16
- function default_1(context, options = 'suggest') {
49
+ function default_1(context, options = -50) {
17
50
  return __awaiter(this, void 0, void 0, function* () {
18
- if (options !== 'ignore') {
19
- //TODO
20
- const result = (0, css_conflict_inspector_1.analyzeCss)('');
51
+ if (options !== 0 && typeof options === 'number') {
52
+ const threshold = Math.abs(options);
53
+ const { main } = context.piletPackage;
54
+ const paths = yield getPiletCssPaths(main, context.root);
55
+ for (const path of paths) {
56
+ const dir = (0, path_1.dirname)(path);
57
+ const file = (0, path_1.basename)(path);
58
+ const score = yield getCssScore(dir, file);
59
+ if (score < threshold) {
60
+ const notify = options > 0 ? context.error : context.warning;
61
+ notify(`
62
+ The CSS in "${file}" might lead to conflicts.
63
+ Minimum: ${threshold} points.
64
+ Received: ${score} points.
65
+ `);
66
+ }
67
+ }
21
68
  }
22
69
  });
23
70
  }
@@ -1 +1 @@
1
- {"version":3,"file":"pilet-has-non-conflicting-css.js","sourceRoot":"","sources":["../../src/rules/pilet-has-non-conflicting-css.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,mEAAoD;AAKpD;;GAEG;AACH,mBAA+B,OAAyB,EAAE,UAAmB,SAAS;;QACpF,IAAI,OAAO,KAAK,QAAQ,EAAE;YACxB,MAAM;YACN,MAAM,MAAM,GAAG,IAAA,mCAAU,EAAC,EAAE,CAAC,CAAC;SAC/B;IACH,CAAC;CAAA;AALD,4BAKC"}
1
+ {"version":3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,KAAK,CAAC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAChD,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACpC,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC;YACtC,MAAM,KAAK,GAAG,MAAM,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;YAEzD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;gBACxB,MAAM,GAAG,GAAG,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC;gBAC1B,MAAM,IAAI,GAAG,IAAA,eAAQ,EAAC,IAAI,CAAC,CAAC;gBAC5B,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;gBAE3C,IAAI,KAAK,GAAG,SAAS,EAAE;oBACrB,MAAM,MAAM,GAAG,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;oBAC7D,MAAM,CACJ;cACI,IAAI;aACL,SAAS;cACR,KAAK;CAClB,CACQ,CAAC;iBACH;aACF;SACF;IACH,CAAC;CAAA;AAvBD,4BAuBC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-cli",
3
- "version": "1.1.0-beta.5790",
3
+ "version": "1.1.0-beta.5795",
4
4
  "description": "The standard CLI for creating and building a Piral instance or a Pilet.",
5
5
  "keywords": [
6
6
  "portal",
@@ -74,12 +74,12 @@
74
74
  "tar": "^4.4.8"
75
75
  },
76
76
  "dependencies": {
77
- "css-conflict-inspector": "^0.1.1",
77
+ "css-conflict-inspector": "^0.2.0",
78
78
  "dets": "^0.13.0",
79
79
  "kras": "^0.15.4",
80
80
  "rimraf": "^3.0.0",
81
81
  "typescript": "^5.0.0",
82
82
  "yargs": "^15.0.0"
83
83
  },
84
- "gitHead": "72d5d80ca6a0265ae77d03bd2fdea1ad7e0101b6"
84
+ "gitHead": "da5f369c6bc3558a4a2013e121b5e622e39a0a54"
85
85
  }
@@ -1,14 +1,66 @@
1
+ import { basename, dirname, resolve } from 'path';
1
2
  import { analyzeCss } from 'css-conflict-inspector';
3
+ import { checkExists, getFileNames, readText } from '../common';
2
4
  import { PiletRuleContext } from '../types';
3
5
 
4
- export type Options = 'suggest' | 'required' | 'ignore';
6
+ export type Options = number;
7
+
8
+ async function getPiletCssPaths(main: string, baseDir: string) {
9
+ const paths = [main, `dist/${main}`, `${main}/index.js`, `dist/${main}/index.js`, 'index.js', 'dist/index.js'];
10
+
11
+ for (const path of paths) {
12
+ const outDir = dirname(resolve(baseDir, path));
13
+ const exists = await checkExists(outDir);
14
+
15
+ if (exists) {
16
+ const files = await getFileNames(outDir);
17
+ return files.filter((m) => m.endsWith('.css')).map((m) => resolve(outDir, m));
18
+ }
19
+ }
20
+
21
+ return [];
22
+ }
23
+
24
+ async function getCssScore(dir: string, file: string) {
25
+ const content = await readText(dir, file);
26
+ const result = analyzeCss(content);
27
+ return result.score;
28
+ }
5
29
 
6
30
  /**
7
- * Checks if the pilet has some CSS rules that might conflict with other pilets.
31
+ * Checks if a pilet might cause a CSS conflict. A score of 100 means that
32
+ * there is the least chance of a CSS conflict, while a score of 0 means that
33
+ * a CSS conflict is most likely.
34
+ *
35
+ * Negative values yield a warning if the CSS score is below the given number.
36
+ *
37
+ * Positive values yield an error if the CSS score is below the given number.
38
+ *
39
+ * A value of 0 turns this validation off.
40
+ *
41
+ * By default, a pilet's stylesheet having a CSS score of below 50 will result in a warning.
8
42
  */
9
- export default async function (context: PiletRuleContext, options: Options = 'suggest') {
10
- if (options !== 'ignore') {
11
- //TODO
12
- const result = analyzeCss('');
43
+ export default async function (context: PiletRuleContext, options: Options = -50) {
44
+ if (options !== 0 && typeof options === 'number') {
45
+ const threshold = Math.abs(options);
46
+ const { main } = context.piletPackage;
47
+ const paths = await getPiletCssPaths(main, context.root);
48
+
49
+ for (const path of paths) {
50
+ const dir = dirname(path);
51
+ const file = basename(path);
52
+ const score = await getCssScore(dir, file);
53
+
54
+ if (score < threshold) {
55
+ const notify = options > 0 ? context.error : context.warning;
56
+ notify(
57
+ `
58
+ The CSS in "${file}" might lead to conflicts.
59
+ Minimum: ${threshold} points.
60
+ Received: ${score} points.
61
+ `,
62
+ );
63
+ }
64
+ }
13
65
  }
14
66
  }