Skip to content

Commit

Permalink
feat(component): repairing unit tests and adding pre-commit hook back
Browse files Browse the repository at this point in the history
  • Loading branch information
shonore-aa authored and aesthetiques committed Aug 29, 2022
1 parent 7a18a4c commit 56e7b69
Show file tree
Hide file tree
Showing 15 changed files with 211 additions and 159 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"


# ./node_modules/.bin/npm-run-all preCommit test linters postinstall
9 changes: 5 additions & 4 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const { browserslist: defaultBrowserslist } = require('./package.json');

const modernBrowserslist = defaultBrowserslist.filter(
(browser) => browser !== 'ie 11'
);
const modernBrowserslist = defaultBrowserslist.filter((browser) => browser !== 'ie 11');

const sharedPlugins = [
'@babel/plugin-syntax-dynamic-import',
Expand All @@ -23,7 +21,10 @@ module.exports = {
env: {
modern: {
// lit-element supports the last two versions of modern browsers, so we don't need to polyfill
exclude: ['node_modules/lit-element/**', 'node_modules/lit-html/**'],
exclude: [
'node_modules/lit-element/**',
'node_modules/lit-html/**'
],
presets: [
[
'@babel/preset-env',
Expand Down
18 changes: 15 additions & 3 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'body-max-line-length': [0, 'always', 120],
'footer-max-line-length': [0, 'always', 120],
'header-max-length': [0, 'always', 120],
'body-max-line-length': [
0,
'always',
120
],
'footer-max-line-length': [
0,
'always',
120
],
'header-max-length': [
0,
'always',
120
],
},
};
5 changes: 2 additions & 3 deletions packageScripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';


const chalk = require('chalk');
const pjson = require('../package.json');
Expand All @@ -22,5 +22,4 @@ console.log(chalk.hex('#f26135')(`
of `) + chalk.hex('#ffd200').bold(`auro-flight v${pjson.version}.`) + chalk.hex('#f26135')(`
╰─────────────────────────────── ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
`)
);
`));
7 changes: 5 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ const production = !process.env.ROLLUP_WATCH;
const getSharedPlugins = (isLegacy) => [
resolve({
// in case of multiple lit-element versions (e.g. importing another auro component)
dedupe: ['lit-element', 'lit-html']
dedupe: [
'lit-element',
'lit-html'
]
}),
commonjs(),
// skipPreflightCheck flag needed or else build fails
Expand Down Expand Up @@ -60,4 +63,4 @@ const legacyConfig = {
plugins: getSharedPlugins(true)
};

export default [modernConfig];
export default [modernConfig];
107 changes: 67 additions & 40 deletions scripts/generateDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,29 @@ const https = require('https');

const readmeTemplateUrl = 'https://raw.githubusercontent.com/AlaskaAirlines/WC-Generator/master/componentDocs/README.md';
const dirDocTemplates = './docTemplates';
const readmeFilePath = dirDocTemplates + '/README.md';
const readmeFilePath = `${dirDocTemplates}/README.md`;

/**
* Extract NPM, NAMESPACE and NAME from package.json
* Extract NPM, NAMESPACE and NAME from package.json.
*/

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

pName = JSON.parse(packageJson).name;

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

let result = {
const result = {
'npm': pName.substring(npmStart, namespaceStart),
'namespace': pName.substring(namespaceStart + 1, nameStart),
'namespaceCap': pName.substring(namespaceStart + 1)[0].toUpperCase() + pName.substring(namespaceStart + 2, nameStart),
Expand All @@ -34,18 +37,21 @@ const readmeFilePath = dirDocTemplates + '/README.md';
};

return result;
};
}

/**
* Replace all instances of [npm], [name], [Name], [namespace] and [Namespace] accordingly
* Replace all instances of [npm], [name], [Name], [namespace] and [Namespace] accordingly.
*/

/**
*
*/
function formatTemplateFileContents(content, destination) {
let nameExtractionData = nameExtraction();
const nameExtractionData = nameExtraction();
let result = content;

/**
* Replace placeholder strings
* Replace placeholder strings.
*/
result = result.replace(/\[npm]/g, nameExtractionData.npm);
result = result.replace(/\[name]/g, nameExtractionData.name);
Expand All @@ -54,7 +60,7 @@ function formatTemplateFileContents(content, destination) {
result = result.replace(/\[Namespace]/g, nameExtractionData.namespaceCap);

/**
* Cleanup line breaks
* Cleanup line breaks.
*/
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.
result = result.replace(/>(\r\n|\r|\n){2,}/g, '>\r\n'); // Remove empty lines directly after a closing html tag.
Expand All @@ -63,35 +69,41 @@ function formatTemplateFileContents(content, destination) {
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
* Write the result to the destination file.
*/
fs.writeFileSync(destination, result, { encoding: 'utf8'});
};
}

/**
*
*/
function formatApiTableContents(content, destination) {
const nameExtractionData = nameExtraction();
const wcName = nameExtractionData.namespace + '-' + nameExtractionData.name;
const wcName = `${nameExtractionData.namespace}-${nameExtractionData.name}`;

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| [$1](#$1)')
.replace(/\| \[\]\(#\)/g, "");
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| [$1](#$1)').
replace(/\| \[\]\(#\)/g, "");

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

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

/**
* If auroLabs project, include auroLabs documentation in `./README.md`
* If auroLabs project, include auroLabs documentation in `./README.md`.
*/

/**
*
*/
function processLabsReadmeContent() {
let nameExtractionData = nameExtraction();
const nameExtractionData = nameExtraction();

if (nameExtractionData.npm === '@aurolabs') {
const callbackAurolabs = function(updatedContent, outputConfig) {
Expand All @@ -109,15 +121,18 @@ function processLabsReadmeContent() {
}

/**
* Compiles `./docTemplates/README.md` -> `./README.md`
* Compiles `./docTemplates/README.md` -> `./README.md`.
*/

/**
*
*/
function processReadme() {
const callback = function(updatedContent, outputConfig) {
processLabsReadmeContent()
processLabsReadmeContent();

if (fs.existsSync('./README.md')) {
fs.readFile('./README.md', 'utf8', function(err, data) {
fs.readFile('./README.md', 'utf8', (err, data) => {
formatTemplateFileContents(data, './README.md');
});
} else {
Expand All @@ -138,13 +153,16 @@ function processReadme() {
}

/**
* Compiles `./docTemplates/demo.md` -> `./demo/demo.md`
* Compiles `./docTemplates/demo.md` -> `./demo/demo.md`.
*/

/**
*
*/
function processDemo() {
const callback = function(updatedContent, outputConfig) {
if (fs.existsSync('./demo/demo.md')) {
fs.readFile('./demo/demo.md', 'utf8', function(err, data) {
fs.readFile('./demo/demo.md', 'utf8', (err, data) => {
formatTemplateFileContents(data, './demo/demo.md');
});
} else {
Expand All @@ -162,11 +180,14 @@ function processDemo() {
markdownMagic(markdownPath, configDemo, callback);
}

/**
*
*/
function processDot() {

const callback = function(updatedContent, outputConfig) {
if (fs.existsSync('./demo/dotCompliance.md')) {
fs.readFile('./demo/dotCompliance.md', 'utf8', function(err, data) {
fs.readFile('./demo/dotCompliance.md', 'utf8', (err, data) => {
formatTemplateFileContents(data, './demo/dotCompliance.md');
});
} else {
Expand All @@ -185,13 +206,16 @@ function processDot() {
}

/**
* Compiles `./docTemplates/apiExamples.md` -> `./demo/apiExamples.md`
* Compiles `./docTemplates/apiExamples.md` -> `./demo/apiExamples.md`.
*/

/**
*
*/
function processApiExamples() {
const callback = function(updatedContent, outputConfig) {
if (fs.existsSync('./demo/apiExamples.md')) {
fs.readFile('./demo/apiExamples.md', 'utf8', function(err, data) {
fs.readFile('./demo/apiExamples.md', 'utf8', (err, data) => {
formatApiTableContents(data, './demo/apiExamples.md');
});
} else {
Expand All @@ -210,25 +234,28 @@ function processApiExamples() {
}

/**
* Copy README.md template from static source
* */
* Copy README.md template from static source.
*/

/**
*
*/
function copyReadmeLocally() {

if (!fs.existsSync(dirDocTemplates)){
if (!fs.existsSync(dirDocTemplates)) {
fs.mkdirSync(dirDocTemplates);
}

if (!fs.existsSync(readmeFilePath)) {
fs.writeFile(readmeFilePath, '', function(err) {
if(err) {
fs.writeFile(readmeFilePath, '', (err) => {
if (err) {
console.log(chalk.red('ERROR: Unable to create README.md file.', err));
}
});
}

https.get(readmeTemplateUrl, function(response) {
let writeTemplate = response.pipe(fs.createWriteStream(readmeFilePath));
https.get(readmeTemplateUrl, (response) => {
const writeTemplate = response.pipe(fs.createWriteStream(readmeFilePath));

writeTemplate.on('finish', () => {
processReadme();
Expand All @@ -240,7 +267,7 @@ function copyReadmeLocally() {
}

/**
* Run all the actual document generation
* Run all the actual document generation.
*/
copyReadmeLocally();
processDemo();
Expand Down
46 changes: 26 additions & 20 deletions scripts/postCss.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ const fs = require('fs');
const directoryPath = path.join(__dirname, '../src');

/**
* Default postCSS run
* Default postCSS run.
*/
fs.readdir(directoryPath, function (err, files) {
//handling error
fs.readdir(directoryPath, (err, files) => {
// handling error
if (err) {
return console.log('Unable to scan directory: ' + err);
return console.log(`Unable to scan directory: ${err}`);
}
//listing all files using forEach
files.forEach(function (file) {
// listing all files using forEach
files.forEach((file) => {
if (file.includes(".css")) {
standardProcessor(file);
}
Expand All @@ -27,20 +27,26 @@ fs.readdir(directoryPath, function (err, files) {
* and completes a post cleanup.
* @param {string} file
*/
function standardProcessor(file) {
function standardProcessor(file) {
fs.readFile(`src/${file}`, (err, css) => {
postcss([autoprefixer, comments])
.use(comments({
remove: function(comment) { return comment[0] == "@"; }
}))
.use(removeRules({
rulesToRemove: {
':root': '*'
}
}))
.process(css, { from: `src/${file}`, to: `src/${file}` })
.then(result => {
fs.writeFile(`src/${file}`, result.css, () => true)
})
postcss([
autoprefixer,
comments
]).
use(comments({
remove(comment) {
return comment[0] == "@";
}
})).
use(removeRules({
rulesToRemove: {
':root': '*'
}
})).
process(css, { from: `src/${file}`,
to: `src/${file}` }).
then((result) => {
fs.writeFile(`src/${file}`, result.css, () => true);
});
});
}
Loading

0 comments on commit 56e7b69

Please sign in to comment.