-
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 pull request #52 from ipetinate/feat/advanced-command
feat: Advanced command
- Loading branch information
Showing
41 changed files
with
1,697 additions
and
130 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,7 @@ | ||
# Scaffold Command | ||
|
||
> Generate resources with local templates | ||
- [Flow and process steps](https://excalidraw.com/#json=Ucl3J2Z61I3fx9JPVEkVV,4Ble4pYYHnbcr1nkK3IOHw) | ||
|
||
![Scaffold Code Flow](./img/scaffold-flow.svg) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
MD046: fenced |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,22 +1,44 @@ | ||
import { compose } from '../utils/compose.js' | ||
import { | ||
checkIfPresetFolderAlreadyExists, | ||
checkIfTemplateFolderAlreadyExists, | ||
createFileIfNotExists, | ||
createPresetFolderIfNotExists, | ||
getConfigContent, | ||
createPresetsFolderAssets, | ||
createTemplateFolderAssets, | ||
createTemplateFolderIfNotExists, | ||
getConfigFilePath | ||
} from '../utils/init-action.js' | ||
|
||
export async function initAction() { | ||
/** | ||
* Init clingon assets, generate necessary files and folders. | ||
* | ||
* @param {Record<"examples", boolean>} options Command options with flags, like `--e` | ||
*/ | ||
export async function initAction(options = { examples: false }) { | ||
/* | ||
* Global Config | ||
*/ | ||
|
||
compose(getConfigFilePath, createFileIfNotExists, getConfigContent) | ||
compose(getConfigFilePath(options?.examples), createFileIfNotExists) | ||
|
||
/* | ||
* Preset Folder | ||
*/ | ||
|
||
compose(checkIfPresetFolderAlreadyExists, createPresetFolderIfNotExists) | ||
compose( | ||
checkIfPresetFolderAlreadyExists(options?.examples), | ||
createPresetFolderIfNotExists, | ||
createPresetsFolderAssets | ||
) | ||
|
||
/* | ||
* Templates Folder | ||
*/ | ||
|
||
compose( | ||
checkIfTemplateFolderAlreadyExists(options?.examples), | ||
createTemplateFolderIfNotExists, | ||
createTemplateFolderAssets | ||
) | ||
} |
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,65 @@ | ||
import { join } from 'node:path' | ||
|
||
import { buildCustomTemplate } from '../generators/custom-template.js' | ||
|
||
import { | ||
getTemplateFromMetaFile, | ||
validateTemplate | ||
} from '../utils/scaffold-action.js' | ||
|
||
/** | ||
* Build resources from local custom templates | ||
* | ||
* @typedef {"template"} Options | ||
* | ||
* @param {string} name | ||
* @param {Record<Options, string>} options | ||
*/ | ||
|
||
export async function scaffoldAction(name, options) { | ||
/** | ||
* Templates folder path | ||
*/ | ||
const basePath = join(process.cwd(), '.clingon', 'templates') | ||
|
||
/** | ||
* Templates from meta file | ||
*/ | ||
const template = getTemplateFromMetaFile(options.template) | ||
|
||
/** | ||
* Template already be validated and flow can continue | ||
*/ | ||
const validationErrors = validateTemplate(template) | ||
|
||
if (validationErrors.length > 0) { | ||
console.error( | ||
`\n⎡ Template has many errors, review your meta file at: \n⎪\n⎣ → ${basePath}` | ||
) | ||
|
||
console.error(`\n⎡ Validation errors: \n⎪`) | ||
|
||
const last = validationErrors.length - 1 | ||
|
||
validationErrors.forEach((error, index) => | ||
console.error(`${last === index ? '⎣' : '⎪'} → ${error}`) | ||
) | ||
|
||
return | ||
} | ||
|
||
/** | ||
* Resources already be created | ||
* | ||
* @type {Record<"resource" | "test" | "story" | "style", string>} | ||
*/ | ||
const paths = await buildCustomTemplate(name, template) | ||
|
||
if (paths) showCreatedResources(paths) | ||
} | ||
|
||
export function showCreatedResources(paths) { | ||
console.info('⎧ 💿 Files successfully created at:\n⎪') | ||
|
||
paths.forEach((path) => console.info('⎪⎯→ ' + path)) | ||
} |
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,18 +1,3 @@ | ||
export const defaultConfig = { | ||
/** | ||
* Alias for text ocurrences replacement | ||
* | ||
* 🚨 Be careful, do not replace "resourcePath" or "ResourceName", to avoid generating strange behavior in the templates, | ||
* causing auto-completion to be unconfigured | ||
*/ | ||
alias: { | ||
/** | ||
* Will replace all `src` occurrences on templates to `@`, Example: `src/components/...` become `@/components/...` | ||
*/ | ||
src: '@' | ||
}, | ||
/** | ||
* If `true` will default export functions, components, pages, etc. Example: | ||
*/ | ||
exportDefault: false | ||
} |
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 @@ | ||
export const templateCoreFiles = [ | ||
{ | ||
folder: 'templates/core/functions', | ||
target: 'functions', | ||
files: ['AsyncFunction.ts', 'AsyncFunction.spec.ts'] | ||
}, | ||
{ | ||
folder: 'templates/core/markdown', | ||
target: 'docs', | ||
files: ['HookDoc.md'] | ||
}, | ||
{ | ||
folder: 'templates/core/react-component', | ||
target: 'components/react-component', | ||
files: [ | ||
'index.tsx', | ||
'Component.tsx', | ||
'Component.test.tsx', | ||
'Component.styles.css', | ||
'Component.stories.tsx' | ||
] | ||
}, | ||
{ | ||
folder: 'templates/core', | ||
target: '', | ||
files: ['meta.yaml', 'SCAFFOLD_GUIDE.md'] | ||
} | ||
] | ||
|
||
export const presetsCoreFiles = [ | ||
{ | ||
folder: 'templates/core', | ||
target: '', | ||
files: ['PRESETS_GUIDE.md', 'function-preset.json'] | ||
} | ||
] | ||
|
||
export const globalCoreFiles = [ | ||
{ | ||
folder: 'templates/core', | ||
target: '', | ||
files: ['clingon.config.json'] | ||
} | ||
] |
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.