-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(): linking and building components
- Loading branch information
Showing
11 changed files
with
336 additions
and
10 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,44 @@ | ||
#!/usr/bin/env node | ||
import program from './program' | ||
import commands from './commands' | ||
import session from './utils/session' | ||
import context from './utils/context' | ||
import validateCommands from './utils/validate-commands' | ||
import { echo } from './utils/print-tools' | ||
|
||
const setup = async () => { | ||
await context.session.load() | ||
|
||
program | ||
.command('link <path>') | ||
.group('Components') | ||
.description('Link all components to your project') | ||
.action(async (...options) => { | ||
session.isAuthenticated() | ||
session.hasProject() | ||
echo() | ||
new commands.ComponentLink(context).run(options) | ||
}) | ||
|
||
program | ||
.command('list') | ||
.group('Components') | ||
.description('List all components') | ||
.action(async (...options) => { | ||
session.isAuthenticated() | ||
session.hasProject() | ||
echo() | ||
new commands.ComponentList(context).run(options) | ||
}) | ||
|
||
program | ||
.on('*', (commandsArr) => validateCommands(commandsArr)) | ||
|
||
if (!process.argv.slice(2).length) { | ||
program.outputHelp() | ||
} | ||
|
||
program.parse(process.argv) | ||
} | ||
|
||
setup() |
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,25 @@ | ||
import path from 'path' | ||
import format from 'chalk' | ||
import { echo, echon } from '../utils/print-tools' | ||
|
||
export default class ComponentLink { | ||
constructor (context) { | ||
this.session = context.session | ||
this.Socket = context.Socket | ||
this.Component = context.Component | ||
} | ||
|
||
async run ([projectPath, cmd]) { | ||
const sockets = await this.Socket.listLocal() | ||
const prints = sockets.map(async socket => { | ||
const components = await this.Socket.getLocal(socket).getComponents() | ||
return components.forEach(async component => { | ||
echon(4)(`Linking component ${format.cyan.bold(component.packageName)}...`) | ||
component.linkWithProject(path.join(process.cwd(), projectPath)) | ||
echo(format.green(' Done')) | ||
}) | ||
}) | ||
await Promise.all(prints) | ||
echo() | ||
} | ||
} |
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,45 @@ | ||
import format from 'chalk' | ||
import logger from '../utils/debug' | ||
import { echo } from '../utils/print-tools' | ||
|
||
const { info, debug } = logger('cmd-component-list') | ||
|
||
export default class ComponentList { | ||
constructor (context) { | ||
this.session = context.session | ||
this.Socket = context.Socket | ||
this.Component = context.Component | ||
} | ||
|
||
async run ([projetPath, cmd]) { | ||
info('ComponentLink.run') | ||
|
||
const sockets = await this.Socket.listLocal() | ||
sockets.forEach(async socket => { | ||
const components = await this.Socket.getLocal(socket).getComponents() | ||
components.forEach(component => { | ||
this.printComponent(component) | ||
}) | ||
}) | ||
} | ||
|
||
async printComponent (component) { | ||
debug('printComponent') | ||
const metadata = component.metadata | ||
|
||
echo(4)(`${format.cyan.bold('name')}: ${format.cyan.bold(component.packageName)}`) | ||
echo(4)(`${format.dim('socket')}: ${component.socketName}`) | ||
|
||
if (metadata.parameters) { | ||
echo() | ||
Object.keys(metadata.parameters).forEach(paramName => { | ||
const paramObj = metadata.parameters[paramName] | ||
echo(8)(`${format.dim('name')}: ${format.cyan(paramName) || ''}`) | ||
echo(8)(`${format.dim('description')}: ${paramObj.description}`) | ||
echo(8)(`${format.dim('example')}: ${paramObj.example}`) | ||
echo() | ||
}) | ||
} | ||
echo() | ||
} | ||
} |
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,18 @@ | ||
import session from '../session' | ||
import Socket from '../sockets' | ||
|
||
class Component { | ||
constructor () { | ||
this.session = session | ||
} | ||
|
||
static async list () { | ||
const sockets = await Socket.list() | ||
sockets.forEach(async socket => { | ||
const components = await socket.getComponents() | ||
console.log(socket.name, components) | ||
}) | ||
} | ||
} | ||
|
||
export default Component |
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,3 @@ | ||
import Component from './component' | ||
|
||
export default Component |
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,13 +1,15 @@ | ||
import Init from './init' | ||
import Hosting from './hosting' | ||
import Socket from './sockets' | ||
import Component from './component' | ||
import Registry from './registry' | ||
import session from './session' | ||
|
||
export default { | ||
Init, | ||
Hosting, | ||
Socket, | ||
Component, | ||
Registry, | ||
session | ||
} |
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,9 @@ | ||
class CompileError { | ||
constructor (traceback) { | ||
this.traceback = traceback | ||
} | ||
} | ||
|
||
export { | ||
CompileError | ||
} |
Oops, something went wrong.