-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea58554
commit afe8b6d
Showing
26 changed files
with
6,946 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
coverage | ||
dist | ||
node_modules |
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,17 @@ | ||
{ | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"rules": { | ||
"comma-dangle": [1, "always-multiline"], | ||
"no-console": "warn", | ||
"semi": "error" | ||
} | ||
} |
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,4 @@ | ||
.DS_store | ||
coverage | ||
dist/lib | ||
node_modules |
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,10 @@ | ||
sudo: false | ||
|
||
language: node_js | ||
|
||
node_js: | ||
- node | ||
|
||
script: | ||
- npm run compile | ||
- npm run test:coveralls |
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,2 @@ | ||
## [0.0.1] - 2021-03-15 | ||
- Initial release |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Michael Paravano | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS, AUTHORS' EMPLOYER(S), OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. |
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,221 @@ | ||
/* eslint-disable no-undef */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const ejs = require('ejs'); | ||
const { copyFileSync, existsSync, readdirSync, readFileSync, writeFileSync } = require('fs'); | ||
const { join, resolve } = require('path'); | ||
const dirTree = require('directory-tree'); | ||
const { parseTags, removeTags } = require('jsdoc-parse-plus'); | ||
const { first, isNotNullOrEmpty } = require('../dist/lib/es5/_private/utils'); | ||
const htmlEncode = require('js-htmlencode').htmlEncode; | ||
|
||
/** | ||
* Available docgen tags: | ||
* @docgen_types - code wrapped display of supported types | ||
* @docgen_note - note about the util (blockquote) | ||
* @docgen_details - Any extra details to say about the function that you don't want in a note blockquote | ||
* @docgen_import - override for the import | ||
*/ | ||
const docgenTags = [ | ||
'@docgen_types', | ||
'@docgen_note', | ||
'@docgen_details', | ||
'@docgen_import', | ||
]; | ||
|
||
const index = async () => { | ||
console.log('Generating README.md...'); | ||
|
||
const root = join(__dirname, '..'); | ||
const src = join(__dirname, '..', 'src'); | ||
const dist = join(__dirname, '..', 'dist'); | ||
const lib = join(__dirname, '..', 'dist', 'lib'); | ||
const es5 = join(__dirname, '..', 'dist', 'lib', 'es5'); | ||
const es6 = join(__dirname, '..', 'dist', 'lib', 'es6'); | ||
|
||
const interfaces = existsSync(join(src, 'types', 'index.ts')) ? readFileSync(join(src, 'types', 'index.ts'), 'utf8') : ''; | ||
const dirs = readdirSync(src).filter(x => !x.includes('.') && !x.startsWith('_') && x !== 'types'); | ||
let utils = []; | ||
|
||
const tags = [ | ||
'@description', | ||
'@since', | ||
'@param', | ||
'@returns', | ||
'@example', | ||
'@see', | ||
'@deprecated', | ||
...docgenTags, | ||
]; | ||
|
||
for (const dir of dirs) { | ||
const functions = Array.from(readFileSync(join(src, dir, 'index.ts'), 'utf8').toString().matchAll(/\/\*\*(\n|\r\n)( \*(.*)(\n|\r\n))* \*\/(\n|\r\n)(.*)/gm)).reduce((accumulator, item) => [...accumulator, item[0]] , []); | ||
|
||
for (const func of functions) { | ||
utils = [...utils, { ...getFunctionNameFromExpression(func), ...parseTags(func, tags) }]; | ||
} | ||
} | ||
|
||
const packageData = require(join(dist, 'package.json')); | ||
const tree = dirTree(lib); | ||
|
||
const templateData = { | ||
interfaces, | ||
utils, | ||
fileTree: tree, | ||
package: packageData, | ||
formatBytes, | ||
generateTable, | ||
}; | ||
|
||
const file = await resolve(__dirname, './readme.ejs'); | ||
|
||
ejs.renderFile(file, templateData, (err, output) => { | ||
if (err) { | ||
console.log(err); | ||
} | ||
writeFileSync(join(dist, 'README.md'), output); | ||
writeFileSync(join(root, 'README.md'), output); | ||
}); | ||
|
||
sanitizeDTS(dirs, es5); | ||
sanitizeDTS(dirs, es6); | ||
|
||
if (existsSync(join(__dirname, '..', 'LICENSE'))) { | ||
copyFileSync(join(__dirname, '..', 'LICENSE'), join(__dirname, '..', 'dist', 'LICENSE')); | ||
} | ||
|
||
if (existsSync(join(__dirname, '..', 'CHANGELOG.md'))) { | ||
copyFileSync(join(__dirname, '..', 'CHANGELOG.md'), join(__dirname, '..', 'dist', 'CHANGELOG.md')); | ||
} | ||
|
||
console.log('Done'); | ||
}; | ||
|
||
const generateTable = (util, packageName) => { | ||
const getValue = key => { | ||
if (util[key]?.value?.length > 0) { | ||
const startsWithTag = new RegExp(/^ *<.*?>/g); | ||
const endsWithTag = new RegExp(/<\/.*?>$/g); | ||
return startsWithTag.test(util[key].value) && endsWithTag.test(util[key].value) ? util[key].value : `<p>${util[key].value}</p>\n`; | ||
} | ||
|
||
return ''; | ||
}; | ||
|
||
const description = getValue('description'); | ||
const since = util.since ? `<p>Since ${util.since.value}</p>\n` : ''; | ||
const hasDefault = util.param.some(x => x.defaultValue !== undefined); | ||
const types = util.docgen_types ? `<h4>Supporting Types</h4>\n\n\`\`\`\n${util.docgen_types.value}\n\`\`\`` : ''; | ||
const details = getValue('docgen_details'); | ||
|
||
let notes = ''; | ||
|
||
if (util?.docgen_note && Array.isArray(util.docgen_note)) { | ||
notes = util.docgen_note.map(note => `<blockquote><p>${note.value}</p></blockquote>`).join(''); | ||
} else if (util?.docgen_note) { | ||
notes = `<blockquote><p>${util.docgen_note.value}</p></blockquote>`; | ||
} | ||
|
||
let examples = existsSync(join(__dirname, '..', 'src', util.name, 'EXAMPLES.md')) ? '\n\n' + readFileSync(join(__dirname, '..', 'src', util.name, 'EXAMPLES.md'), 'utf8') + '\n\n' : ''; | ||
|
||
if (isNotNullOrEmpty(util.example)) { | ||
examples = examples + '\n\n' + ` | ||
\`\`\` | ||
${util.example.map(x => x.value).join('\n')} | ||
\`\`\` | ||
`; | ||
} | ||
|
||
if (isNotNullOrEmpty(examples)) { | ||
examples = '<h3>Examples</h3>\n\n' + examples; | ||
} | ||
|
||
const _import = ` | ||
<h3>Import</h3> | ||
\`\`\` | ||
import ${isNotNullOrEmpty(util.docgen_import) ? util.docgen_import.value : `{ ${util.name} }`} from '${packageName}'; | ||
\`\`\` | ||
`; | ||
|
||
return ( | ||
'\n\n' + | ||
`<h2>${util.name}${util.generic ? `<${util.generic}>` : ''}</h2>` + | ||
'\n' + | ||
description + | ||
since + | ||
`<table> | ||
<thead> | ||
<tr> | ||
<th>Param</th> | ||
<th>Type</th>` + | ||
(hasDefault ? '<th>Default</th>' : '') + | ||
`</tr> | ||
</thead> | ||
<tbody>` + | ||
util.param.map(x => ( | ||
`<tr><td><p><b>${x.name}${x.optional ? ' <span>(optional)</span>' : ''}</b></p>${x.description}</td>` + | ||
`<td>${htmlEncode(x.type)}</td>` + | ||
(hasDefault ? `<td>${x.optional && x.defaultValue !== undefined ? x.defaultValue : ''}</td>` : '') + | ||
'</tr>' | ||
)).join('') + | ||
`</tbody> | ||
</table>` + | ||
`<p><b>Returns:</b> ${htmlEncode(util.returns.raw.replace('@returns', '').trim())}</p>` + | ||
notes + | ||
types + | ||
details + | ||
_import + | ||
examples | ||
); | ||
}; | ||
|
||
/** | ||
* Remove anything from jsdoc comments that is used for documentation generation only | ||
* | ||
* @param {string[]} dirs The directory names | ||
* @param {string} path The path to the directories | ||
*/ | ||
const sanitizeDTS = (dirs, path) => { | ||
console.log('Sanitizing *.d.ts: ' + path + '...'); | ||
|
||
for (const dir of dirs) { | ||
let file = readFileSync(join(path, dir, 'index.d.ts'), 'utf8'); | ||
const matches = Array.from(file.matchAll(/@docgen_default +(.*)/g)); | ||
|
||
for (const match of matches) { | ||
file = file.replace(match[0], ' '); | ||
} | ||
|
||
file = removeTags(file, docgenTags); | ||
writeFileSync(join(path, dir, 'index.d.ts'), file); | ||
} | ||
}; | ||
|
||
/** | ||
* Gets the function name from a function expression string | ||
* @param {string} func - The function expression string | ||
* @returns {{name: string, generic?: string}} | ||
*/ | ||
const getFunctionNameFromExpression = func => { | ||
const name = first(first(func.match(/export const (.*) =/), '').split('='), '').replace('export const ', '').trim(); | ||
const genericMatch = func.match(/export const (.*?) = <(.*?)>/); | ||
const generic = genericMatch && genericMatch[2] || undefined; | ||
|
||
return { name, generic }; | ||
}; | ||
|
||
|
||
const formatBytes = (a, b) => { | ||
if (a === 0) return '0 Bytes'; | ||
const c = 1024, | ||
d = b || 2, | ||
e = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], | ||
f = Math.floor(Math.log(a) / Math.log(c)); | ||
return parseFloat((a / Math.pow(c, f)).toFixed(d)) + ' ' + e[f]; | ||
}; | ||
|
||
index(); |
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,44 @@ | ||
[![Build Status](https://travis-ci.com/TheSpicyMeatball/css-in-js-preprocessor.svg?branch=main)](https://travis-ci.com/TheSpicyMeatball/css-in-js-preprocessor) | ||
[![Coverage Status](https://coveralls.io/repos/github/TheSpicyMeatball/css-in-js-preprocessor/badge.svg?branch=main)](https://coveralls.io/github/TheSpicyMeatball/css-in-js-preprocessor?branch=main) | ||
[![dependencies Status](https://status.david-dm.org/gh/TheSpicyMeatball/css-in-js-preprocessor.svg)](https://david-dm.org/TheSpicyMeatball/css-in-js-preprocessor) | ||
[![npm version](https://badge.fury.io/js/css-in-js-preprocessor.svg)](https://badge.fury.io/js/css-in-js-preprocessor) | ||
|
||
# <%= package.name %> | ||
|
||
> <%= package.description %> | ||
|
||
<p>Hello friend.</p> | ||
<p>CSS-in-JS is awesome and powerful, but do you miss the ability to preprocess your styles with your token values (like .less & .sass) without having to have your tokens as a dependency?</p> | ||
<p>Well, that's where <code><%= package.name %></code> is here to save the day!</p> | ||
<p>With <code><%= package.name %></code>, you can use your design system tokens to build your styles while also <i>auto-MAGICALLY</i> replacing the references to them with the actual values! Thus, eliminating the need for a dependency on a tokens package and ensuring that your values are up to date on every compile.</p> | ||
|
||
<p><b>Version:</b> <%= package.version %></p> | ||
|
||
<% for(var f=0; f < utils.length; f++) { %> | ||
<%- generateTable(utils[f], package.name) %> | ||
<hr /> | ||
<% } %> | ||
|
||
<a href="#package-contents"></a> | ||
<h2>Package Contents</h2> | ||
|
||
Within the module you'll find the following directories and files: | ||
|
||
```html | ||
package.json | ||
CHANGELOG.md -- history of changes to the module | ||
LICENSE | ||
README.md -- this file | ||
/<%= fileTree.name -%><% fileTree.children.forEach( function(child){ if (child.type == 'directory') { %> | ||
└───/<%= child.name -%><% child.children.forEach(function(grandChild){ if (grandChild.type == 'directory') { %> | ||
└───/<%= grandChild.name -%><% grandChild.children.forEach(function(greatGrand){ %> | ||
└───<%= greatGrand.name -%> - <%= formatBytes(greatGrand.size) -%><% }) } else { %> | ||
└───<%= grandChild.name -%> - <%= formatBytes(grandChild.size) -%><% } })} else { %> | ||
└───<%= child.name -%> - <%= formatBytes(child.size) -%><% }}) %> | ||
``` | ||
|
||
<a href="#license"></a> | ||
<h2>License</h2> | ||
|
||
<%= package.license %> |
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,2 @@ | ||
## [0.0.1] - 2021-03-15 | ||
- Initial release |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Michael Paravano | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS, AUTHORS' EMPLOYER(S), OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. |
Oops, something went wrong.