Skip to content

Commit

Permalink
feat: add suport for SSR projects
Browse files Browse the repository at this point in the history
This commit updates scripts and configs to support SSR style projects.

Changes to be committed:
renamed:    commitlint.config.js -> commitlint.config.cjs
modified:   package-lock.json
modified:   package.json
modified:   packageScripts/postinstall.mjs
renamed:    scripts/generateDocs.js -> scripts/generateDocs.mjs
renamed:    scripts/postCss.js -> scripts/postCss.mjs
modified:   scripts/pre-commit.mjs
  • Loading branch information
blackfalcon authored and jordanjones243 committed Jan 18, 2024
1 parent 15aac4f commit fe2d4ce
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 46 deletions.
File renamed without changes.
33 changes: 29 additions & 4 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"type": "git",
"url": "https://github.com/AlaskaAirlines/auro-checkbox"
},
"type": "module",
"main": "index.js",
"license": "Apache-2.0",
"engines": {
Expand All @@ -28,6 +29,7 @@
"@aurodesignsystem/webcorestylesheets": "^5.0.5"
},
"devDependencies": {
"@aurodesignsystem/auro-library": "^2.2.4",
"@aurodesignsystem/design-tokens": "^4.3.0",
"@aurodesignsystem/eslint-config": "^1.3.0",
"@aurodesignsystem/webcorestylesheets": "^5.0.5",
Expand Down Expand Up @@ -132,7 +134,7 @@
"build:ci": "npm-run-all sweep build",
"build:api": "wca analyze 'src/auro-checkbox.js' --outFiles docs/api.md",
"build:dev:assets": "npm-run-all build:sass:component postCss:component sass:render build:docs",
"build:docs": "node scripts/generateDocs.js",
"build:docs": "node scripts/generateDocs.mjs",
"build:sass": "npm-run-all build:sass:component postCss:component sass:render",
"build:sass:component": "sass --no-source-map src:src",
"build:watch": "nodemon -e scss,js,html --watch src --watch apiExamples/**/* --exec npm run build:dev:assets",
Expand All @@ -143,7 +145,7 @@
"esLint": "./node_modules/.bin/eslint src/**/*.js",
"linters": "npm-run-all scssLint esLint",
"preCommit": "node scripts/pre-commit.mjs",
"postCss:component": "node ./scripts/postCss.js",
"postCss:component": "node ./scripts/postCss.mjs",
"postinstall": "node packageScripts/postinstall.mjs",
"sass:render": "sass-render src/*.css -t ./scripts/staticStyles-template.js",
"serve": "web-dev-server --open demo/ --node-resolve --watch",
Expand Down
2 changes: 1 addition & 1 deletion packageScripts/postinstall.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ console.log(chalk.hex('#f26135')(`
╭ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ──────────────────────────────╮
Thanks for installing the latest version
of `) + chalk.hex('#ffd200').bold(`auro-checkbox v${pjson.version}.`) + chalk.hex('#f26135')(`
of `) + chalk.hex('#ffd200').bold(`${pjson.name} v${pjson.version}.`) + chalk.hex('#f26135')(`
╰─────────────────────────────── ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
`)
Expand Down
73 changes: 40 additions & 33 deletions scripts/generateDocs.js → scripts/generateDocs.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
const path = require('path');
const markdownMagic = require('markdown-magic');
const fs = require('fs');
const https = require('https');
/**
* 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';
import https from 'https';

const __dirname = new URL('.', import.meta.url).pathname;

const readmeTemplateUrl = 'https://raw.githubusercontent.com/AlaskaAirlines/WC-Generator/master/componentDocs/README.md';
const dirDocTemplates = './docTemplates';
Expand All @@ -11,29 +18,29 @@ const readmeFilePath = dirDocTemplates + '/README.md';
* Extract NPM, NAMESPACE and NAME from package.json
*/

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

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

let npmStart = pName.indexOf('@');
let namespaceStart = pName.indexOf('/');
let nameStart = pName.indexOf('-');
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)
};
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;
};
return result;
}

/**
* Replace all instances of [npm], [name], [Name], [namespace] and [Namespace] accordingly
Expand All @@ -47,8 +54,8 @@ 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);

Expand All @@ -65,7 +72,7 @@ function formatTemplateFileContents(content, destination) {
* Write the result to the destination file
*/
fs.writeFileSync(destination, result, { encoding: 'utf8'});
};
}

function formatApiTableContents(content, destination) {
const nameExtractionData = nameExtraction();
Expand All @@ -80,8 +87,8 @@ function formatApiTableContents(content, destination) {

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

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

Expand Down Expand Up @@ -142,12 +149,12 @@ function processDemo() {

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

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

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

markdownMagic(markdownPath, config, callback);
}
Expand Down
8 changes: 4 additions & 4 deletions scripts/postCss.js → scripts/postCss.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const autoprefixer = require('autoprefixer');
const postcss = require('postcss');
const comments = require('postcss-discard-comments');
const fs = require('fs');
import autoprefixer from 'autoprefixer';
import postcss from 'postcss';
import comments from 'postcss-discard-comments';
import fs from 'fs';

fs.readFile('src/auro-checkbox-group.css', (err, css) => {
postcss([autoprefixer, comments])
Expand Down
2 changes: 0 additions & 2 deletions scripts/pre-commit.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

import chalk from 'chalk';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
console.log(chalk.hex('#ffd200')(`
╭ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ──────────────────────────────╮`) + chalk.hex('#f26135')(`
Expand Down

0 comments on commit fe2d4ce

Please sign in to comment.