-
Notifications
You must be signed in to change notification settings - Fork 182
feat/cli #572
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
Open
JayaKrishnaNamburu
wants to merge
25
commits into
development
Choose a base branch
from
feat/cli-beta
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat/cli #572
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
6d00746
Initial Setup
JayaKrishnaNamburu 2e214f2
refactor(cli): setup cli for development
JayaKrishnaNamburu 78e2e5e
Adding missing @types for packages
JayaKrishnaNamburu ccd1edd
fix(mapper): disable watcher for cli and improve cli worklflow
JayaKrishnaNamburu bf64ae4
DIsabling validator in project temporarly
JayaKrishnaNamburu 4446724
refactor(mapper): improving project validator error messages and bug …
JayaKrishnaNamburu 1c44ccc
(feat): Parsing abilitites to generate links
JayaKrishnaNamburu f979ae8
refactor(cli): by default fallback to project generation
JayaKrishnaNamburu 4f24a34
Refacotring code generator
JayaKrishnaNamburu 130e4a2
Merge branch 'development' into feat/cli-beta
JayaKrishnaNamburu 0a52ce9
refactor(proj-plugin): improvements in handling project plugins
JayaKrishnaNamburu b48bfa5
name bug fixes for generated projects
JayaKrishnaNamburu fc31206
Merge branch 'development' into feat/cli-beta
JayaKrishnaNamburu 6c176e7
Merging development and changes for build for cli and mapper
JayaKrishnaNamburu 7f17a43
Merge branch 'development' into feat/cli-beta
JayaKrishnaNamburu 16e0c09
Merge branch 'development' into feat/cli-beta
JayaKrishnaNamburu e1a82af
Bringing cli to working state
JayaKrishnaNamburu a15ef4f
Extracting few packages and access to editorcc env too
JayaKrishnaNamburu 4717bdd
Fixing lint errors
JayaKrishnaNamburu 24b0d95
Plugin workflow setup for using teleport-cli
JayaKrishnaNamburu d543dab
Merge branch 'development' into feat/cli-beta
JayaKrishnaNamburu 0f6bcf9
Merge branch 'development' into feat/cli-beta
JayaKrishnaNamburu 3a3efa4
Update lock file
JayaKrishnaNamburu 080e5b4
Update correction for component detection andd upgraded to generators
JayaKrishnaNamburu 859f7e6
Merge branch 'development' into feat/cli-beta
JayaKrishnaNamburu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,63 @@ | ||
## @teleporthq/teleport-cli | ||
|
||
### Clone a Project | ||
|
||
```shell | ||
teleport clone --link <link-to-project> --path <sys-path> | ||
|
||
teleport clone -l https://repl.teleporthq.io/project/2c5878e9-1bbc-4f7c-a27a-b8822dd39571 | ||
|
||
teleport clone --link https://teleport-gui-git-development-teleport-team.vercel.app/projects/new-project-zan7 | ||
``` | ||
|
||
### Clone a Component | ||
|
||
```shell | ||
teleport clone --link <link-to-component> --path <sys-path> | ||
|
||
teleport clone --link https://repl.teleporthq.io/\?uidlLink\=35c82f1c-d272-4f8b-8a3f-5fa44702a1e6\&flavor\=React\&style\=CSS-Modules | ||
|
||
teleport clone --link https://teleport-gui-git-development-teleport-team.vercel.app/projects/new-project-zan7/editor/5c3c97d9-98e9-4649-b654-b9103a99c200 --path /components | ||
``` | ||
|
||
### Format | ||
After cloning and resolving merge conflicts. If we want to format, please run | ||
|
||
```shell | ||
teleport format --path <sys-path> | ||
|
||
teleport format -p /components | ||
|
||
teleport format | ||
``` | ||
|
||
### Sync | ||
|
||
Using `teleport.config.json` and sync's the project and component's used. | ||
|
||
```shell | ||
teleport sync | ||
``` | ||
|
||
We can use `--force` to `overwrite` local files with remote changes. | ||
|
||
```shell | ||
teleport sync --force | ||
``` | ||
|
||
### Init | ||
|
||
Creates a `teleport.config.json` in a existing project | ||
|
||
```shell | ||
teleport init | ||
``` | ||
|
||
### Dev Workflow | ||
|
||
- Install `dependencies` using `yarn` in the root folder. Under `teleport-code-generator`. | ||
- Run `yarn build` to build the project. | ||
- Run `yarn link` to create a `sym-link`. | ||
- Now go to the required folder and run `yarn link "@teleporthq/teleport-cli"`where we want to use the command line. | ||
- To run the `cli` in watch mode, please run `yarn dev`. This will re-complie the `.ts` files every-time we make changes. | ||
|
This file contains hidden or 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 @@ | ||
{ | ||
"name": "@teleporthq/teleport-cli", | ||
"version": "0.16.3", | ||
"description": "A command line utility to sync work from studio and other sources to local.", | ||
"author": "teleportHQ", | ||
"license": "MIT", | ||
"homepage": "https://teleporthq.io/", | ||
"types": "dist/src/index.d.ts", | ||
"sideEffects": false, | ||
"main": "dist/src/index.js", | ||
"bin": { | ||
"teleport": "dist/src/index.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://[email protected]/teleporthq/teleport-code-generators.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/teleporthq/teleport-code-generators/issues" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"clean": "rimraf dist", | ||
"dev": "tsc -p tsconfig-cjs.json --watch", | ||
"build": "tsc -p tsconfig-cjs.json" | ||
}, | ||
"dependencies": { | ||
"@teleporthq/teleport-code-generator": "^0.16.3", | ||
"@teleporthq/teleport-postprocessor-prettier-html": "^0.16.3", | ||
"@teleporthq/teleport-postprocessor-prettier-jsx": "^0.16.3", | ||
"@teleporthq/teleport-postprocessor-prettier-ts": "^0.16.3", | ||
"@teleporthq/teleport-postprocessor-vue-file": "^0.16.3", | ||
"@teleporthq/teleport-types": "^0.16.3", | ||
"@teleporthq/teleport-mapper": "^0.16.3", | ||
"chalk": "^4.1.1", | ||
"commander": "^7.2.0", | ||
"diff": "^5.0.0", | ||
"fs-extra": "^9.1.0", | ||
"minimist": "^1.2.5", | ||
"node-fetch": "^2.6.1", | ||
"ora": "^5.4.0" | ||
} | ||
} | ||
|
This file contains hidden or 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,126 @@ | ||
import { ProjectType, VComponentUIDL, VProjectUIDL } from '@teleporthq/teleport-types' | ||
import { | ||
fetchSnapshotFromPlayground, | ||
fetchUIDLFromREPL, | ||
generateComponentFromUIDL, | ||
generateProjectFromUIDL, | ||
} from '../services' | ||
import { injectFilesToPath } from '../services/file' | ||
import { getComponentType, updateConfigFile } from '../utils' | ||
import { MapSnapshotToUIDL } from '@teleporthq/teleport-mapper' | ||
import ora from 'ora' | ||
|
||
/* Basic projects seems to generate | ||
- Fonts & Assets | ||
- Default Element Styles (Buttons) | ||
*/ | ||
|
||
export default async function (options: { url: string; targetPath: string; force?: boolean }) { | ||
const { url, targetPath, force = false } = options | ||
let uidl: VComponentUIDL | VProjectUIDL | ||
const spinner = ora() | ||
spinner.start() | ||
// Assuming it is coming from playground | ||
if (url.includes('teleport') && !url.includes('repl.teleporthq.io')) { | ||
const opts = url.split('/') | ||
if (opts.length === 5) { | ||
try { | ||
spinner.text = `Fetching from studio ${opts[4]} \n` | ||
|
||
const { | ||
snapshot: { data }, | ||
} = await fetchSnapshotFromPlayground(opts[4]) | ||
const mapper = new MapSnapshotToUIDL(data) | ||
uidl = mapper.toProjectUIDL() | ||
|
||
if (!uidl) { | ||
throw new Error('Failed in Generating Project') | ||
} | ||
|
||
await generateProjectFromUIDL({ | ||
uidl, | ||
projectType: ProjectType.NEXT, | ||
targetPath, | ||
url, | ||
force, | ||
}) | ||
|
||
spinner.text = `Project Generated Successfully` | ||
spinner.succeed() | ||
} catch (e) { | ||
spinner.text = `Project Generation Failed` | ||
spinner.fail() | ||
} | ||
} | ||
|
||
if (opts.length >= 7) { | ||
try { | ||
spinner.text = `Fetching from studio ${opts[4]} \n` | ||
|
||
const { | ||
snapshot: { data }, | ||
} = await fetchSnapshotFromPlayground(opts[4]) | ||
const mapper = new MapSnapshotToUIDL(data) | ||
uidl = mapper.componentToUIDL(opts[6]) | ||
|
||
if (!uidl) { | ||
throw new Error('Failed in Generating Project') | ||
} | ||
|
||
const { files } = await generateComponentFromUIDL(uidl, getComponentType()) | ||
injectFilesToPath(process.cwd(), targetPath, files, force) | ||
updateConfigFile((content) => { | ||
content.components[url] = { url, path: targetPath } | ||
}) | ||
|
||
spinner.text = `Component ${files[0].name}.${files[0].fileType} generated` | ||
spinner.succeed() | ||
} catch (e) { | ||
spinner.text = 'Failed in generating project' | ||
spinner.fail() | ||
} | ||
} | ||
} | ||
|
||
if (url.includes('repl.teleporthq.io')) { | ||
/* Generating projects */ | ||
if (url.includes('project')) { | ||
try { | ||
spinner.text = `Fetching project from repl \n` | ||
|
||
uidl = (await fetchUIDLFromREPL(url)) as VProjectUIDL | ||
await generateProjectFromUIDL({ | ||
uidl, | ||
projectType: ProjectType.NEXT, | ||
targetPath, | ||
url, | ||
force, | ||
}) | ||
|
||
spinner.text = `Project Generated Successfully` | ||
spinner.succeed() | ||
} catch (e) { | ||
spinner.text = `Project Generation Failed` | ||
spinner.fail() | ||
} | ||
} else { | ||
try { | ||
spinner.text = `Fetching component from repl \n` | ||
|
||
uidl = (await fetchUIDLFromREPL(url)) as VComponentUIDL | ||
const { files } = await generateComponentFromUIDL(uidl, getComponentType()) | ||
injectFilesToPath(process.cwd(), targetPath, files, force) | ||
updateConfigFile((content) => { | ||
content.components[url] = { url, path: targetPath } | ||
}) | ||
|
||
spinner.text = `Component ${files[0].name}.${files[0].fileType} generated` | ||
spinner.succeed() | ||
} catch (e) { | ||
spinner.text = `Component Generation Failed` | ||
spinner.fail() | ||
} | ||
} | ||
} | ||
spinner.stop() | ||
} |
This file contains hidden or 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 ora from 'ora' | ||
import path from 'path' | ||
import { readdirSync, writeFileSync, readFileSync, lstatSync } from 'fs-extra' | ||
import { FileType, PostProcessor } from '@teleporthq/teleport-types' | ||
import processorVUE from '@teleporthq/teleport-postprocessor-vue-file' | ||
import processorTS from '@teleporthq/teleport-postprocessor-prettier-ts' | ||
import processorJSX from '@teleporthq/teleport-postprocessor-prettier-jsx' | ||
import processorHTML from '@teleporthq/teleport-postprocessor-prettier-html' | ||
import { IGNORE_EXTENSIONS, IGNORE_FOLDERS } from '../constants' | ||
|
||
/* Fromat is currently broken, please check */ | ||
const processors: Record<string, PostProcessor> = { | ||
[FileType.JS]: processorJSX, | ||
[FileType.HTML]: processorHTML, | ||
[FileType.VUE]: processorVUE, | ||
[FileType.TS]: processorTS, | ||
} | ||
/* We can extend the prettier config, ignore folders, ignore extensions */ | ||
const format = async ({ targetPath }: { targetPath: string }) => { | ||
formatFilesFromFolder(targetPath) | ||
} | ||
|
||
const formatFilesFromFolder = (folderPath: string) => { | ||
try { | ||
const files: string[] = readdirSync(path.join(process.cwd(), folderPath)) | ||
if (files.length === 0) { | ||
return | ||
} | ||
|
||
files.forEach((fileName) => { | ||
if ( | ||
IGNORE_FOLDERS.includes(fileName) || | ||
IGNORE_EXTENSIONS.some((ext) => fileName.endsWith(ext)) || | ||
fileName.startsWith('.') | ||
) { | ||
return | ||
} | ||
|
||
const fileStatus = ora(fileName) | ||
try { | ||
const filePath = path.join(process.cwd(), folderPath, fileName) | ||
const isDirectory = lstatSync(filePath).isDirectory() | ||
if (!isDirectory) { | ||
const file = readFileSync(filePath) | ||
const fileExtension = path.extname(filePath)?.substring(1) | ||
const processor = processors[fileExtension] | ||
if (processor) { | ||
const formattedCode = processor({ [fileExtension]: file.toString('utf-8') }) | ||
writeFileSync(filePath, formattedCode[fileExtension]) | ||
fileStatus.succeed() | ||
} | ||
return | ||
} | ||
formatFilesFromFolder(path.join(folderPath, fileName)) | ||
} catch (e) { | ||
fileStatus.text = `Failed in formatting file ${fileName}` | ||
fileStatus.fail() | ||
} | ||
}) | ||
} catch (e) { | ||
console.warn(e) | ||
} | ||
} | ||
|
||
export default format |
This file contains hidden or 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,17 @@ | ||
import chalk from 'chalk' | ||
import { writeFileSync } from 'fs-extra' | ||
import path from 'path' | ||
import { DEFAULT_CONFIG_FILE_NAME, DEFALT_CONFIG_TEMPLATE } from '../constants' | ||
import { findFileByName } from '../services/file' | ||
|
||
export default function () { | ||
const isFileExists = findFileByName(DEFAULT_CONFIG_FILE_NAME) | ||
if (!isFileExists) { | ||
writeFileSync( | ||
path.join(process.cwd(), DEFAULT_CONFIG_FILE_NAME), | ||
JSON.stringify(DEFALT_CONFIG_TEMPLATE, null, 2) | ||
) | ||
return | ||
} | ||
console.warn(chalk.yellow(`${DEFAULT_CONFIG_FILE_NAME} already exists`)) | ||
} |
This file contains hidden or 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,23 @@ | ||
import chalk from 'chalk' | ||
import { DefaultConfigTemplate, DEFAULT_CONFIG_FILE_NAME } from '../constants' | ||
import { findFileByName } from '../services/file' | ||
import clone from './clone' | ||
|
||
/* By default sync only components specified ? */ | ||
export default async function sync({ force }: { force: boolean }) { | ||
const config = findFileByName(DEFAULT_CONFIG_FILE_NAME) | ||
if (!config) { | ||
console.warn(chalk.yellow(`${DEFAULT_CONFIG_FILE_NAME} is missing from project.`)) | ||
} | ||
|
||
const { components = {}, project } = JSON.parse(config) as DefaultConfigTemplate | ||
|
||
if (project?.url) { | ||
clone({ url: project.url, targetPath: '../', force }) | ||
} | ||
|
||
Object.values(components).forEach((comp) => { | ||
const { url, path: targetPath } = comp | ||
clone({ url, targetPath, force }) | ||
}) | ||
} |
This file contains hidden or 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,21 @@ | ||
import ora from 'ora' | ||
import { findFileByName } from '../services/file' | ||
import { DEFAULT_CONFIG_FILE_NAME } from '../constants' | ||
import { extractCompIdsFromURls } from '../utils' | ||
|
||
/* Watch takes a set of components defined and tried to observe for changes. | ||
And loads then on request */ | ||
|
||
export default async function () { | ||
const content = JSON.parse(findFileByName(DEFAULT_CONFIG_FILE_NAME)) | ||
const { components = [] } = content || {} | ||
if (components.length === 0) { | ||
return | ||
} | ||
const compIds = extractCompIdsFromURls(components) | ||
const spinner = ora(`Watching components \n ${JSON.stringify(compIds)}`) | ||
spinner.start() | ||
setTimeout(() => { | ||
spinner.stop() | ||
}, 1000) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.