-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from nicolethoen/docs_scaffolding
fix: clean up, add documentation scaffolding
- Loading branch information
Showing
29 changed files
with
3,433 additions
and
4,166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const fse = require('fs-extra'); | ||
const glob = require('glob'); | ||
const path = require('path'); | ||
|
||
const root = process.cwd(); | ||
|
||
const sourceFiles = glob | ||
.sync(`${root}/src/*/`) | ||
.map((name) => name.replace(/\/$/, '')); | ||
|
||
const indexTypings = glob.sync(`${root}/src/index.d.ts`); | ||
|
||
async function copyTypings(files, dest) { | ||
const cmds = []; | ||
files.forEach((file) => { | ||
const fileName = file.split('/').pop(); | ||
cmds.push(fse.copyFile(file, `${dest}/${fileName}`)); | ||
}); | ||
return Promise.all(cmds); | ||
} | ||
|
||
async function createPackage(file) { | ||
const fileName = file.split('/').pop(); | ||
const esmSource = glob.sync(`${root}/esm/${fileName}/**/index.js`)[0]; | ||
/** | ||
* Prevent creating package.json for directories with no JS files (like CSS directories) | ||
*/ | ||
if (!esmSource) { | ||
return; | ||
} | ||
|
||
const destFile = `${path.resolve(root, file.split('/src/').pop())}/package.json`; | ||
|
||
const esmRelative = path.relative(file.replace('/src', ''), esmSource); | ||
const content = { | ||
main: 'index.js', | ||
module: esmRelative, | ||
}; | ||
const typings = glob.sync(`${root}/src/${fileName}/*.d.ts`); | ||
let cmds = []; | ||
content.typings = 'index.d.ts'; | ||
cmds.push(copyTypings(typings, `${root}/${fileName}`)); | ||
cmds.push(fse.writeJSON(destFile, content)); | ||
return Promise.all(cmds); | ||
} | ||
|
||
async function generatePackages(files) { | ||
const cmds = files.map((file) => createPackage(file)); | ||
return Promise.all(cmds); | ||
} | ||
|
||
async function run(files) { | ||
try { | ||
await generatePackages(files); | ||
if (indexTypings.length === 1) { | ||
copyTypings(indexTypings, root); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
run(sourceFiles); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const fs = require('fs'); | ||
const fse = require('fs-extra'); | ||
const path = require('path'); | ||
|
||
const charts_scss = path.join(__dirname, 'build/css/_tokens-charts.scss'); | ||
const dark_scss = path.join(__dirname, 'build/css/_tokens-dark.scss'); | ||
const default_scss = path.join(__dirname, 'build/css/_tokens-default.scss'); | ||
const palette_scss = path.join(__dirname, 'build/css/_tokens-palette.scss'); | ||
|
||
const chartFileContents = fs.readFileSync(charts_scss, 'utf-8'); | ||
const darkFileContents = fs.readFileSync(dark_scss, 'utf-8'); | ||
const defaultFileContents = fs.readFileSync(default_scss, 'utf-8'); | ||
const paletteFileContents = fs.readFileSync(palette_scss, 'utf-8'); | ||
|
||
const scssAsJson = {} | ||
|
||
const addToMap = (line) => { | ||
const trimmedLine = line.trimStart(); | ||
if (trimmedLine.startsWith("--")) { | ||
const varName = trimmedLine.substring(0, trimmedLine.indexOf(':')); | ||
|
||
// value should have var( ) stripped from it, so it's just the variable name | ||
// if no var ( ) then just the value should be stored in the map | ||
let value = trimmedLine.substring(trimmedLine.indexOf(':')+1, trimmedLine.indexOf(';')).trimStart(); | ||
if (value.startsWith('var(')) { | ||
value = value.substring(value.indexOf('(')+1, value.indexOf(')')); | ||
} | ||
scssAsJson[varName] = value | ||
} | ||
} | ||
|
||
paletteFileContents.split(/\r?\n/).forEach(line => addToMap(line)); | ||
defaultFileContents.split(/\r?\n/).forEach(line => addToMap(line)); | ||
darkFileContents.split(/\r?\n/).forEach(line => addToMap(line)); | ||
chartFileContents.split(/\r?\n/).forEach(line => addToMap(line)); | ||
|
||
fse.writeJson(path.join(__dirname, 'patternfly-docs/scssAsJson.json'), scssAsJson); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.