Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node 18 + Manifest Tweak #29

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 5 additions & 5 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ on:
jobs:
build:

runs-on: macos-latest
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x]
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build
- run: git config --local user.name ${{ github.actor }}
- run: git add index.json
- run: git commit -m "Automatic manifest update"
- name:
- name:
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
44 changes: 44 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
*.swp

pids
logs
results
tmp

# Build
public/css/main.css
/build*
/regression/output

# Coverage reports
coverage

# API keys and secrets
.env

# Dependency directory
node_modules
bower_components

# Editors
.vscode
.idea
*.iml

# OS metadata
.DS_Store
Thumbs.db

# Ignore built ts files
dist/**/*

# ignore yarn.lock
yarn.lock
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 18.19.0
82 changes: 55 additions & 27 deletions manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require('path');
const moment = require('moment');
const lineReaderComponent = require('readline');

const baseExamplesPath = path.join(__dirname, 'Examples');
const manifestPath = path.join(__dirname, 'index.json');

/***
Expand Down Expand Up @@ -32,51 +33,78 @@ async function getMetadata(filePath, fileName) {
return metaData;
}

/***
* Takes the local file path of a file and retuns the corresponding Github url suffix
*/
function generatePath(filePath) {
let urlPath = filePath.split('FSHOnline-Examples/Examples/')[1];
return urlPath.replace(' ', '%20'); // Spaces appear as '%20' in Github urls
}

/***
* Returns an array of manifest objects when provided a directory's filepath
*/
async function getChildren(baseDirName) {
async function getChildren(relativeDir = '') {
let workingArray = [];

// First we'll take in all files in the provided directory
const files = fs.readdirSync(baseDirName);
const files = fs.readdirSync(path.join(baseExamplesPath, relativeDir));

for (const file of files) {
const filePath = path.join(baseDirName, file); // We're appending the child file name to the base directory name
let fileStats = fs.statSync(filePath); // This contains directory information
const relativeFilePath = path.join(relativeDir, file);
const fullFilePath = path.join(baseExamplesPath, relativeFilePath); // We're appending the child file name to the base directory name
let fileStats = fs.statSync(fullFilePath); // This contains directory information

if (file.endsWith('fsh')) {
const index = workingArray.push({ path: generatePath(filePath) }) - 1;
const metaData = await getMetadata(filePath, file);
workingArray[index].name = metaData.name;
workingArray[index].description = metaData.description;
workingArray[index].type = "file";
const metaData = await getMetadata(fullFilePath, file);
workingArray.push({
path: encodeURI(relativeFilePath),
...metaData,
type: 'file'
});
} else if (fileStats.isDirectory()) {
const index = workingArray.push({ name: file, path: generatePath(filePath) }) - 1;
workingArray[index].type = 'category';
workingArray[index].children = [];
const children = await getChildren(filePath);
workingArray[index].children = children;
if (workingArray[index].children.length === 0) {
workingArray.pop();
const children = await getChildren(relativeFilePath);
if (children.length) {
workingArray.push({
name: file,
path: encodeURI(relativeFilePath),
type: 'category',
children
});
}
}
}
return workingArray;
}

async function generateManifest() {
const examplesArr = await getChildren(path.join(__dirname, 'Examples'));
let manifestObj = {timestamp: moment(Date.now()).format(), children: examplesArr };
fs.writeFileSync(manifestPath, JSON.stringify(manifestObj, null, "\t"), 'utf-8');
let oldManifest;
if (fs.existsSync(manifestPath)) {
oldManifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
} else {
oldManifest = { timestamp: 'n/a', children: [] };
}
console.log('Old Manifest:');
console.log('=============')
console.log(`${'Timestamp:'.padEnd(15)} ${oldManifest.timestamp}`);
oldManifest.children?.forEach(c => {
console.log(`${(c.name + ':').padEnd(15)} ${c.children?.length ?? 0} entries`)
});
console.log();

const examplesArr = await getChildren();
let newManifest = { timestamp: moment(Date.now()).format(), children: examplesArr };
console.log('New Manifest:');
console.log('=============')
console.log(`${'Timestamp:'.padEnd(15)} ${newManifest.timestamp}`);
newManifest.children?.forEach(c => {
const oldCount = oldManifest.children?.find(oc => oc.name === c.name)?.children?.length ?? 0;
const newCount = c.children?.length ?? 0;
const delta = newCount - oldCount;
const extra = delta !== 0 ? ` (${delta > 0 ? '+': ''}${delta})` : '';
console.log(`${(c.name + ':').padEnd(15)} ${newCount} entries${extra}`);
});
oldManifest.children?.forEach(c => {
if (!newManifest.children.some(nc => nc.name == c.name)) {
const oldCount = c.children?.length ?? 0;
console.log(`${(c.name + ':').padEnd(15)} 0 entries (-${oldCount})`);
}
});
console.log();

fs.writeFileSync(manifestPath, JSON.stringify(newManifest, null, '\t'), 'utf-8');
}

generateManifest();
Loading
Loading