@aurodesignsystem/auro-library 2.1.0 → 2.2.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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # Semantic Release Automated Changelog
2
2
 
3
+ # [2.2.0](https://github.com/AlaskaAirlines/auro-library/compare/v2.1.1...v2.2.0) (2024-01-09)
4
+
5
+
6
+ ### Features
7
+
8
+ * add build scripts from generator [#47](https://github.com/AlaskaAirlines/auro-library/issues/47) ([ac81a7d](https://github.com/AlaskaAirlines/auro-library/commit/ac81a7d3768e97435d7c80436ae241e2ce38e30b))
9
+
10
+ ## [2.1.1](https://github.com/AlaskaAirlines/auro-library/compare/v2.1.0...v2.1.1) (2023-12-29)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **utils:** move runtime utils to separete file from node utils ([592990e](https://github.com/AlaskaAirlines/auro-library/commit/592990eeb693282999d75998dc49e62f0857012a))
16
+
3
17
  # [2.1.0](https://github.com/AlaskaAirlines/auro-library/compare/v2.0.0...v2.1.0) (2023-12-28)
4
18
 
5
19
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aurodesignsystem/auro-library",
3
- "version": "2.1.0",
4
- "description": "This repository holds shared scripts, utilities, and workflows utilized acorss repositories along the Auro Design System.",
3
+ "version": "2.2.0",
4
+ "description": "This repository holds shared scripts, utilities, and workflows utilized across repositories along the Auro Design System.",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/AlaskaAirlines/auro-library.git"
@@ -0,0 +1,18 @@
1
+ import autoprefixer from 'autoprefixer';
2
+ import postcss from 'postcss';
3
+ import comments from 'postcss-discard-comments';
4
+ import fs from 'fs';
5
+
6
+ fs.readFile('src/style.css', (err, css) => {
7
+ postcss([autoprefixer, comments])
8
+ .use(comments({
9
+ remove: function(comment) { return comment[0] == "@"; }
10
+ }))
11
+ .process(css, { from: 'src/style.css', to: 'src/style.css' })
12
+ .then(result => {
13
+ fs.writeFile('src/style.css', result.css, () => true)
14
+ if ( result.map ) {
15
+ fs.writeFile('src/style.map', result.map, () => true)
16
+ }
17
+ })
18
+ });
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ import chalk from 'chalk';
4
+ import { createRequire } from 'node:module';
5
+ const require = createRequire(import.meta.url);
6
+ const pjson = require('../package.json');
7
+
8
+ console.log(chalk.hex('#f26135')(`
9
+
10
+ _______ __ __ __
11
+ | __|.---.-.--.--. | |--.-----.| | |.-----.
12
+ |__ || _ | | | | | -__|| | || _ |
13
+ |_______||___._|___ | |__|__|_____||__|__||_____|
14
+ |_____|
15
+ __ _______ __
16
+ | |_.-----. | _ |.--.--.----.-----.| |
17
+ | _| _ | | || | | _| _ ||__|
18
+ |____|_____| |___|___||_____|__| |_____||__|
19
+
20
+
21
+ ╭ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ──────────────────────────────╮
22
+
23
+ Thanks for installing the latest version
24
+ of `) + chalk.hex('#ffd200').bold(`${pjson.name} v${pjson.version}.`) + chalk.hex('#f26135')(`
25
+
26
+ ╰─────────────────────────────── ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
27
+ `)
28
+ );
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ import chalk from 'chalk';
4
+ console.log(chalk.hex('#ffd200')(`
5
+
6
+ ╭ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ──────────────────────────────╮`) + chalk.hex('#f26135')(`
7
+
8
+ Are you familiar with Auro's Definition of Done?
9
+
10
+ Please be sure to review`) + chalk.hex('#ffd200')(`
11
+ https://auro.alaskaair.com/definition-of-done`) + chalk.hex('#f26135')(`
12
+ before submitting your pull request
13
+ to ensure that you are compliant.`) + chalk.hex('#ffd200')(`
14
+
15
+ ╰─────────────────────────────── ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
16
+ `)
17
+ );
@@ -3,6 +3,8 @@
3
3
 
4
4
  // ---------------------------------------------------------------------
5
5
 
6
+ /* eslint-disable arrow-parens, line-comment-position, no-console, no-inline-comments, no-magic-numbers, prefer-arrow-callback, require-unicode-regexp, jsdoc/require-description-complete-sentence, prefer-named-capture-group */
7
+
6
8
  import * as fs from 'fs';
7
9
  import * as path from 'path';
8
10
  import chalk from 'chalk';
@@ -10,7 +12,7 @@ import chalk from 'chalk';
10
12
  export default class AuroLibraryUtils {
11
13
 
12
14
  /**
13
- * Copys and pastes all files in a source directory into a destination directory.
15
+ * Copies and pastes all files in a source directory into a destination directory.
14
16
  * @param {String} srcDir - File path of directory to copy from.
15
17
  * @param {String} destDir - File path of directory to paste files into.
16
18
  * @param {Boolean} removeFiles - If true, removes all files in destination directory before pasting files.
@@ -24,7 +26,7 @@ export default class AuroLibraryUtils {
24
26
  const destFiles = fs.readdirSync(destDir);
25
27
 
26
28
  let filesRemoved = 0;
27
-
29
+
28
30
  destFiles.forEach(file => {
29
31
  const filePath = path.join(destDir, file);
30
32
  fs.unlinkSync(filePath);
@@ -42,24 +44,24 @@ export default class AuroLibraryUtils {
42
44
  if (!fs.existsSync(destDir)) {
43
45
  fs.mkdirSync(destDir);
44
46
  }
45
-
47
+
46
48
  // All files from source directory
47
49
  const files = fs.readdirSync(srcDir);
48
-
49
- // Copys over all files from source directory to destination directory
50
+
51
+ // Copies over all files from source directory to destination directory
50
52
  files.forEach(file => {
51
53
  const sourceFilePath = path.join(srcDir, file);
52
54
  const destFilePath = path.join(destDir, file);
53
-
55
+
54
56
  const stat = fs.statSync(sourceFilePath);
55
-
57
+
56
58
  if (stat.isDirectory()) {
57
59
  this.copyDirectory(srcDir, destDir, removeFiles);
58
60
  } else {
59
61
  fs.copyFileSync(sourceFilePath, destFilePath);
60
62
 
61
63
  fs.readFile(destFilePath, 'utf8', (err, data) => {
62
- this.formatFileContents(data, destFilePath);
64
+ this.formatFileContents(data, destFilePath);
63
65
  });
64
66
 
65
67
  this.auroLogger(`Copied file: ${file}`, 'success');
@@ -69,7 +71,7 @@ export default class AuroLibraryUtils {
69
71
  }
70
72
 
71
73
  /**
72
- * Logs out messages in a readble format.
74
+ * Logs out messages in a readable format.
73
75
  * @param {String} message - Message to be logged.
74
76
  * @param {String} status - Status that determines the color of the logged message.
75
77
  * @param {Boolean} section - If true, adds a box around the message for readability.
@@ -80,7 +82,7 @@ export default class AuroLibraryUtils {
80
82
  const successColor = '#4CBB17'; // green
81
83
  const errorColor = '#ff0000'; // red
82
84
 
83
- let color = undefined;
85
+ let color = undefined; // eslint-disable-line no-undef-init
84
86
 
85
87
  if (status === 'info') {
86
88
  color = infoColor;
@@ -93,9 +95,9 @@ export default class AuroLibraryUtils {
93
95
  if (section) {
94
96
  console.log(chalk.hex(color)(`╭ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ──────────────────────────────╮\n`));
95
97
  }
96
-
98
+
97
99
  console.log(chalk.hex(color)(message));
98
-
100
+
99
101
  if (section) {
100
102
  console.log(chalk.hex(color)('\n╰─────────────────────────────── ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯'));
101
103
  }
@@ -103,9 +105,9 @@ export default class AuroLibraryUtils {
103
105
  if (section) {
104
106
  console.log(`╭ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ──────────────────────────────╮\n`);
105
107
  }
106
-
108
+
107
109
  console.log(message);
108
-
110
+
109
111
  if (section) {
110
112
  console.log(`\n╰─────────────────────────────── ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯`);
111
113
  }
@@ -114,7 +116,7 @@ export default class AuroLibraryUtils {
114
116
 
115
117
  /**
116
118
  * Extracts NPM VERSION, BRANCH NAME, NPM, NAMESPACE, and NAME from package.json.
117
- * @returns {Object} result - Object containing data from package.json.
119
+ * @returns {Object} result - Object containing data from package.json.
118
120
  */
119
121
  nameExtraction() {
120
122
  const packageJson = fs.readFileSync('package.json', 'utf8', function(err) {
@@ -122,14 +124,14 @@ export default class AuroLibraryUtils {
122
124
  console.log('ERROR: Unable to read package.json file', err);
123
125
  }
124
126
  });
125
-
127
+
126
128
  const pName = JSON.parse(packageJson).name;
127
-
128
- let npmStart = pName.indexOf('@');
129
- let namespaceStart = pName.indexOf('/');
130
- let nameStart = pName.indexOf('-');
131
-
132
- let result = {
129
+
130
+ const npmStart = pName.indexOf('@');
131
+ const namespaceStart = pName.indexOf('/');
132
+ const nameStart = pName.indexOf('-');
133
+
134
+ const result = {
133
135
  'abstractNodeVersion': JSON.parse(packageJson).engines.node.substring(2),
134
136
  'branchName': JSON.parse(packageJson).release.branch,
135
137
  'npm': pName.substring(npmStart, namespaceStart),
@@ -138,19 +140,22 @@ export default class AuroLibraryUtils {
138
140
  'name': pName.substring(nameStart + 1),
139
141
  'nameCap': pName.substring(nameStart + 1)[0].toUpperCase() + pName.substring(nameStart + 2)
140
142
  };
141
-
143
+
142
144
  return result;
143
145
  }
144
146
 
145
147
  /**
146
- * Replace all instances of [abstractNodeVersion], [branchName], [npm], [name], [Name], [namespace] and [Namespace] accordingly
148
+ * Replace all instances of [abstractNodeVersion], [branchName], [npm], [name], [Name], [namespace] and [Namespace] accordingly.
149
+ * @param {String} content - The content to be formatted.
150
+ * @param {String} destination - The location to write the formatted content.
151
+ * @returns {void}
147
152
  */
148
153
  formatFileContents(content, destination) {
149
- let nameExtractionData = this.nameExtraction();
154
+ const nameExtractionData = this.nameExtraction();
150
155
  let result = content;
151
156
 
152
157
  /**
153
- * Replace placeholder strings
158
+ * Replace placeholder strings.
154
159
  */
155
160
  result = result.replace(/\[abstractNodeVersion]/g, nameExtractionData.abstractNodeVersion);
156
161
  result = result.replace(/\[branchName]/g, nameExtractionData.branchName);
@@ -159,36 +164,20 @@ export default class AuroLibraryUtils {
159
164
  result = result.replace(/\[Name](?!\()/g, nameExtractionData.nameCap);
160
165
  result = result.replace(/\[namespace]/g, nameExtractionData.namespace);
161
166
  result = result.replace(/\[Namespace]/g, nameExtractionData.namespaceCap);
162
-
167
+
163
168
  /**
164
- * Cleanup line breaks
169
+ * Cleanup line breaks.
165
170
  */
166
171
  result = result.replace(/(\r\n|\r|\n)[\s]+(\r\n|\r|\n)/g, '\r\n\r\n'); // Replace lines containing only whitespace with a carriage return.
167
172
  result = result.replace(/>(\r\n|\r|\n){2,}/g, '>\r\n'); // Remove empty lines directly after a closing html tag.
168
173
  result = result.replace(/>(\r\n|\r|\n)```/g, '>\r\n\r\n```'); // Ensure an empty line before code samples.
169
174
  result = result.replace(/>(\r\n|\r|\n){2,}```(\r\n|\r|\n)/g, '>\r\n```\r\n'); // Ensure no empty lines before close of code sample.
170
175
  result = result.replace(/([^(\r\n|\r|\n)])(\r\n|\r|\n)+#/g, "$1\r\n\r\n#"); // Ensure empty line before header sections.
171
-
176
+
172
177
  /**
173
- * Write the result to the destination file
178
+ * Write the result to the destination file.
174
179
  */
175
180
  fs.writeFileSync(destination, result, { encoding: 'utf8'});
176
181
  }
177
-
178
- /**
179
- * Finds and returns the closest HTML Element based on a selector.
180
- */
181
- closestElement(
182
- selector, // selector like in .closest()
183
- base = this, // extra functionality to skip a parent
184
- __Closest = (el, found = el && el.closest(selector)) =>
185
- !el || el === document || el === window
186
- ? null // standard .closest() returns null for non-found selectors also
187
- : found
188
- ? found // found a selector INside this element
189
- : __Closest(el.getRootNode().host) // recursion!! break out to parent DOM
190
- ) {
191
- return __Closest(base);
192
- }
193
182
  }
194
183
 
@@ -0,0 +1,29 @@
1
+ // Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
2
+ // See LICENSE in the project root for license information.
3
+
4
+ // ---------------------------------------------------------------------
5
+
6
+ /* eslint-disable line-comment-position, no-inline-comments, no-confusing-arrow, no-nested-ternary, implicit-arrow-linebreak */
7
+
8
+ export default class AuroLibraryRuntimeUtils {
9
+
10
+ /* eslint-disable jsdoc/require-param */
11
+ /**
12
+ * Finds and returns the closest HTML Element based on a selector.
13
+ * @returns {void}
14
+ */
15
+ closestElement(
16
+ selector, // selector like in .closest()
17
+ base = this, // extra functionality to skip a parent
18
+ __Closest = (el, found = el && el.closest(selector)) =>
19
+ !el || el === document || el === window
20
+ ? null // standard .closest() returns null for non-found selectors also
21
+ : found
22
+ ? found // found a selector INside this element
23
+ : __Closest(el.getRootNode().host) // recursion!! break out to parent DOM
24
+ ) {
25
+ return __Closest(base);
26
+ }
27
+ /* eslint-enable jsdoc/require-param */
28
+ }
29
+