Skip to content

Commit

Permalink
docs: update to show accurate deps versions
Browse files Browse the repository at this point in the history
Changes to be committed:
modified:   README.md
modified:   docTemplates/README.md
modified:   package-lock.json
modified:   package.json
modified:   scripts/generateDocs.mjs
  • Loading branch information
blackfalcon committed Feb 7, 2024
1 parent 50314c5 commit 70e7420
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 57 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,18 @@ import "@aurodesignsystem/auro-background";
<!-- AURO-GENERATED-CONTENT:START (REMOTE:url=https://raw.githubusercontent.com/AlaskaAirlines/WC-Generator/master/componentDocs/partials/usage/bundleInstallDescription.md) -->
In cases where the project is not able to process JS assets, there are pre-processed assets available for use. See -- `auro-background__bundled.js` for modern browsers. Legacy browsers such as IE11 are no longer supported.

We recommend you load these bundles using [differential serving](https://philipwalton.com/articles/deploying-es2015-code-in-production-today/) so that the browser only loads the bundle correctly. To accomplish this, the script tag for the modern bundle should have `type="module"` and the script tag.
**WARNING!** When installing into your application environment, DO NOT use `@latest` for the requested version. Risks include unknown MAJOR version releases and instant adoption of any new features and possible bugs without developer knowledge. The `@latest` wildcard should NEVER be used for production customer-facing applications. You have been warned.

<!-- AURO-GENERATED-CONTENT:END -->

### Bundle example code

<!-- AURO-GENERATED-CONTENT:START (REMOTE:url=https://raw.githubusercontent.com/AlaskaAirlines/WC-Generator/master/componentDocs/partials/usage/bundleUse.md) -->
<!-- AURO-GENERATED-CONTENT:START (REMOTE:url=https://raw.githubusercontent.com/AlaskaAirlines/WC-Generator/master/componentDocs/partials/usage/bundleUseModBrowsers.md) -->

```html
<!-- **NOTE:** Be sure to replace `@latest` in the URL with the version of the asset you want. @latest is NOT aware of any MAJOR releases, use at your own risk. -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/design-tokens@latest/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/webcorestylesheets@latest/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-background@latest/dist/auro-background__bundled.js" type="module"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/design-tokens@4.3.0/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/webcorestylesheets@5.0.5/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-background@2.1.1/dist/auro-background__bundled.js" type="module"></script>
```

<!-- AURO-GENERATED-CONTENT:END -->
Expand Down
2 changes: 1 addition & 1 deletion docTemplates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ The following sections are editable by making changes to the following files:

### Bundle example code

<!-- AURO-GENERATED-CONTENT:START (REMOTE:url=https://raw.githubusercontent.com/AlaskaAirlines/WC-Generator/master/componentDocs/partials/usage/bundleUse.md) -->
<!-- AURO-GENERATED-CONTENT:START (REMOTE:url=https://raw.githubusercontent.com/AlaskaAirlines/WC-Generator/master/componentDocs/partials/usage/bundleUseModBrowsers.md) -->
<!-- AURO-GENERATED-CONTENT:END -->

## [namespace]-[name] use cases
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@aurodesignsystem/webcorestylesheets": "^5.0.5"
},
"devDependencies": {
"@aurodesignsystem/auro-library": "^2.4.0",
"@aurodesignsystem/auro-library": "^2.4.7",
"@aurodesignsystem/design-tokens": "^4.3.1",
"@aurodesignsystem/eslint-config": "^1.3.1",
"@aurodesignsystem/webcorestylesheets": "^5.0.6",
Expand Down
94 changes: 49 additions & 45 deletions scripts/generateDocs.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* This version is sans dependencies
* Create for use with the SSR updates
*/

import path from 'path';
import markdownMagic from 'markdown-magic';
import fs from 'fs';
Expand All @@ -19,28 +14,34 @@ const readmeFilePath = dirDocTemplates + '/README.md';
*/

function nameExtraction() {
const packageJson = fs.readFileSync('package.json', 'utf8', function(err, data) {
if (err) {
console.log('ERROR: Unable to read package.json file', err);
}
})

let pName = JSON.parse(packageJson).name;

let npmStart = pName.indexOf('@');
let namespaceStart = pName.indexOf('/');
let nameStart = pName.indexOf('-');

let result = {
'npm': pName.substring(npmStart, namespaceStart),
'namespace': pName.substring(namespaceStart + 1, nameStart),
'namespaceCap': pName.substring(namespaceStart + 1)[0].toUpperCase() + pName.substring(namespaceStart + 2, nameStart),
'name': pName.substring(nameStart + 1),
'nameCap': pName.substring(nameStart + 1)[0].toUpperCase() + pName.substring(nameStart + 2)
};

return result;
}
const packageJson = fs.readFileSync('package.json', 'utf8', function(err, data) {
if (err) {
console.log('ERROR: Unable to read package.json file', err);
}
})

let pName = JSON.parse(packageJson).name;
let pVersion = JSON.parse(packageJson).version;
let pdtVersion = JSON.parse(packageJson).peerDependencies['\@aurodesignsystem/design-tokens'].substring(1)
let wcssVersion = JSON.parse(packageJson).peerDependencies['\@aurodesignsystem/webcorestylesheets'].substring(1)

let npmStart = pName.indexOf('@');
let namespaceStart = pName.indexOf('/');
let nameStart = pName.indexOf('-');

let result = {
'npm': pName.substring(npmStart, namespaceStart),
'namespace': pName.substring(namespaceStart + 1, nameStart),
'namespaceCap': pName.substring(namespaceStart + 1)[0].toUpperCase() + pName.substring(namespaceStart + 2, nameStart),
'name': pName.substring(nameStart + 1),
'nameCap': pName.substring(nameStart + 1)[0].toUpperCase() + pName.substring(nameStart + 2),
'version': pVersion,
'tokensVersion': pdtVersion,
'wcssVersion': wcssVersion
};

return result;
}

/**
* Replace all instances of [npm], [name], [Name], [namespace] and [Namespace] accordingly
Expand All @@ -54,10 +55,13 @@ function formatTemplateFileContents(content, destination) {
* Replace placeholder strings
*/
result = result.replace(/\[npm]/g, nameExtractionData.npm);
result = result.replace(/\[name]/g, nameExtractionData.name);
result = result.replace(/\[Name]/g, nameExtractionData.nameCap);
result = result.replace(/\[name](?!\()/g, nameExtractionData.name);
result = result.replace(/\[Name](?!\()/g, nameExtractionData.nameCap);
result = result.replace(/\[namespace]/g, nameExtractionData.namespace);
result = result.replace(/\[Namespace]/g, nameExtractionData.namespaceCap);
result = result.replace(/\[Version]/g, nameExtractionData.version);
result = result.replace(/\[dtVersion]/g, nameExtractionData.tokensVersion);
result = result.replace(/\[wcssVersion]/g, nameExtractionData.wcssVersion);

/**
* Cleanup line breaks
Expand All @@ -66,7 +70,7 @@ function formatTemplateFileContents(content, destination) {
result = result.replace(/>(\r\n|\r|\n){2,}/g, '>\r\n'); // Remove empty lines directly after a closing html tag.
result = result.replace(/>(\r\n|\r|\n)```/g, '>\r\n\r\n```'); // Ensure an empty line before code samples.
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.
result = result.replace(/([^(\r\n|\r|\n)])(\r\n|\r|\n)+#/g, "$1\r\n\r\n#"); // Ensure empty line before header sections.
result = result.replace(/([^(\r\n|\r|\n)])(\r?\n|\r(?!\n))+#/g, "$1\r\n\r\n#"); // Ensure empty line before header sections.

/**
* Write the result to the destination file
Expand All @@ -81,14 +85,14 @@ function formatApiTableContents(content, destination) {
let result = content;

result = result
.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>`)
.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>`)
.replace(/\r\n|\r|\n\|\s`([a-zA-Z]*)`/g, '\r\n| [$1](#$1)')
.replace(/\| \[\]\(#\)/g, "");

fs.writeFileSync(destination, result, { encoding: 'utf8'});

fs.readFile('./demo/api.md', 'utf8', function(err, data) {
formatTemplateFileContents(data, './demo/api.md');
fs.readFile('./demo/apiExamples.md', 'utf8', function(err, data) {
formatTemplateFileContents(data, './demo/apiExamples.md');
});
}

Expand Down Expand Up @@ -119,17 +123,17 @@ function processReadme() {
}

/**
* Compiles `../docs/partials/index.md` -> `./demo/index.md`
* Compiles `./docTemplates/demo.md` -> `./demo/demo.md`
*/

function processDemo() {
const callback = function(updatedContent, outputConfig) {
if (fs.existsSync('./demo/index.md')) {
fs.readFile('./demo/index.md', 'utf8', function(err, data) {
formatTemplateFileContents(data, './demo/index.md');
if (fs.existsSync('./demo/demo.md')) {
fs.readFile('./demo/demo.md', 'utf8', function(err, data) {
formatTemplateFileContents(data, './demo/demo.md');
});
} else {
console.log('ERROR: ./demo/index.md file is missing');
console.log('ERROR: ./demo/demo.md file is missing');
}
};

Expand All @@ -138,23 +142,23 @@ function processDemo() {
outputDir: './demo'
};

const markdownPath = path.join(__dirname, '../docs/partials/index.md');
const markdownPath = path.join(__dirname, '../docs/partials/demo.md');

markdownMagic(markdownPath, configDemo, callback);
}

/**
* Compiles `../docs/partials/api.md` -> `./demo/api.md`
* Compiles `./docTemplates/apiExamples.md` -> `./demo/apiExamples.md`
*/

function processApiExamples() {
const callback = function(updatedContent, outputConfig) {
if (fs.existsSync('./demo/api.md')) {
fs.readFile('./demo/api.md', 'utf8', function(err, data) {
formatApiTableContents(data, './demo/api.md');
if (fs.existsSync('./demo/apiExamples.md')) {
fs.readFile('./demo/apiExamples.md', 'utf8', function(err, data) {
formatApiTableContents(data, './demo/apiExamples.md');
});
} else {
console.log('ERROR: ./demo/api.md file is missing');
console.log('ERROR: ./demo/apiExamples.md file is missing');
}
};

Expand All @@ -163,7 +167,7 @@ function processApiExamples() {
outputDir: './demo'
};

const markdownPath = path.join(__dirname, '../docs/partials/api.md');
const markdownPath = path.join(__dirname, '../docs/partials/apiExamples.md');

markdownMagic(markdownPath, config, callback);
}
Expand Down

0 comments on commit 70e7420

Please sign in to comment.