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