@aurodesignsystem/auro-library 1.0.2 → 2.0.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 +33 -0
- package/README.md +202 -2
- package/componentTemplates/workflows/autoAssign.yml +9 -0
- package/componentTemplates/workflows/codeql.yml +58 -0
- package/componentTemplates/workflows/demo.yml +11 -0
- package/componentTemplates/workflows/testPublish.yml +46 -0
- package/package.json +13 -9
- package/scripts/build/generateDocs.mjs +145 -0
- package/scripts/build/generateReadme.mjs +60 -0
- package/scripts/utils/auroLibraryUtils.mjs +178 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# Semantic Release Automated Changelog
|
|
2
2
|
|
|
3
|
+
# [2.0.0](https://github.com/AlaskaAirlines/auro-library/compare/v1.1.0...v2.0.0) (2023-10-05)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Performance Improvements
|
|
7
|
+
|
|
8
|
+
* **npmignore:** include scripts/config/ directory [#38](https://github.com/AlaskaAirlines/auro-library/issues/38) ([e4e1a75](https://github.com/AlaskaAirlines/auro-library/commit/e4e1a7526765cc828d6124c71853d8cb9e9d3f6f))
|
|
9
|
+
* **scripts:** update directory file for config scripts [#38](https://github.com/AlaskaAirlines/auro-library/issues/38) ([8167f2f](https://github.com/AlaskaAirlines/auro-library/commit/8167f2f5521a22145419d9f7cd8f5e5c4ba5dd80))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### BREAKING CHANGES
|
|
13
|
+
|
|
14
|
+
* **scripts:** The automation scripts directory name has been changed from "setup" to "config".
|
|
15
|
+
|
|
16
|
+
# [1.1.0](https://github.com/AlaskaAirlines/auro-library/compare/v1.0.2...v1.1.0) (2023-08-31)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* **err:** update parameter handling ([04af13a](https://github.com/AlaskaAirlines/auro-library/commit/04af13a315ebb35795fe7b6c162373d7b9c5d3b3))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Features
|
|
25
|
+
|
|
26
|
+
* **automation:** add automation scripts for workflows and linters [#32](https://github.com/AlaskaAirlines/auro-library/issues/32) ([5dff1b7](https://github.com/AlaskaAirlines/auro-library/commit/5dff1b7dcbe2d7862b4994399f40781037b48d69))
|
|
27
|
+
* **surge:** add workflow that deploys surge demo [#35](https://github.com/AlaskaAirlines/auro-library/issues/35) ([7117212](https://github.com/AlaskaAirlines/auro-library/commit/71172129d0309e132821f1bcb5d8673baa746468))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Performance Improvements
|
|
31
|
+
|
|
32
|
+
* **.npmignore:** update .npmignore ([2de9db7](https://github.com/AlaskaAirlines/auro-library/commit/2de9db717b6e069a8ffb6b6e067a83b08c41d8c6))
|
|
33
|
+
* **docs:** add generateDocs script [#36](https://github.com/AlaskaAirlines/auro-library/issues/36) ([9746820](https://github.com/AlaskaAirlines/auro-library/commit/97468201ca83767b3cc1dd1396e0d78f311a69f5))
|
|
34
|
+
* **extraction:** extract functions and insert into library utils [#36](https://github.com/AlaskaAirlines/auro-library/issues/36) ([c3018eb](https://github.com/AlaskaAirlines/auro-library/commit/c3018eb01acf4b3682b63b0b92c3beb5b3641161))
|
|
35
|
+
|
|
3
36
|
## [1.0.2](https://github.com/AlaskaAirlines/auro-library/compare/v1.0.1...v1.0.2) (2023-07-24)
|
|
4
37
|
|
|
5
38
|
|
package/README.md
CHANGED
|
@@ -1,3 +1,203 @@
|
|
|
1
|
-
# Auro
|
|
1
|
+
# Auro-Library
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../docs/partials/description.md) -->
|
|
4
|
+
<!-- The below content is automatically added from ./../docs/partials/description.md -->
|
|
5
|
+
This repository holds shared scripts, utilities, and workflows utilized acorss repositories along the Auro Design System.
|
|
6
|
+
<!-- AURO-GENERATED-CONTENT:END -->
|
|
7
|
+
|
|
8
|
+
## Scripts
|
|
9
|
+
|
|
10
|
+
#### Publish Surge Demo
|
|
11
|
+
|
|
12
|
+
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../docs/partials/description.md) -->
|
|
13
|
+
<!-- The below content is automatically added from ./../docs/partials/description.md -->
|
|
14
|
+
This repository holds shared scripts, utilities, and workflows utilized acorss repositories along the Auro Design System.
|
|
15
|
+
<!-- AURO-GENERATED-CONTENT:END -->
|
|
16
|
+
|
|
17
|
+
#### Surge Demo Teardown
|
|
18
|
+
|
|
19
|
+
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../docs/partials/demoTeardown.md) -->
|
|
20
|
+
<!-- The below content is automatically added from ./../docs/partials/demoTeardown.md -->
|
|
21
|
+
|
|
22
|
+
## Dependency Tag Versioming
|
|
23
|
+
|
|
24
|
+
This workflow works to automatically delete and clear any surge demos that have been active for more than 2+ months. Surge in theory allows us to have an infinite amount of active pages but by clearing unused and stale demos we can keep our Surge account more organized in the future.
|
|
25
|
+
|
|
26
|
+
> Note: This workflow exectutes on a monthly cronjob on the first of each month.
|
|
27
|
+
|
|
28
|
+
In order to clear all our surge projects we rely on [this GitHub Action](https://github.com/marketplace/actions/surge-sh-teardown) to handle the deletion logic.
|
|
29
|
+
<!-- AURO-GENERATED-CONTENT:END -->
|
|
30
|
+
|
|
31
|
+
#### Dependency Tag Versioning
|
|
32
|
+
|
|
33
|
+
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../docs/partials/dependencyTagVersioning.md) -->
|
|
34
|
+
<!-- The below content is automatically added from ./../docs/partials/dependencyTagVersioning.md -->
|
|
35
|
+
|
|
36
|
+
## Dependency Tag Versioming
|
|
37
|
+
|
|
38
|
+
This is a two part utility for the purpose of generating a custom string for dependency component tag naming. This is important to prevent [version conflicts](https://www.thinktecture.com/en/web-components/web-components-flaws/#elementor-toc__heading-anchor-0) when multiple versions of a given Auro component may be loaded on a single page.
|
|
39
|
+
|
|
40
|
+
_Note: The example configuration used below in all code samples assumes `auro-dropdown` is the dependency component. Substitute any Auro component in the example code as needed._
|
|
41
|
+
|
|
42
|
+
### Part 1: The Build
|
|
43
|
+
|
|
44
|
+
#### Configuration
|
|
45
|
+
|
|
46
|
+
1. Create a new file `./scripts/version.js` with the following content:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
const versionWriter = require("./versionWriter"); // need to update this with the right path when used from node_modules
|
|
50
|
+
|
|
51
|
+
versionWriter.writeDepVersionFile('@aurodesignsystem/auro-dropdown'); // duplicate this line for each Auro dependency.
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
2. Add the following script to the component `package.json` file:
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
"build:version": "node scripts/version.js"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
3. The `build:version` script in `package.json` should be added as the first step of the `build` script.
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
"build": "npm-run-all build:version ... etc.",
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### Execution
|
|
67
|
+
|
|
68
|
+
Once configuration is complete, execute `npm run build`. This must be done once before `npm run dev` when developing locally. When Auro dependencies are initially installed or updated to new versions then `npm run build:version` or a complete `npm run build` must be executed.
|
|
69
|
+
|
|
70
|
+
Upon execution of `build:version`, for each Auro dependency defined in the `./scripts/version.js` file, a new JS file will be created that contains the installed version of the dependency.
|
|
71
|
+
|
|
72
|
+
For example, following these steps:
|
|
73
|
+
1. Run `npm i @aurodesignsystem/auro-dropdown@1.0.0`
|
|
74
|
+
1. add the following to the `./scripts/version.js` script file:
|
|
75
|
+
```js
|
|
76
|
+
versionWriter.writeDepVersionFile('@aurodesignsystem/auro-dropdown');
|
|
77
|
+
```
|
|
78
|
+
1. Run `npm run build`
|
|
79
|
+
|
|
80
|
+
Will result in:
|
|
81
|
+
- A new file created: `./src/dropdownVersion.js`
|
|
82
|
+
- File content will export the version of the component installed. In this case:
|
|
83
|
+
`export default '1.0.0'`
|
|
84
|
+
|
|
85
|
+
### Part 2: The Runtime
|
|
86
|
+
|
|
87
|
+
#### Configuration
|
|
88
|
+
|
|
89
|
+
In the main component JS file located in the `./src` directory add the following:
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
import { AuroDependencyVersioning } from "../scripts/dependencyTagVersioning.mjs";
|
|
93
|
+
import { AuroDropdown } from '@aurodesignsystem/auro-dropdown/src/auro-dropdown.js';
|
|
94
|
+
import dropdownVersion from './dropdownVersion';
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
In the components constructor add the following:
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
const versioning = new AuroDependencyVersioning();
|
|
101
|
+
this.dropdownTag = versioning.generateTag('auro-dropdown', dropdownVersion, AuroDropdown);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
In the component properties add the following:
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
/**
|
|
108
|
+
* @private
|
|
109
|
+
*/
|
|
110
|
+
dropdownTag: { type: Object }
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### Usage
|
|
114
|
+
|
|
115
|
+
The new dynamically named version of `auro-dropdown` may now be used in your component template as follows:
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
render() {
|
|
119
|
+
return html`
|
|
120
|
+
<div>
|
|
121
|
+
<${this.dropdownTag}></${this.dropdownTag}>
|
|
122
|
+
</div>
|
|
123
|
+
`;
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
When the component is rendered during runtime the DOM will now show up as follows:
|
|
128
|
+
|
|
129
|
+
```html
|
|
130
|
+
<div>
|
|
131
|
+
<auro-dropdown_1_0_0></auro-dropdown_1_0_0>
|
|
132
|
+
</div>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
_Note: the numbers attached in the tag name will match the version of the dependency that was installed._
|
|
136
|
+
|
|
137
|
+
#### Accessing the dynamically named element with JS
|
|
138
|
+
|
|
139
|
+
The dynamic component is accessible using a the following string in a JS query selector: `this.dropdownTag._$litStatic# Auro-Library
|
|
140
|
+
|
|
141
|
+
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../docs/partials/description.md) -->
|
|
142
|
+
<!-- The below content is automatically added from ./../docs/partials/description.md -->
|
|
143
|
+
This repository holds shared scripts, utilities, and workflows utilized acorss repositories along the Auro Design System.
|
|
144
|
+
<!-- AURO-GENERATED-CONTENT:END -->
|
|
145
|
+
|
|
146
|
+
## Scripts
|
|
147
|
+
|
|
148
|
+
#### Publish Surge Demo
|
|
149
|
+
|
|
150
|
+
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../docs/partials/description.md) -->
|
|
151
|
+
<!-- The below content is automatically added from ./../docs/partials/description.md -->
|
|
152
|
+
This repository holds shared scripts, utilities, and workflows utilized acorss repositories along the Auro Design System.
|
|
153
|
+
<!-- AURO-GENERATED-CONTENT:END -->
|
|
154
|
+
|
|
155
|
+
#### Surge Demo Teardown
|
|
156
|
+
|
|
157
|
+
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../docs/partials/demoTeardown.md) -->
|
|
158
|
+
<!-- The below content is automatically added from ./../docs/partials/demoTeardown.md -->
|
|
159
|
+
|
|
160
|
+
## Dependency Tag Versioming
|
|
161
|
+
|
|
162
|
+
This workflow works to automatically delete and clear any surge demos that have been active for more than 2+ months. Surge in theory allows us to have an infinite amount of active pages but by clearing unused and stale demos we can keep our Surge account more organized in the future.
|
|
163
|
+
|
|
164
|
+
> Note: This workflow exectutes on a monthly cronjob on the first of each month.
|
|
165
|
+
|
|
166
|
+
In order to clear all our surge projects we rely on [this GitHub Action](https://github.com/marketplace/actions/surge-sh-teardown) to handle the deletion logic.
|
|
167
|
+
<!-- AURO-GENERATED-CONTENT:END -->
|
|
168
|
+
|
|
169
|
+
#### Dependency Tag Versioning
|
|
170
|
+
|
|
171
|
+
```js
|
|
172
|
+
firstUpdated() {
|
|
173
|
+
this.dropdown = this.shadowRoot.querySelector(this.dropdownTag._$litStatic$);
|
|
174
|
+
};
|
|
175
|
+
```
|
|
176
|
+
<!-- AURO-GENERATED-CONTENT:END -->
|
|
177
|
+
|
|
178
|
+
#### Sync All Templates
|
|
179
|
+
|
|
180
|
+
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../docs/partials/syncAllTemplates.md) -->
|
|
181
|
+
<!-- The below content is automatically added from ./../docs/partials/syncAllTemplates.md -->
|
|
182
|
+
|
|
183
|
+
## How to Run the `syncAllTemplates.mjs` Script
|
|
184
|
+
|
|
185
|
+
To run the `syncAllTemplates.mjs` script, you will need to add a new node script into the linked component and point that to the `syncAllTemplates.mjs` file. You can individually run the workflow configurations by pointing to the `syncAllTemplates.mjs` file and adding a `--github` parameter after the path. The same can be done for the linter configurations by adding a `--linters` parameter.
|
|
186
|
+
|
|
187
|
+
### Example Calls
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
// Default
|
|
191
|
+
"syncTemplates": "./node_modules/@aurodesignsystem/auro-library/scripts/config/syncAllTemplates.mjs"
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
// Only sync github workflow templates
|
|
196
|
+
"syncTemplates": "./node_modules/@aurodesignsystem/auro-library/scripts/config/syncAllTemplates.mjs --github"
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
// Only sync linter configuration templates
|
|
201
|
+
"syncTemplates": "./node_modules/@aurodesignsystem/auro-library/scripts/config/syncAllTemplates.mjs --linters"
|
|
202
|
+
```
|
|
203
|
+
<!-- AURO-GENERATED-CONTENT:END -->
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
name: "CodeQL"
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ [branchName] ]
|
|
6
|
+
pull_request:
|
|
7
|
+
# The branches below must be a subset of the branches above
|
|
8
|
+
branches: [ [branchName] ]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
analyze:
|
|
12
|
+
name: Analyze
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
permissions:
|
|
15
|
+
actions: read
|
|
16
|
+
contents: read
|
|
17
|
+
security-events: write
|
|
18
|
+
|
|
19
|
+
strategy:
|
|
20
|
+
fail-fast: false
|
|
21
|
+
matrix:
|
|
22
|
+
language: [ 'javascript' ]
|
|
23
|
+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
|
|
24
|
+
|
|
25
|
+
steps:
|
|
26
|
+
- name: Checkout repository
|
|
27
|
+
uses: actions/checkout@v3
|
|
28
|
+
|
|
29
|
+
# Initializes the CodeQL tools for scanning.
|
|
30
|
+
- name: Initialize CodeQL
|
|
31
|
+
uses: github/codeql-action/init@v2
|
|
32
|
+
with:
|
|
33
|
+
languages: ${{ matrix.language }}
|
|
34
|
+
# If you wish to specify custom queries, you can do so here or in a config file.
|
|
35
|
+
# By default, queries listed here will override any specified in a config file.
|
|
36
|
+
# Prefix the list here with "+" to use these queries and those in the config file.
|
|
37
|
+
|
|
38
|
+
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
|
|
39
|
+
# queries: security-extended,security-and-quality
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
|
43
|
+
# If this step fails, then you should remove it and run the build manually (see below)
|
|
44
|
+
# - name: Autobuild
|
|
45
|
+
# uses: github/codeql-action/autobuild@v2
|
|
46
|
+
|
|
47
|
+
# ℹ️ Command-line programs to run using the OS shell.
|
|
48
|
+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
|
49
|
+
|
|
50
|
+
# If the Autobuild fails above, remove it and uncomment the following three lines.
|
|
51
|
+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
|
|
52
|
+
|
|
53
|
+
# - run: |
|
|
54
|
+
# echo "Run, Build Application using script"
|
|
55
|
+
# ./location_of_script_within_repo/buildscript.sh
|
|
56
|
+
|
|
57
|
+
- name: Perform CodeQL Analysis
|
|
58
|
+
uses: github/codeql-action/analyze@v2
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
name: Test and publish
|
|
2
|
+
|
|
3
|
+
# Controls when the action will run. Triggers the workflow on push or pull request
|
|
4
|
+
# events but only for the main branch
|
|
5
|
+
on:
|
|
6
|
+
push:
|
|
7
|
+
branches: [ [branchName] ]
|
|
8
|
+
pull_request:
|
|
9
|
+
branches: [ [branchName] ]
|
|
10
|
+
|
|
11
|
+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
|
|
12
|
+
jobs:
|
|
13
|
+
test:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
|
|
16
|
+
strategy:
|
|
17
|
+
matrix:
|
|
18
|
+
node-version: [ [abstractNodeVersion] ]
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v3
|
|
22
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
23
|
+
uses: actions/setup-node@v3
|
|
24
|
+
with:
|
|
25
|
+
node-version: ${{ matrix.node-version }}
|
|
26
|
+
- run: npm ci
|
|
27
|
+
- run: npm test
|
|
28
|
+
|
|
29
|
+
release:
|
|
30
|
+
# Only release on push to main
|
|
31
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/[branchName]'
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
needs: test
|
|
34
|
+
steps:
|
|
35
|
+
- uses: actions/checkout@v3
|
|
36
|
+
with:
|
|
37
|
+
persist-credentials: false
|
|
38
|
+
- uses: actions/setup-node@v3
|
|
39
|
+
with:
|
|
40
|
+
node-version: [abstractNodeVersion]
|
|
41
|
+
- run: npm ci
|
|
42
|
+
- run: npm run build:docs
|
|
43
|
+
- uses: cycjimmy/semantic-release-action@v3
|
|
44
|
+
env:
|
|
45
|
+
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
|
|
46
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aurodesignsystem/auro-library",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "This repository holds shared scripts, utilities, and workflows utilized acorss repositories along the Auro Design System.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "
|
|
7
|
+
"url": "https://github.com/AlaskaAirlines/auro-library.git"
|
|
8
8
|
},
|
|
9
9
|
"main": "index.js",
|
|
10
10
|
"license": "Apache-2.0",
|
|
@@ -13,15 +13,15 @@
|
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@aurodesignsystem/eslint-config": "^1.3.0",
|
|
16
|
-
"@commitlint/cli": "^17.
|
|
17
|
-
"@commitlint/config-conventional": "^17.
|
|
16
|
+
"@commitlint/cli": "^17.7.1",
|
|
17
|
+
"@commitlint/config-conventional": "^17.7.0",
|
|
18
18
|
"@semantic-release/changelog": "^6.0.3",
|
|
19
19
|
"@semantic-release/git": "^10.0.1",
|
|
20
|
-
"@semantic-release/npm": "^10.0.
|
|
21
|
-
"eslint": "^8.
|
|
22
|
-
"eslint-plugin-jsdoc": "^46.
|
|
20
|
+
"@semantic-release/npm": "^10.0.5",
|
|
21
|
+
"eslint": "^8.48.0",
|
|
22
|
+
"eslint-plugin-jsdoc": "^46.5.1",
|
|
23
23
|
"husky": "^8.0.3",
|
|
24
|
-
"semantic-release": "^21.
|
|
24
|
+
"semantic-release": "^21.1.1"
|
|
25
25
|
},
|
|
26
26
|
"release": {
|
|
27
27
|
"branches": [
|
|
@@ -57,9 +57,13 @@
|
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"prepare": "husky install",
|
|
60
|
-
"lint": "eslint ./scripts/**/*.js"
|
|
60
|
+
"lint": "eslint ./scripts/**/*.js",
|
|
61
|
+
"build:docs": "node scripts/build/generateReadme.mjs"
|
|
61
62
|
},
|
|
62
63
|
"bugs": {
|
|
63
64
|
"url": "https://github.com/AlaskaAirlines/auro-library/issues"
|
|
65
|
+
},
|
|
66
|
+
"dependencies": {
|
|
67
|
+
"markdown-magic": "^2.6.1"
|
|
64
68
|
}
|
|
65
69
|
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import markdownMagic from 'markdown-magic';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as https from 'https';
|
|
4
|
+
|
|
5
|
+
import AuroLibraryUtils from "../utils/auroLibraryUtils.mjs";
|
|
6
|
+
|
|
7
|
+
const auroLibraryUtils = new AuroLibraryUtils();
|
|
8
|
+
|
|
9
|
+
const readmeTemplateUrl = 'https://raw.githubusercontent.com/AlaskaAirlines/WC-Generator/master/componentDocs/README.md';
|
|
10
|
+
const dirDocTemplates = './docTemplates';
|
|
11
|
+
const readmeFilePath = dirDocTemplates + '/README.md';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Replace all instances of [npm], [name], [Name], [namespace] and [Namespace] accordingly
|
|
15
|
+
*/
|
|
16
|
+
function formatApiTableContents(content, destination) {
|
|
17
|
+
const nameExtractionData = auroLibraryUtils.nameExtraction();
|
|
18
|
+
const wcName = nameExtractionData.namespace + '-' + nameExtractionData.name;
|
|
19
|
+
|
|
20
|
+
let result = content;
|
|
21
|
+
|
|
22
|
+
result = result
|
|
23
|
+
.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>`)
|
|
24
|
+
.replace(/\r\n|\r|\n\|\s`([a-zA-Z]*)`/g, '\r\n| [$1](#$1)')
|
|
25
|
+
.replace(/\| \[\]\(#\)/g, "");
|
|
26
|
+
|
|
27
|
+
fs.writeFileSync(destination, result, { encoding: 'utf8'});
|
|
28
|
+
|
|
29
|
+
fs.readFile('./demo/api.md', 'utf8', function(err, data) {
|
|
30
|
+
auroLibraryUtils.formatFileContents(data, './demo/api.md');
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Compiles `./docTemplates/README.md` -> `./README.md`
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
function processReadme() {
|
|
39
|
+
const callback = function() {
|
|
40
|
+
|
|
41
|
+
if (fs.existsSync('./README.md')) {
|
|
42
|
+
fs.readFile('./README.md', 'utf8', function(err, data) {
|
|
43
|
+
auroLibraryUtils.formatFileContents(data, './README.md');
|
|
44
|
+
});
|
|
45
|
+
} else {
|
|
46
|
+
console.log('ERROR: ./README.md file is missing');
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const config = {
|
|
51
|
+
matchWord: 'AURO-GENERATED-CONTENT',
|
|
52
|
+
outputDir: './'
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const markdownPath = './docTemplates/README.md';
|
|
56
|
+
|
|
57
|
+
markdownMagic(markdownPath, config, callback);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Compiles `./docTemplates/demo.md` -> `./demo/demo.md`
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
function processDemo() {
|
|
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');
|
|
69
|
+
});
|
|
70
|
+
} else {
|
|
71
|
+
console.log('ERROR: ./demo/demo.md file is missing');
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const configDemo = {
|
|
76
|
+
matchWord: 'AURO-GENERATED-CONTENT',
|
|
77
|
+
outputDir: './demo'
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const markdownPath = './docs/partials/demo.md';
|
|
81
|
+
|
|
82
|
+
markdownMagic(markdownPath, configDemo, callback);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Compiles `./docTemplates/api.md` -> `./demo/api.md`
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
function processApiExamples() {
|
|
90
|
+
const callback = function() {
|
|
91
|
+
if (fs.existsSync('./demo/api.md')) {
|
|
92
|
+
fs.readFile('./demo/api.md', 'utf8', function(err, data) {
|
|
93
|
+
formatApiTableContents(data, './demo/api.md');
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
console.log('ERROR: ./demo/api.md file is missing');
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const config = {
|
|
101
|
+
matchWord: 'AURO-GENERATED-CONTENT',
|
|
102
|
+
outputDir: './demo'
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const markdownPath = './docs/partials/api.md';
|
|
106
|
+
|
|
107
|
+
markdownMagic(markdownPath, config, callback);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Copy README.md template from static source
|
|
112
|
+
* */
|
|
113
|
+
|
|
114
|
+
function copyReadmeLocally() {
|
|
115
|
+
|
|
116
|
+
if (!fs.existsSync(dirDocTemplates)){
|
|
117
|
+
fs.mkdirSync(dirDocTemplates);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (!fs.existsSync(readmeFilePath)) {
|
|
121
|
+
fs.writeFile(readmeFilePath, '', function(err) {
|
|
122
|
+
if(err) {
|
|
123
|
+
console.log('ERROR: Unable to create README.md file.', err);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
https.get(readmeTemplateUrl, function(response) {
|
|
129
|
+
let writeTemplate = response.pipe(fs.createWriteStream(readmeFilePath));
|
|
130
|
+
|
|
131
|
+
writeTemplate.on('finish', () => {
|
|
132
|
+
processReadme();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
}).on('error', (err) => {
|
|
136
|
+
console.log('ERROR: Unable to fetch README.md file from server.', err);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Run all the actual document generation
|
|
142
|
+
*/
|
|
143
|
+
copyReadmeLocally();
|
|
144
|
+
processApiExamples();
|
|
145
|
+
processDemo();
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import markdownMagic from 'markdown-magic';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
|
|
4
|
+
const dirDocs = './docs';
|
|
5
|
+
const readmeFilePath = dirDocs + '/README.md';
|
|
6
|
+
|
|
7
|
+
import AuroLibraryUtils from "../utils/auroLibraryUtils.mjs";
|
|
8
|
+
|
|
9
|
+
const auroLibraryUtils = new AuroLibraryUtils();
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Compiles `./docs/README.md` -> `./README.md`
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
function processReadme() {
|
|
16
|
+
const callback = function() {
|
|
17
|
+
|
|
18
|
+
if (fs.existsSync('./README.md')) {
|
|
19
|
+
fs.readFile('./README.md', 'utf8', function(err, data) {
|
|
20
|
+
auroLibraryUtils.formatFileContents(data, './README.md');
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
console.log('ERROR: ./README.md file is missing');
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const config = {
|
|
28
|
+
matchWord: 'AURO-GENERATED-CONTENT',
|
|
29
|
+
outputDir: './'
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const markdownPath = './docs/README.md';
|
|
33
|
+
|
|
34
|
+
markdownMagic(markdownPath, config, callback);
|
|
35
|
+
|
|
36
|
+
fs.copyFileSync(readmeFilePath, './README.md');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Copy README.md template from static source
|
|
41
|
+
* */
|
|
42
|
+
|
|
43
|
+
function copyReadmeLocally() {
|
|
44
|
+
|
|
45
|
+
if (!fs.existsSync(dirDocs)){
|
|
46
|
+
fs.mkdirSync(dirDocs);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!fs.existsSync(readmeFilePath)) {
|
|
50
|
+
fs.writeFile(readmeFilePath, '', function(err) {
|
|
51
|
+
if(err) {
|
|
52
|
+
console.log('ERROR: Unable to create README.md file.', err);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
processReadme();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
copyReadmeLocally();
|
|
@@ -0,0 +1,178 @@
|
|
|
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
|
+
import * as fs from 'fs';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import chalk from 'chalk';
|
|
9
|
+
|
|
10
|
+
export default class AuroLibraryUtils {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Copys and pastes all files in a source directory into a destination directory.
|
|
14
|
+
* @param {String} srcDir - File path of directory to copy from.
|
|
15
|
+
* @param {String} destDir - File path of directory to paste files into.
|
|
16
|
+
* @param {Boolean} removeFiles - If true, removes all files in destination directory before pasting files.
|
|
17
|
+
*/
|
|
18
|
+
copyDirectory(srcDir, destDir, removeFiles) {
|
|
19
|
+
if (!fs.existsSync(srcDir)) {
|
|
20
|
+
this.auroLogger(`Source directory ${srcDir} does not exist`, 'error', false);
|
|
21
|
+
} else {
|
|
22
|
+
// Removes all files from directory
|
|
23
|
+
if (removeFiles && fs.existsSync(destDir)) {
|
|
24
|
+
const destFiles = fs.readdirSync(destDir);
|
|
25
|
+
|
|
26
|
+
let filesRemoved = 0;
|
|
27
|
+
|
|
28
|
+
destFiles.forEach(file => {
|
|
29
|
+
const filePath = path.join(destDir, file);
|
|
30
|
+
fs.unlinkSync(filePath);
|
|
31
|
+
this.auroLogger(`Removed file: ${file}`, 'success', false);
|
|
32
|
+
|
|
33
|
+
filesRemoved += 1;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
if (filesRemoved > 0) {
|
|
37
|
+
this.auroLogger(`Removed ${filesRemoved} files`, 'success', false);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Creates destination directory if it does not exist
|
|
42
|
+
if (!fs.existsSync(destDir)) {
|
|
43
|
+
fs.mkdirSync(destDir);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// All files from source directory
|
|
47
|
+
const files = fs.readdirSync(srcDir);
|
|
48
|
+
|
|
49
|
+
// Copys over all files from source directory to destination directory
|
|
50
|
+
files.forEach(file => {
|
|
51
|
+
const sourceFilePath = path.join(srcDir, file);
|
|
52
|
+
const destFilePath = path.join(destDir, file);
|
|
53
|
+
|
|
54
|
+
const stat = fs.statSync(sourceFilePath);
|
|
55
|
+
|
|
56
|
+
if (stat.isDirectory()) {
|
|
57
|
+
this.copyDirectory(srcDir, destDir, removeFiles);
|
|
58
|
+
} else {
|
|
59
|
+
fs.copyFileSync(sourceFilePath, destFilePath);
|
|
60
|
+
|
|
61
|
+
fs.readFile(destFilePath, 'utf8', (err, data) => {
|
|
62
|
+
this.formatFileContents(data, destFilePath);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
this.auroLogger(`Copied file: ${file}`, 'success');
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Logs out messages in a readble format.
|
|
73
|
+
* @param {String} message - Message to be logged.
|
|
74
|
+
* @param {String} status - Status that determines the color of the logged message.
|
|
75
|
+
* @param {Boolean} section - If true, adds a box around the message for readability.
|
|
76
|
+
*/
|
|
77
|
+
auroLogger(message, status, section) {
|
|
78
|
+
if (status) {
|
|
79
|
+
const infoColor = '#0096FF'; // blue
|
|
80
|
+
const successColor = '#4CBB17'; // green
|
|
81
|
+
const errorColor = '#ff0000'; // red
|
|
82
|
+
|
|
83
|
+
let color = undefined;
|
|
84
|
+
|
|
85
|
+
if (status === 'info') {
|
|
86
|
+
color = infoColor;
|
|
87
|
+
} else if (status === 'success') {
|
|
88
|
+
color = successColor;
|
|
89
|
+
} else if (status === 'error') {
|
|
90
|
+
color = errorColor;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (section) {
|
|
94
|
+
console.log(chalk.hex(color)(`╭ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ──────────────────────────────╮\n`));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
console.log(chalk.hex(color)(message));
|
|
98
|
+
|
|
99
|
+
if (section) {
|
|
100
|
+
console.log(chalk.hex(color)('\n╰─────────────────────────────── ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯'));
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
if (section) {
|
|
104
|
+
console.log(`╭ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ──────────────────────────────╮\n`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
console.log(message);
|
|
108
|
+
|
|
109
|
+
if (section) {
|
|
110
|
+
console.log(`\n╰─────────────────────────────── ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Extracts NPM VERSION, BRANCH NAME, NPM, NAMESPACE, and NAME from package.json.
|
|
117
|
+
* @returns {Object} result - Object containing data from package.json.
|
|
118
|
+
*/
|
|
119
|
+
nameExtraction() {
|
|
120
|
+
const packageJson = fs.readFileSync('package.json', 'utf8', function(err) {
|
|
121
|
+
if (err) {
|
|
122
|
+
console.log('ERROR: Unable to read package.json file', err);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
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 = {
|
|
133
|
+
'abstractNodeVersion': JSON.parse(packageJson).engines.node.substring(2),
|
|
134
|
+
'branchName': JSON.parse(packageJson).release.branch,
|
|
135
|
+
'npm': pName.substring(npmStart, namespaceStart),
|
|
136
|
+
'namespace': pName.substring(namespaceStart + 1, nameStart),
|
|
137
|
+
'namespaceCap': pName.substring(namespaceStart + 1)[0].toUpperCase() + pName.substring(namespaceStart + 2, nameStart),
|
|
138
|
+
'name': pName.substring(nameStart + 1),
|
|
139
|
+
'nameCap': pName.substring(nameStart + 1)[0].toUpperCase() + pName.substring(nameStart + 2)
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Replace all instances of [abstractNodeVersion], [branchName], [npm], [name], [Name], [namespace] and [Namespace] accordingly
|
|
147
|
+
*/
|
|
148
|
+
formatFileContents(content, destination) {
|
|
149
|
+
let nameExtractionData = this.nameExtraction();
|
|
150
|
+
let result = content;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Replace placeholder strings
|
|
154
|
+
*/
|
|
155
|
+
result = result.replace(/\[abstractNodeVersion]/g, nameExtractionData.abstractNodeVersion);
|
|
156
|
+
result = result.replace(/\[branchName]/g, nameExtractionData.branchName);
|
|
157
|
+
result = result.replace(/\[npm]/g, nameExtractionData.npm);
|
|
158
|
+
result = result.replace(/\[name](?!\()/g, nameExtractionData.name);
|
|
159
|
+
result = result.replace(/\[Name](?!\()/g, nameExtractionData.nameCap);
|
|
160
|
+
result = result.replace(/\[namespace]/g, nameExtractionData.namespace);
|
|
161
|
+
result = result.replace(/\[Namespace]/g, nameExtractionData.namespaceCap);
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Cleanup line breaks
|
|
165
|
+
*/
|
|
166
|
+
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
|
+
result = result.replace(/>(\r\n|\r|\n){2,}/g, '>\r\n'); // Remove empty lines directly after a closing html tag.
|
|
168
|
+
result = result.replace(/>(\r\n|\r|\n)```/g, '>\r\n\r\n```'); // Ensure an empty line before code samples.
|
|
169
|
+
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
|
+
result = result.replace(/([^(\r\n|\r|\n)])(\r\n|\r|\n)+#/g, "$1\r\n\r\n#"); // Ensure empty line before header sections.
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Write the result to the destination file
|
|
174
|
+
*/
|
|
175
|
+
fs.writeFileSync(destination, result, { encoding: 'utf8'});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|