Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

43 changes: 0 additions & 43 deletions .eslintrc.json

This file was deleted.

7 changes: 3 additions & 4 deletions .github/workflows/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ name: CLI test

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]

jobs:
test:
Expand All @@ -15,10 +14,10 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 22

Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ name: Node.js CI

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]

jobs:
build:
Expand All @@ -16,13 +15,13 @@ jobs:

strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
node-version: [20.x, 22.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ playground/src
.idea/

*.iml
*.iws
*.iws

dist/
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

- Make sure to run `npm test` and `npm run lint:fix` after changes have been finished
- Keep the project lightweight and avoid adding more dependencies
- Make sure to update `src/serve-mocks.spec.js` with tests for new features, it is basically a kind of e2e test which covers most of logic
- Make sure to update existing unit tests or create new ones for new features

## Scripts

Expand Down
8 changes: 8 additions & 0 deletions cli.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env node
export interface AppConfig {
types: string[] | null;
templatePath: string;
componentPath: string;
nameStyle: string;
}
//# sourceMappingURL=cli.d.ts.map
1 change: 1 addition & 0 deletions cli.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 36 additions & 15 deletions cli.js → cli.ts
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
processInitCommand,
processPromptCommand,
processUpgradeCommand,
type CommandEnv,
} from './src/commands.js'
import { getDirectories } from './src/utilities.js'
import { readFileSync, existsSync } from 'fs'
Expand All @@ -16,24 +17,27 @@ import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

interface AppConfig {
types: string[] | null
templatePath: string
componentPath: string
nameStyle: string
}

const CONFIG_DIRECTORY = '.create-frontend-component'
const CONFIG_FILE_NAME = 'config.json'
const PRESET_DIR = 'presets'
const PRESET_PATH = path.join(__dirname, PRESET_DIR)

const configDefaults = {
const configDefaults: AppConfig = {
types: ['atoms', 'molecules', 'organisms'],
templatePath: CONFIG_DIRECTORY + '/templates',
templatePath: `${CONFIG_DIRECTORY}/templates`,
componentPath: 'src/components',
nameStyle: 'pascalCase'
}

/**
* @return {object}
*/
function loadConfig() {
const filePath = path.resolve(process.cwd(), '.create-frontend-component', 'config.json')
function loadConfig(): AppConfig {
const filePath = path.resolve(process.cwd(), CONFIG_DIRECTORY, CONFIG_FILE_NAME)

try {
if (!existsSync(filePath)) {
Expand All @@ -46,22 +50,32 @@ function loadConfig() {
const configFromFile = JSON.parse(fileContent)

return {
...configDefaults,
types: configDefaults.types ?? null,
templatePath: configDefaults.templatePath,
componentPath: configDefaults.componentPath,
nameStyle: configDefaults.nameStyle,
...configFromFile
}
} catch (error) {
console.error(`Error loading configuration file: ${error.message}`)
console.error(`Error loading configuration file: ${(error as Error).message}`)
console.error('Try running "npx create-frontend-component init" to reset the configuration.')
process.exit(1)
}
}

const packageJsonPath = path.join(__dirname, '..', 'package.json')
const { version } = JSON.parse(readFileSync(packageJsonPath, { encoding: 'utf-8' }))

program
.name('create-frontend-component')
.description('Frontend Component Generator')
.version(version)

program
.version('2.1.0')
.command('create-frontend-component [component-name]') // Define the command
.option( '-t, --type <type>', 'Component type, default: atoms')
.option( '-f, --flavour <flavour>', 'Component flavour')
.action( async function(componentNameArg, env) {
.command('create-frontend-component [component-name]')
.option('-t, --type <type>', 'Component type, default: atoms')
.option('-f, --flavour <flavour>', 'Component flavour')
.action(async function(componentNameArg: string | undefined, env: CommandEnv) {
const componentName = componentNameArg || ''

if (componentName.toLowerCase() === 'init') {
Expand All @@ -81,6 +95,12 @@ program
const fullTemplatePath = path.join(process.cwd(), templatePath)
const availableFlavours = getDirectories(fullTemplatePath)

if (availableFlavours.length === 0) {
console.error('Error: No flavours found in template directory.')
console.error(`Please ensure templates exist in ${fullTemplatePath}`)
process.exit(1)
}

if (componentName.toLowerCase() === 'prompt' || !componentName.trim()) {
await processPromptCommand(allowedComponentTypes, availableFlavours, fullTemplatePath, componentPath, nameStyle)
} else if (componentName.toLowerCase() === 'upgrade') {
Expand All @@ -89,4 +109,5 @@ program
processCreateComponentCommand(env, allowedComponentTypes, fullTemplatePath, componentPath, componentName, availableFlavours, nameStyle)
}
})
.parse(process.argv)

program.parse(process.argv)
33 changes: 33 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import tseslint from 'typescript-eslint'

export default tseslint.config(
tseslint.configs.recommended,
{
files: ['**/*.ts'],
ignores: ['**/*.spec.ts', 'dist', 'node_modules'],
languageOptions: {
parserOptions: {
project: './tsconfig.json',
},
},
rules: {
'prefer-const': 'error',
'object-curly-spacing': ['warn', 'always'],
'indent': ['error', 2],
'linebreak-style': ['error', 'unix'],
'quotes': ['error', 'single'],
'semi': ['warn', 'never'],
'comma-dangle': ['error', 'only-multiline'],
'@typescript-eslint/no-unused-vars': ['error', { 'argsIgnorePattern': '^_' }],
},
},
{
files: ['**/*.spec.ts'],
rules: {
'@typescript-eslint/no-unused-vars': 'off',
},
},
{
ignores: ['dist', 'node_modules', 'coverage'],
}
)
Loading