@jobber/design 1.0.0-alpha.0 → 1.0.0-pre.1

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 CHANGED
@@ -8,6 +8,60 @@ menu: Changelog
8
8
  All notable changes to this project will be documented in this file.
9
9
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
10
10
 
11
+ # [1.0.0-pre.1](https://github.com/GetJobber/atlantis/compare/@jobber/design@1.0.0-pre.0...@jobber/design@1.0.0-pre.1) (2023-01-24)
12
+
13
+ **Note:** Version bump only for package @jobber/design
14
+
15
+
16
+
17
+
18
+
19
+ # [1.0.0-pre.0](https://github.com/GetJobber/atlantis/compare/@jobber/design@0.26.0...@jobber/design@1.0.0-pre.0) (2023-01-24)
20
+
21
+
22
+ ### Features
23
+
24
+ * **design:** BREAKING CHANGE: Implement new typefaces in Atlantis [JOB-46209] ([#952](https://github.com/GetJobber/atlantis/issues/952)) ([15f604c](https://github.com/GetJobber/atlantis/commit/15f604cc51ee6881a5ed9c1be01081c76cf5ce6e))
25
+
26
+
27
+ ### BREAKING CHANGES
28
+
29
+ * **design:** Added Jobber Fonts support
30
+
31
+ * Remove file that was needed for major bump in design
32
+
33
+ * Revert "update button styles"
34
+
35
+ This reverts commit d5278133003f4f770af56d583ef104b5abc8b886.
36
+
37
+ * Remove unneeded logging
38
+
39
+ * Update install instructions for non-jobber developers
40
+
41
+ * Changed how package works when being installed to better support non jobber devs.
42
+
43
+ * Use variables in docz instead of a string
44
+
45
+ * Remove change that caused failures for Jobber people
46
+
47
+ * Moved script location
48
+
49
+ * Maybe fix cloudflare builds. Hopefully
50
+
51
+ * Update README.md
52
+
53
+ * Updated prerelease docs.
54
+ Verify fonts aren't bundled with pre-releases.
55
+
56
+ * rebuild cloudflare
57
+
58
+ Co-authored-by: Chris Murray <39704901+chris-at-jobber@users.noreply.github.com>
59
+ Co-authored-by: Michael Paradis <michael.p@getjobber.com>
60
+
61
+
62
+
63
+
64
+
11
65
  # [1.0.0-alpha.0](https://github.com/GetJobber/atlantis/compare/@jobber/design@0.26.0...@jobber/design@1.0.0-alpha.0) (2023-01-24)
12
66
 
13
67
 
package/buildColors.js ADDED
@@ -0,0 +1,15 @@
1
+ /* eslint-env node */
2
+ /* eslint-disable @typescript-eslint/no-var-requires */
3
+ const fs = require("fs");
4
+ const postcss = require("postcss");
5
+ const postcssCustomProperties = require("postcss-custom-properties");
6
+
7
+ const colors = fs.readFileSync("src/colors.css");
8
+
9
+ postcss([
10
+ postcssCustomProperties({
11
+ exportTo: ["colors.js"],
12
+ }),
13
+ ])
14
+ .process(colors, { from: undefined })
15
+ .then();
@@ -0,0 +1,15 @@
1
+ /* eslint-env node */
2
+ /* eslint-disable @typescript-eslint/no-var-requires */
3
+ const fs = require("fs");
4
+ const postcss = require("postcss");
5
+ const postcssCustomProperties = require("postcss-custom-properties");
6
+
7
+ const foundation = fs.readFileSync("./foundation.css");
8
+
9
+ postcss([
10
+ postcssCustomProperties({
11
+ exportTo: ["src/foundation.js"],
12
+ }),
13
+ ])
14
+ .process(foundation, { from: undefined })
15
+ .then();
@@ -0,0 +1,44 @@
1
+ /* eslint-env node */
2
+ /* eslint-disable @typescript-eslint/no-var-requires */
3
+
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ const postcss = require("postcss");
7
+ const postcssCustomProperties = require("postcss-custom-properties");
8
+ const postcssCalc = require("postcss-calc");
9
+ const transform = require("css-to-react-native-transform").default;
10
+
11
+ const icon = fs.readFileSync("src/icons/Icon.css");
12
+ const size = fs.readFileSync("src/icons/Sizes.css");
13
+ const color = fs.readFileSync("src/icons/Colors.css");
14
+
15
+ const allCss = [icon, size, color].join("\n");
16
+
17
+ postcss([
18
+ postcssCustomProperties({
19
+ preserve: false,
20
+ importFrom: ["foundation.css"],
21
+ }),
22
+ postcssCalc(),
23
+ ])
24
+ .process(allCss, { from: undefined })
25
+ .then(function (result) {
26
+ const calculated = transform(result.css);
27
+ const jsonContent =
28
+ "/* This file is automatically generated by buildIconStyle.js and should not be edited. */\n" +
29
+ "export const iconStyles = " +
30
+ JSON.stringify(calculated, undefined, 2);
31
+
32
+ fs.writeFile(
33
+ path.join(__dirname, "src/icons/iconStyles.ts"),
34
+ jsonContent,
35
+ "utf8",
36
+ function (err) {
37
+ if (err) {
38
+ console.log("An error occurred while writing JSON object to File.");
39
+ return console.log(err);
40
+ }
41
+ console.log("JSON file has been saved.");
42
+ },
43
+ );
44
+ });
@@ -0,0 +1,17 @@
1
+ /* eslint-env node */
2
+ /* eslint-disable @typescript-eslint/no-var-requires */
3
+
4
+ const postcss = require("postcss");
5
+
6
+ module.exports = postcss.plugin(
7
+ "postcss-filter-rules",
8
+ (opts = { ruleFilters: [] }) => {
9
+ // Work with options here
10
+
11
+ return root => {
12
+ root.nodes.forEach(rule => {
13
+ opts.ruleFilters.forEach(filter => filter(rule));
14
+ });
15
+ };
16
+ },
17
+ );
@@ -0,0 +1,58 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+ /* eslint-env node */
3
+
4
+ const postcssCustomProperties = require("postcss-custom-properties");
5
+ const postcssImport = require("postcss-import");
6
+ const postcssCopy = require("postcss-copy");
7
+ const removeRule = require("./postcss-filter-rules");
8
+
9
+ let maintainPath;
10
+ let hasJobberFonts = false;
11
+ try {
12
+ ({ maintainPath } = require("@jobber/fonts"));
13
+ hasJobberFonts = true;
14
+ } catch (e) {
15
+ hasJobberFonts = false;
16
+ }
17
+ function removeFontImport(rule) {
18
+ if (rule.params?.includes("@jobber/fonts")) {
19
+ if (!hasJobberFonts) {
20
+ console.warn("remove rule in foundation config", { hasJobberFonts });
21
+ rule.remove();
22
+ }
23
+ }
24
+ }
25
+ const postcssCopyInstance = postcssCopy({
26
+ dest: "./dist",
27
+ basePath: ["./src", "./node_modules"],
28
+ preservePath: true,
29
+ template(fileMeta) {
30
+ return fileMeta.filename;
31
+ },
32
+ });
33
+ const postcssImportInstance = postcssImport({
34
+ basedir: ["./src", "./node_modules"],
35
+ filter: path => {
36
+ if (path.includes("@jobber/fonts")) {
37
+ console.warn("include fonts, import, foundation config", {
38
+ hasJobberFonts,
39
+ });
40
+ return hasJobberFonts;
41
+ } else {
42
+ return true;
43
+ }
44
+ },
45
+ });
46
+
47
+ module.exports = {
48
+ plugins: [
49
+ removeRule({ ruleFilters: [removeFontImport] }),
50
+ postcssImportInstance,
51
+ hasJobberFonts && postcssCopyInstance,
52
+ hasJobberFonts &&
53
+ maintainPath({ pathToFind: "dist/fonts", pathToSet: "./dist/fonts" }),
54
+ postcssCustomProperties({
55
+ exportTo: ["src/foundation.js"],
56
+ }),
57
+ ],
58
+ };
package/jobberStyle.js ADDED
@@ -0,0 +1,164 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+ const fs = require("fs");
3
+ // eslint-disable-next-line import/no-internal-modules
4
+ const customPropertiesObject = require("./src/foundation.js");
5
+
6
+ const regexExpressions = {
7
+ cssVars: /var\((.*)\)/,
8
+ calculations: /calc\((.*)\)/,
9
+ rgbVars: /rgb\(var\((.*)\)\)/,
10
+ rgbaVars: /rgba\(var\((.*)\),?(.*)\)/,
11
+ removeAllNonNumerals: /[^0-9.+\-/*]/gi,
12
+ extractAllVarGroups: /var\(.*?\)/g,
13
+ };
14
+
15
+ const customProperties = customPropertiesObject.customProperties;
16
+
17
+ const resolvedCssVars = getResolvedCSSVars(customProperties);
18
+
19
+ const jsonContent =
20
+ "export const JobberStyle = " + JSON.stringify(resolvedCssVars, undefined, 2);
21
+
22
+ fs.writeFile("./foundation.js", jsonContent, "utf8", function (err) {
23
+ if (err) {
24
+ console.log("An error occured while writing JSON object to File.");
25
+ return console.log(err);
26
+ }
27
+ console.log("JSON file has been saved.");
28
+ });
29
+
30
+ const scssColors = getResolvedSCSSColors(resolvedCssVars);
31
+
32
+ fs.writeFile(
33
+ "./foundation.scss",
34
+ scssColors.join("\n"),
35
+ "utf-8",
36
+ function (err) {
37
+ if (err) {
38
+ console.log("An error occured while writing SCSS to File.");
39
+ return console.log(err);
40
+ }
41
+ console.log("SCSS file has been saved.");
42
+ },
43
+ );
44
+
45
+ /**
46
+ * Recursively resolve css custom properties.
47
+ *
48
+ * eg:
49
+ * ```
50
+ * jobberStyle(`
51
+ * "--base": "5px",
52
+ * "--foo": "calc(var(--base) * 2),
53
+ * `);
54
+ * ```
55
+ * =>
56
+ * ```
57
+ * {
58
+ * "--base": "5",
59
+ * "--foo": "10",
60
+ * }
61
+ * ```
62
+ */
63
+
64
+ function jobberStyle(styling) {
65
+ const styleValue = customProperties[styling];
66
+
67
+ //varRegexResult returns --base-unit from var(--base-unit)
68
+ const varRegexResult = regexExpressions.cssVars.exec(styleValue);
69
+ //rgbVarRegexResult returns --base-unit from rgb(var(--base-unit))
70
+ const rgbVarRegexResult = regexExpressions.rgbVars.exec(styleValue);
71
+ //rgbaVarRegexResult returns --base-unit and alpha (if exists) from rgba(var(--base-unit), alpha)
72
+ const rgbaVarRegexResult = regexExpressions.rgbaVars.exec(styleValue);
73
+
74
+ //calcRegexResult returns var(--base-unit) / 16 from calc(var(--base-unit) / 16)
75
+ const calcRegexResult = regexExpressions.calculations.exec(styleValue);
76
+ if (calcRegexResult) {
77
+ return handleCalc(calcRegexResult);
78
+ } else if (rgbVarRegexResult) {
79
+ return jobberStyle(rgbVarRegexResult[1]);
80
+ } else if (rgbaVarRegexResult) {
81
+ return handleRbga(rgbaVarRegexResult);
82
+ } else if (varRegexResult) {
83
+ return jobberStyle(varRegexResult[1]);
84
+ } else {
85
+ return isSpacingValue(styleValue) ? parseFloat(styleValue) : styleValue;
86
+ }
87
+ }
88
+
89
+ function handleCalc(calcRegexResult) {
90
+ const finalExpression = handleExpressionsInCalc(calcRegexResult);
91
+ // eslint-disable-next-line no-new-func
92
+ const calculatedValue = new Function(
93
+ "return " +
94
+ finalExpression.replace(regexExpressions.removeAllNonNumerals, ""),
95
+ )();
96
+ return isSpacingValue(calculatedValue)
97
+ ? parseFloat(calculatedValue)
98
+ : calculatedValue;
99
+ }
100
+
101
+ function handleRbga(rgbaVarRegexResult) {
102
+ let resolved = "rgba(" + jobberStyle(rgbaVarRegexResult[1]);
103
+ if (rgbaVarRegexResult[2]) {
104
+ resolved += "," + rgbaVarRegexResult[2];
105
+ }
106
+ resolved += ")";
107
+
108
+ return resolved;
109
+ }
110
+
111
+ function handleExpressionsInCalc(calcRegexResult) {
112
+ const calcExtract = calcRegexResult[1];
113
+ const varGroups = calcExtract.match(regexExpressions.extractAllVarGroups);
114
+ let finalExpression = calcExtract;
115
+ varGroups &&
116
+ varGroups.forEach(group => {
117
+ const cssVariableRegexResult = regexExpressions.cssVars.exec(group);
118
+ if (cssVariableRegexResult) {
119
+ finalExpression = resolveCssVarsInExpression({
120
+ group,
121
+ cssVariableRegexResult,
122
+ finalExpression,
123
+ });
124
+ }
125
+ });
126
+ return finalExpression;
127
+ }
128
+
129
+ function resolveCssVarsInExpression({
130
+ group,
131
+ cssVariableRegexResult,
132
+ finalExpression,
133
+ }) {
134
+ const cssVariable = cssVariableRegexResult[1];
135
+ const realValue = jobberStyle(cssVariable);
136
+ const unresolvedCssVariable = group;
137
+ return finalExpression.replace(unresolvedCssVariable, realValue);
138
+ }
139
+
140
+ function isSpacingValue(value) {
141
+ return !!String(value).match(
142
+ /(^\d+(px|%|rem|em|ex|ch|vw|vh|vmin|vmax)$)|(^\d+$)/,
143
+ );
144
+ }
145
+
146
+ function getResolvedCSSVars(cssProperties) {
147
+ const allKeys = Object.keys(cssProperties);
148
+ return allKeys.reduce((acc, key) => {
149
+ const newKey = key.replace("--", "");
150
+ acc[newKey] = jobberStyle(key);
151
+ return acc;
152
+ }, {});
153
+ }
154
+
155
+ function getResolvedSCSSColors(cssProperties) {
156
+ const allKeys = Object.keys(cssProperties);
157
+ return allKeys.reduce((acc, cssVar) => {
158
+ if (cssVar.includes("color")) {
159
+ return [...acc, `$${cssVar}: ${resolvedCssVars[cssVar]};`];
160
+ } else {
161
+ return acc;
162
+ }
163
+ }, []);
164
+ }