-
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.
Merge branch 'main' into feature-icon-library
- Loading branch information
Showing
122 changed files
with
10,554 additions
and
2,809 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
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,20 @@ | ||
import { compile } from "svelte/compiler"; | ||
import { readFile, writeFile } from "fs/promises"; | ||
import path from "path"; | ||
import { fileURLToPath } from 'url'; | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
const themePath = path.resolve(__dirname, "../src/lib/Theme/Theme.svelte"); | ||
const outputPath = path.resolve(__dirname, "..", "dist/style", "theme.css"); | ||
|
||
|
||
async function main() { | ||
const themeSource = await readFile(themePath, "utf-8") | ||
const { css } = compile(themeSource, { | ||
cssHash: () => "tmpglobal" | ||
}); | ||
const globalCss = css.code.replaceAll(".tmpglobal", ""); | ||
return writeFile(outputPath, globalCss); | ||
} | ||
|
||
main() |
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,72 @@ | ||
#!/usr/bin/env node | ||
import { input } from "@inquirer/prompts"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
import process from "process"; | ||
import { createStory } from "./createStory.js"; | ||
import { createDocs } from "./createDocs.js"; | ||
|
||
// check if PascalCase https://www.w3resource.com/javascript-exercises/javascript-string-exercise-56.php | ||
function isPascalCase(str) { | ||
return /^[A-Z][A-Za-z]*$/.test(str); | ||
} | ||
|
||
// check if name is valid | ||
function validateName(componentName) { | ||
if (!componentName) { | ||
return "Please enter a component name"; | ||
} else if (!isPascalCase(componentName)) { | ||
return "Component name must be in PascalCase"; | ||
} else { | ||
return true; | ||
} | ||
} | ||
|
||
function createFiles(componentName) { | ||
// validate file name | ||
const validated = validateName(componentName); | ||
if (validated !== true) { | ||
return console.error(validated); | ||
} | ||
|
||
// declare dir | ||
const dir = path.join(process.cwd(), "src", "lib", componentName); | ||
|
||
// if directory exists show error, else create files | ||
if (fs.existsSync(dir)) { | ||
console.error("Directory already exists"); | ||
} else { | ||
// create directory | ||
fs.mkdirSync(dir, { recursive: true }); | ||
|
||
// create Component.svelte (blank) | ||
const svelteFilePath = path.join(dir, `${componentName}.svelte`); | ||
fs.writeFileSync(svelteFilePath, "", "utf8"); | ||
|
||
// create Component.docs.md | ||
const docsFilePath = path.join(dir, `${componentName}.docs.md`); | ||
fs.writeFileSync(docsFilePath, createDocs(componentName), "utf8"); | ||
|
||
// create Component.stories.svelte | ||
const storyFilePath = path.join(dir, `${componentName}.stories.svelte`); | ||
fs.writeFileSync(storyFilePath, createStory(componentName), "utf8"); | ||
|
||
// Confirmation text | ||
console.log(`Boilerplate files created in ${dir}`); | ||
} | ||
} | ||
|
||
async function main() { | ||
// if there's an argument in the command, use it (but no more) | ||
if (process.argv[2] && !process.argv[3]) { | ||
createFiles(process.argv[2]); | ||
} else { | ||
// show input | ||
await input({ | ||
message: "What is the name of your component? (ie: MyComponent)", | ||
validate: validateName | ||
}).then(createFiles); | ||
} | ||
} | ||
|
||
main().catch(console.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,8 @@ | ||
export function createDocs(componentName) { | ||
return `Esse ipsum deserunt dolor minim dolore sunt cillum. | ||
\`\`\`js | ||
import { ${componentName} } from "@urbaninstitute/dataviz-components"; | ||
\`\`\` | ||
`; | ||
} |
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,32 @@ | ||
export function createStory(componentName) { | ||
return `<script context="module"> | ||
import TestingTree from "./TestingTree.svelte"; | ||
import docs from "./TestingTree.docs.md?raw"; | ||
export const meta = { | ||
title: "Components/TestingTree", | ||
component: TestingTree, | ||
tags: ["autodocs"], | ||
parameters: { | ||
docs: { | ||
description: { | ||
component: docs | ||
} | ||
}, | ||
githubLink: { | ||
url: "/TestingTree/TestingTree.svelte" | ||
} | ||
} | ||
}; | ||
</script> | ||
<script> | ||
import { Story, Template } from "@storybook/addon-svelte-csf"; | ||
</script> | ||
<Template let:args> | ||
<TestingTree {...args} /> | ||
</Template> | ||
<Story name="Default" />`; | ||
} |
Oops, something went wrong.