@aurodesignsystem/auro-library 2.4.7 → 2.5.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,18 @@
1
1
  # Semantic Release Automated Changelog
2
2
 
3
+ # [2.5.0](https://github.com/AlaskaAirlines/auro-library/compare/v2.4.7...v2.5.0) (2024-02-07)
4
+
5
+
6
+ ### Features
7
+
8
+ * add alt generator ([4bb0207](https://github.com/AlaskaAirlines/auro-library/commit/4bb0207a47a80230954c876647115f47dc9cdfb4))
9
+ * add support for scrapping package.json ([551b407](https://github.com/AlaskaAirlines/auro-library/commit/551b4071ea407d5d5db68037fb63b1874161a35d))
10
+
11
+
12
+ ### Performance Improvements
13
+
14
+ * update to support index.md ([87634f6](https://github.com/AlaskaAirlines/auro-library/commit/87634f62a76a1923e3584bc9c7b98c673f663755))
15
+
3
16
  ## [2.4.7](https://github.com/AlaskaAirlines/auro-library/compare/v2.4.6...v2.4.7) (2024-02-07)
4
17
 
5
18
 
@@ -0,0 +1,210 @@
1
+ import path from 'path';
2
+ import markdownMagic from 'markdown-magic';
3
+ import fs from 'fs';
4
+ import https from 'https';
5
+
6
+ const __dirname = new URL('.', import.meta.url).pathname;
7
+
8
+ const readmeTemplateUrl = 'https://raw.githubusercontent.com/AlaskaAirlines/WC-Generator/master/componentDocs/README.md';
9
+ const dirDocTemplates = './docTemplates';
10
+ const readmeFilePath = dirDocTemplates + '/README.md';
11
+
12
+ /**
13
+ * Extract NPM, NAMESPACE and NAME from package.json
14
+ */
15
+
16
+ function nameExtraction() {
17
+ const packageJson = fs.readFileSync('package.json', 'utf8', function(err, data) {
18
+ if (err) {
19
+ console.log('ERROR: Unable to read package.json file', err);
20
+ }
21
+ })
22
+
23
+ let pName = JSON.parse(packageJson).name;
24
+ let pVersion = JSON.parse(packageJson).version;
25
+ let pdtVersion = JSON.parse(packageJson).peerDependencies['\@aurodesignsystem/design-tokens'].substring(1)
26
+ let wcssVersion = JSON.parse(packageJson).peerDependencies['\@aurodesignsystem/webcorestylesheets'].substring(1)
27
+
28
+ let npmStart = pName.indexOf('@');
29
+ let namespaceStart = pName.indexOf('/');
30
+ let nameStart = pName.indexOf('-');
31
+
32
+ let result = {
33
+ 'npm': pName.substring(npmStart, namespaceStart),
34
+ 'namespace': pName.substring(namespaceStart + 1, nameStart),
35
+ 'namespaceCap': pName.substring(namespaceStart + 1)[0].toUpperCase() + pName.substring(namespaceStart + 2, nameStart),
36
+ 'name': pName.substring(nameStart + 1),
37
+ 'nameCap': pName.substring(nameStart + 1)[0].toUpperCase() + pName.substring(nameStart + 2),
38
+ 'version': pVersion,
39
+ 'tokensVersion': pdtVersion,
40
+ 'wcssVersion': wcssVersion
41
+ };
42
+
43
+ return result;
44
+ }
45
+
46
+ /**
47
+ * Replace all instances of [npm], [name], [Name], [namespace] and [Namespace] accordingly
48
+ */
49
+
50
+ function formatTemplateFileContents(content, destination) {
51
+ let nameExtractionData = nameExtraction();
52
+ let result = content;
53
+
54
+ /**
55
+ * Replace placeholder strings
56
+ */
57
+ result = result.replace(/\[npm]/g, nameExtractionData.npm);
58
+ result = result.replace(/\[name](?!\()/g, nameExtractionData.name);
59
+ result = result.replace(/\[Name](?!\()/g, nameExtractionData.nameCap);
60
+ result = result.replace(/\[namespace]/g, nameExtractionData.namespace);
61
+ result = result.replace(/\[Namespace]/g, nameExtractionData.namespaceCap);
62
+ result = result.replace(/\[Version]/g, nameExtractionData.version);
63
+ result = result.replace(/\[dtVersion]/g, nameExtractionData.tokensVersion);
64
+ result = result.replace(/\[wcssVersion]/g, nameExtractionData.wcssVersion);
65
+
66
+ /**
67
+ * Cleanup line breaks
68
+ */
69
+ 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.
70
+ result = result.replace(/>(\r\n|\r|\n){2,}/g, '>\r\n'); // Remove empty lines directly after a closing html tag.
71
+ result = result.replace(/>(\r\n|\r|\n)```/g, '>\r\n\r\n```'); // Ensure an empty line before code samples.
72
+ 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.
73
+ result = result.replace(/([^(\r\n|\r|\n)])(\r?\n|\r(?!\n))+#/g, "$1\r\n\r\n#"); // Ensure empty line before header sections.
74
+
75
+ /**
76
+ * Write the result to the destination file
77
+ */
78
+ fs.writeFileSync(destination, result, { encoding: 'utf8'});
79
+ }
80
+
81
+ function formatApiTableContents(content, destination) {
82
+ const nameExtractionData = nameExtraction();
83
+ const wcName = nameExtractionData.namespace + '-' + nameExtractionData.name;
84
+
85
+ let result = content;
86
+
87
+ result = result
88
+ .replace(/\r\n|\r|\n####\s`([a-zA-Z]*)`/g, `\r\n#### <a name="$1"></a>\`$1\`<a href="#" style="float: right; font-size: 1rem; font-weight: 100;">back to top</a>`)
89
+ .replace(/\r\n|\r|\n\|\s`([a-zA-Z]*)`/g, '\r\n| [$1](#$1)')
90
+ .replace(/\| \[\]\(#\)/g, "");
91
+
92
+ fs.writeFileSync(destination, result, { encoding: 'utf8'});
93
+
94
+ fs.readFile('./demo/apiExamples.md', 'utf8', function(err, data) {
95
+ formatTemplateFileContents(data, './demo/apiExamples.md');
96
+ });
97
+ }
98
+
99
+ /**
100
+ * Compiles `./docTemplates/README.md` -> `./README.md`
101
+ */
102
+
103
+ function processReadme() {
104
+ const callback = function(updatedContent, outputConfig) {
105
+
106
+ if (fs.existsSync('./README.md')) {
107
+ fs.readFile('./README.md', 'utf8', function(err, data) {
108
+ formatTemplateFileContents(data, './README.md');
109
+ });
110
+ } else {
111
+ console.log('ERROR: ./README.md file is missing');
112
+ }
113
+ };
114
+
115
+ const config = {
116
+ matchWord: 'AURO-GENERATED-CONTENT',
117
+ outputDir: './'
118
+ };
119
+
120
+ const markdownPath = path.join(__dirname, '../docTemplates/README.md');
121
+
122
+ markdownMagic(markdownPath, config, callback);
123
+ }
124
+
125
+ /**
126
+ * Compiles `./docTemplates/demo.md` -> `./demo/index.md`
127
+ */
128
+
129
+ function processDemo() {
130
+ const callback = function(updatedContent, outputConfig) {
131
+ if (fs.existsSync('./demo/index.md')) {
132
+ fs.readFile('./demo/index.md', 'utf8', function(err, data) {
133
+ formatTemplateFileContents(data, './demo/index.md');
134
+ });
135
+ } else {
136
+ console.log('ERROR: ./demo/index.md file is missing');
137
+ }
138
+ };
139
+
140
+ const configDemo = {
141
+ matchWord: 'AURO-GENERATED-CONTENT',
142
+ outputDir: './demo'
143
+ };
144
+
145
+ const markdownPath = path.join(__dirname, '../docs/partials/demo.md');
146
+
147
+ markdownMagic(markdownPath, configDemo, callback);
148
+ }
149
+
150
+ /**
151
+ * Compiles `./docTemplates/apiExamples.md` -> `./demo/apiExamples.md`
152
+ */
153
+
154
+ function processApiExamples() {
155
+ const callback = function(updatedContent, outputConfig) {
156
+ if (fs.existsSync('./demo/apiExamples.md')) {
157
+ fs.readFile('./demo/apiExamples.md', 'utf8', function(err, data) {
158
+ formatApiTableContents(data, './demo/apiExamples.md');
159
+ });
160
+ } else {
161
+ console.log('ERROR: ./demo/apiExamples.md file is missing');
162
+ }
163
+ };
164
+
165
+ const config = {
166
+ matchWord: 'AURO-GENERATED-CONTENT',
167
+ outputDir: './demo'
168
+ };
169
+
170
+ const markdownPath = path.join(__dirname, '../docs/partials/apiExamples.md');
171
+
172
+ markdownMagic(markdownPath, config, callback);
173
+ }
174
+
175
+ /**
176
+ * Copy README.md template from static source
177
+ * */
178
+
179
+ function copyReadmeLocally() {
180
+
181
+ if (!fs.existsSync(dirDocTemplates)){
182
+ fs.mkdirSync(dirDocTemplates);
183
+ }
184
+
185
+ if (!fs.existsSync(readmeFilePath)) {
186
+ fs.writeFile(readmeFilePath, '', function(err) {
187
+ if(err) {
188
+ console.log('ERROR: Unable to create README.md file.', err);
189
+ }
190
+ });
191
+ }
192
+
193
+ https.get(readmeTemplateUrl, function(response) {
194
+ let writeTemplate = response.pipe(fs.createWriteStream(readmeFilePath));
195
+
196
+ writeTemplate.on('finish', () => {
197
+ processReadme();
198
+ });
199
+
200
+ }).on('error', (err) => {
201
+ console.log('ERROR: Unable to fetch README.md file from server.', err);
202
+ });
203
+ }
204
+
205
+ /**
206
+ * Run all the actual document generation
207
+ */
208
+ copyReadmeLocally();
209
+ processApiExamples();
210
+ processDemo();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aurodesignsystem/auro-library",
3
- "version": "2.4.7",
3
+ "version": "2.5.0",
4
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",
@@ -58,17 +58,17 @@ function processReadme() {
58
58
  }
59
59
 
60
60
  /**
61
- * Compiles `./docTemplates/demo.md` -> `./demo/demo.md`
61
+ * Compiles `./docTemplates/demo.md` -> `./demo/index.md`
62
62
  */
63
63
 
64
64
  function processDemo() {
65
65
  const callback = function() {
66
- if (fs.existsSync('./demo/demo.md')) {
67
- fs.readFile('./demo/demo.md', 'utf8', function(err, data) {
68
- auroLibraryUtils.formatFileContents(data, './demo/demo.md');
66
+ if (fs.existsSync('./demo/index.md')) {
67
+ fs.readFile('./demo/index.md', 'utf8', function(err, data) {
68
+ auroLibraryUtils.formatFileContents(data, './demo/index.md');
69
69
  });
70
70
  } else {
71
- console.log('ERROR: ./demo/demo.md file is missing');
71
+ console.log('ERROR: ./demo/index.md file is missing');
72
72
  }
73
73
  };
74
74
 
@@ -138,7 +138,10 @@ export default class AuroLibraryUtils {
138
138
  'namespace': pName.substring(namespaceStart + 1, nameStart),
139
139
  'namespaceCap': pName.substring(namespaceStart + 1)[0].toUpperCase() + pName.substring(namespaceStart + 2, nameStart),
140
140
  'name': pName.substring(nameStart + 1),
141
- 'nameCap': pName.substring(nameStart + 1)[0].toUpperCase() + pName.substring(nameStart + 2)
141
+ 'nameCap': pName.substring(nameStart + 1)[0].toUpperCase() + pName.substring(nameStart + 2),
142
+ 'version': pVersion,
143
+ 'tokensVersion': pdtVersion,
144
+ 'wcssVersion': wcssVersion
142
145
  };
143
146
 
144
147
  return result;
@@ -164,6 +167,9 @@ export default class AuroLibraryUtils {
164
167
  result = result.replace(/\[Name](?!\()/g, nameExtractionData.nameCap);
165
168
  result = result.replace(/\[namespace]/g, nameExtractionData.namespace);
166
169
  result = result.replace(/\[Namespace]/g, nameExtractionData.namespaceCap);
170
+ result = result.replace(/\[Version]/g, nameExtractionData.version);
171
+ result = result.replace(/\[dtVersion]/g, nameExtractionData.tokensVersion);
172
+ result = result.replace(/\[wcssVersion]/g, nameExtractionData.wcssVersion);
167
173
 
168
174
  /**
169
175
  * Cleanup line breaks.