Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a new CLI app to build a complete Module Federation project by… #39

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
169 changes: 90 additions & 79 deletions bin/create-mf-app.ts
Original file line number Diff line number Diff line change
@@ -1,106 +1,117 @@
#!/usr/bin/env node
import inquirer from 'inquirer'
import shell from 'shelljs'
import * as yargs from 'yargs'
import fs from 'fs'
import path from 'path'
import { buildProject } from '../src/index'
import { buildProject, buildProjectWithConfig } from '../src/index'
import { Project } from '../src/types'
;(async function () {
const answers = await inquirer.prompt<Project>([
{
type: 'input',
message: 'Pick the name of your app:',
name: 'name',
default: 'host',
},
{
type: 'list',
message: 'Project Type:',
name: 'type',
choices: ['Application', 'API Server', 'Library'],
default: 'Application',
},
])

if (answers.type === 'Library') {
buildProject(answers)
}
let args: any = yargs.option('path', {
alias: 'p',
demand: false,
}).argv

if (answers.type === 'API Server') {
const templates = fs
.readdirSync(path.join(__dirname, '../templates/server'))
.sort()

const serverAnswers = await inquirer.prompt<Project>([
if (args.path) {
buildProjectWithConfig(args.path)
} else {
;(async function () {
const answers = await inquirer.prompt<Project>([
{
type: 'input',
message: 'Port number:',
name: 'port',
default: '8080',
message: 'Pick the name of your app:',
name: 'name',
default: 'host',
},
{
type: 'list',
message: 'Template:',
name: 'framework',
choices: templates,
default: 'express',
message: 'Project Type:',
name: 'type',
choices: ['Application', 'API Server', 'Library'],
default: 'Application',
},
])

buildProject({
...answers,
...serverAnswers,
language: 'typescript',
})
}
if (answers.type === 'Library') {
buildProject(answers)
}

if (answers.type === 'Application') {
const templates = fs
.readdirSync(path.join(__dirname, '../templates/application'))
.sort()
if (answers.type === 'API Server') {
const templates = fs
.readdirSync(path.join(__dirname, '../templates/server'))
.sort()

const appAnswers = await inquirer.prompt<Project>([
{
type: 'input',
message: 'Port number:',
name: 'port',
default: '8080',
},
{
type: 'list',
message: 'Framework:',
name: 'framework',
choices: templates,
default: 'react',
},
{
type: 'list',
message: 'Language:',
name: 'language',
choices: ['typescript', 'javascript'],
default: 'javascript',
},
{
type: 'list',
message: 'CSS:',
name: 'css',
choices: ['CSS', 'Tailwind'],
default: 'CSS',
},
])
const serverAnswers = await inquirer.prompt<Project>([
{
type: 'input',
message: 'Port number:',
name: 'port',
default: '8080',
},
{
type: 'list',
message: 'Template:',
name: 'framework',
choices: templates,
default: 'express',
},
])

buildProject({
...answers,
...serverAnswers,
language: 'typescript',
})
}

if (answers.type === 'Application') {
const templates = fs
.readdirSync(path.join(__dirname, '../templates/application'))
.sort()

const appAnswers = await inquirer.prompt<Project>([
{
type: 'input',
message: 'Port number:',
name: 'port',
default: '8080',
},
{
type: 'list',
message: 'Framework:',
name: 'framework',
choices: templates,
default: 'react',
},
{
type: 'list',
message: 'Language:',
name: 'language',
choices: ['typescript', 'javascript'],
default: 'javascript',
},
{
type: 'list',
message: 'CSS:',
name: 'css',
choices: ['CSS', 'Tailwind'],
default: 'CSS',
},
])

buildProject({
...answers,
...appAnswers,
})
}
buildProject({
...answers,
...appAnswers,
})
}

shell.echo(`Your '${answers.name}' project is ready to go.
shell.echo(`Your '${answers.name}' project is ready to go.

Next steps:

▶️ cd ${answers.name}
▶️ npm install
▶️ npm start
`)
})()
})()
}
32 changes: 32 additions & 0 deletions mfconfig.example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apps:
- cart:
framework: react
language: typescript
port: 3000
css: tailwind
consumes:
- pdp
- cart
- home
- pdp:
framework: react
language: typescript
port: 3001
css: tailwind
consumes:
- pdp
- cart
- home
- home:
framework: react
language: typescript
port: 3002
css: tailwind
consumes:
- pdp
- cart
- home
servers:
- server:
framework: express
port: 8080
Loading