-
Notifications
You must be signed in to change notification settings - Fork 5
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
Showing
30 changed files
with
2,283 additions
and
131 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env node | ||
const directoryTree = require('directory-tree') | ||
const path = require('path') | ||
const fs = require('fs') | ||
|
||
const iconsDirectory = path.join(__dirname, '..', 'src', 'assets', 'icons') | ||
const validSubdirectories = ['attribute', 'outline', 'twotone', 'fullcolor'] | ||
|
||
// Utility to remove redundant parent directory name from the filename | ||
function removeRedundantName(type, filename) { | ||
const pattern = | ||
type === 'attribute' ? /-outline$/ : new RegExp(`-${type}$`, 'i') | ||
return filename.replace(pattern, '') | ||
} | ||
|
||
function generateIconObject(tree) { | ||
if (!tree || !tree.children) return [] | ||
|
||
return tree.children | ||
.filter((child) => validSubdirectories.includes(child.name)) | ||
.flatMap((subdir) => { | ||
return subdir.children.map((file) => { | ||
const cleanName = removeRedundantName( | ||
subdir.name, | ||
path.basename(file.name, '.svg') | ||
) | ||
return { | ||
type: subdir.name, | ||
filepath: `${subdir.name}/${file.name}`, | ||
name: cleanName, | ||
alias: `${subdir.name}-${cleanName}`, | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
const tree = directoryTree(iconsDirectory, { extensions: /\.svg$/ }) | ||
|
||
if (!tree) { | ||
console.error( | ||
`Error: The icon assets folder ${iconsDirectory} does not exist or could not be accessed.` | ||
) | ||
process.exit(1) | ||
} | ||
|
||
const icons = generateIconObject(tree) | ||
const output = { | ||
icons: icons, | ||
} | ||
|
||
// Define the path to the output file | ||
const outputPath = path.join( | ||
__dirname, | ||
'..', | ||
'src', | ||
'app', | ||
'generated', | ||
'civic.icons.data.json' | ||
) | ||
|
||
// Write the JSON data to the file | ||
fs.writeFileSync(outputPath, JSON.stringify(output, null, 2)) | ||
|
||
console.log(`Icon data written to ${outputPath}`) |
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,46 @@ | ||
#!/usr/bin/env node | ||
const fs = require('fs') | ||
const path = require('path') | ||
const mustache = require('mustache') | ||
|
||
// Load the generated icon data JSON | ||
const jsonDataPath = path.join( | ||
__dirname, | ||
'..', | ||
'src', | ||
'app', | ||
'generated', | ||
'civic.icons.data.json' | ||
) | ||
const iconData = JSON.parse(fs.readFileSync(jsonDataPath, 'utf-8')) | ||
|
||
// Define the mustache template | ||
const template = ` | ||
.. |{{alias}}| image:: /images/icons/{{{filepath}}} | ||
:class: 'cvc-icon' | ||
` | ||
|
||
// Render the RST using mustache | ||
const renderedRst = | ||
'..\n ' + | ||
'GENERATED BY CiVIC CLIENT DEV SCRIPT, DO NOT EDIT\n ' + | ||
'(unless you know what you are doing)\n ' + | ||
'Produced by `generate-icon-rst` script in civic-v2/client/scripts\n' + | ||
iconData.icons.map((icon) => mustache.render(template, icon)).join('\n') | ||
|
||
// Define the path to the output RST file | ||
const outputPath = path.join( | ||
__dirname, | ||
'..', | ||
'src', | ||
'app', | ||
'generated', | ||
'civic.docs-aliases.rst' | ||
) | ||
|
||
// Write the rendered RST to the file | ||
fs.writeFileSync(outputPath, renderedRst) | ||
|
||
console.log( | ||
`RST written to ${outputPath}, copy to civic-docs/docs/generated to update docs aliases.` | ||
) |
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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
<div> | ||
<cvc-string-tag | ||
*ngFor="let tag of tags$ | ngrxPush" | ||
[cvcMode]="'closeable'" | ||
[cvcMode]="this.props.disabled ? 'default' : 'closeable'" | ||
[cvcLabel]="tag" | ||
(cvcOnClose)="tagClosed(tag)"></cvc-string-tag> | ||
<input nz-input | ||
(keydown.enter)="onEnter($event)" | ||
<input nz-input | ||
[disabled]="this.props.disabled" | ||
(keydown.enter)="onEnter($event)" | ||
[placeholder]="this.props.placeholder" /> | ||
</div> | ||
|
||
<input hidden nz-input [formControl]="formControl" [formlyAttributes]="field"/> | ||
<input hidden nz-input [formControl]="formControl" [formlyAttributes]="field"/> |
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.