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

Fix cli not working, tiged replaced with git-simple #31

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion bin/dev.cmd
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@echo off

node "%~dp0\dev" %*
node --loader ts-node/esm --no-warnings=ExperimentalWarning "%~dp0\dev" %*
12 changes: 6 additions & 6 deletions bin/dev.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env ts-node
// eslint-disable-next-line node/shebang, unicorn/prefer-top-level-await
(async () => {
const oclif = await import('@oclif/core')
await oclif.execute({development: true, dir: __dirname})
})()
#!/usr/bin/env -S node --loader ts-node/esm --disable-warning=ExperimentalWarning

// eslint-disable-next-line n/shebang
import {execute} from '@oclif/core'

await execute({development: true, dir: import.meta.url})
8 changes: 3 additions & 5 deletions bin/run.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env node

// eslint-disable-next-line unicorn/prefer-top-level-await
(async () => {
const oclif = await import('@oclif/core')
await oclif.execute({development: false, dir: __dirname})
})()
import { execute } from '@oclif/core'

await execute({ dir: import.meta.url })
28 changes: 13 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,30 @@
"dependencies": {
"@clack/core": "^0.3.3",
"@clack/prompts": "^0.7.0",
"@oclif/core": "^3",
"@oclif/plugin-help": "^5",
"@oclif/plugin-plugins": "^4",
"@oclif/core": "^4",
"@oclif/plugin-help": "^6",
"@oclif/plugin-plugins": "^5",
"picocolors": "^1.0.0",
"tiged": "^2.12.5"
"simple-git": "^3.25.0"
},
"devDependencies": {
"@oclif/prettier-config": "^0.2.1",
"@oclif/test": "^3",
"@oclif/test": "^4",
"@types/chai": "^4",
"@types/mocha": "^9.0.0",
"@types/mocha": "^10",
"@types/node": "^18",
"chai": "^4",
"eslint": "^8.52.0",
"eslint-config-oclif": "^5",
"eslint-config-oclif-typescript": "^3",
"eslint-config-prettier": "^9.0.0",
"mocha": "^10",
"oclif": "^3.17.2",
"oclif": "^4",
"shx": "^0.3.4",
"ts-node": "^10.9.1",
"typescript": "^5"
},
"type": "module",
"engines": {
"node": ">=18.0.0"
},
Expand All @@ -45,19 +46,16 @@
"main": "dist/index.js",
"oclif": {
"bin": "create-ceramic-app",
"default": "clone",
"hooks": {
"init": "./dist/hooks/init"
},
"dirname": "create-ceramic-app",
"commands": "./dist/commands",
"plugins": [
"@oclif/plugin-help",
"@oclif/plugin-plugins"
],
"topicSeparator": " ",
"topics": {
"clone": {
"description": "Create a sample app with Ceramic and ComposeDB"
}
}
"topicSeparator": " "
},
"repository": "git+https://github.com/ceramicstudio/create-ceramic-app.git",
"scripts": {
Expand All @@ -74,4 +72,4 @@
"oclif"
],
"types": "dist/index.d.ts"
}
}
47 changes: 29 additions & 18 deletions src/commands/clone/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
import {cancel, intro, isCancel, note, outro, select, spinner, text} from '@clack/prompts'
import {Command} from '@oclif/core'
import {execSync} from 'node:child_process'
import {bgBlue, bgGreen, black, green, inverse} from 'picocolors'
const tiged = require('tiged')
import fs from 'node:fs';
import path from 'node:path';
import picocolors from 'picocolors'
const { bgBlue, bgGreen, black, green, inverse } = picocolors;

import {simpleGit} from 'simple-git'


export default class Clone extends Command {
static description = "Create a sample app with Ceramic and ComposeDB"

export default class DefaultCommand extends Command {
async run(): Promise<void> {
this.log(' ')
const clack = await import('@clack/prompts');
const sp = clack.spinner()

const sp = spinner()

intro(`${bgGreen(black(' 🧡 Welcome! Let us build you a ComposeDB example app. '))}`)
clack.intro(`${bgGreen(black(' 🧡 Welcome! Let us build you a ComposeDB example app. '))}`)

// picocolors options:
// bold, dim, italic, underline, inverse, hidden, strikethrough,
// black, red, green, yellow, blue, magenta, cyan, white, gray,
// bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite

const getProjectName = async (message: string, defaultName: string): Promise<string> => {
const projectName = await text({
const projectName = await clack.text({
message,
placeholder: defaultName,
validate(value: string = ''): string | void {
Expand All @@ -30,9 +36,9 @@ export default class DefaultCommand extends Command {
return undefined
},
})
if (isCancel(projectName)) {
cancel('Canceling.')
process.exit(0)
if (clack.isCancel(projectName)) {
clack.cancel('Canceling.')
throw process.exit(0)
}

return (projectName || defaultName).toLowerCase()
Expand All @@ -43,9 +49,14 @@ export default class DefaultCommand extends Command {
// Clone repository from https://github.com/ceramicstudio/ComposeDbExampleApp.git
sp.start('Cloning CeramicDB Example App from repository...')
try {
await tiged('https://github.com/ceramicstudio/ComposeDbExampleApp.git').clone(projectName)
const git = simpleGit();
await git.clone('https://github.com/ceramicstudio/ComposeDbExampleApp.git', projectName, ['--depth', '1'])
// Remove the .git directory to avoid keeping the git history
fs.rmSync(path.join(projectName, '.git'), { force: true, recursive: true });
} catch (error) {
console.error('Error occurred while cloning the repository:', error)
sp.stop("Failed to clone repository")
return;
}

sp.stop(green('✅ Repository cloned. ⬇️ Now installing dependencies...'))
Expand Down Expand Up @@ -76,9 +87,9 @@ export default class DefaultCommand extends Command {
please use Wheel to generate a development environment.
Instructions for Wheel: ${bgBlue('https://developers.ceramic.network/docs/composedb/set-up-your-environment')}
`
note(infoMsg)
clack.note(infoMsg)

const readyToLaunch = await select({
const readyToLaunch = await clack.select({
message: '🎉 Your Ceramic app with ComposeDB is ready! Ready to launch it now?',
initialValue: 'Yes',
options: [
Expand All @@ -87,9 +98,9 @@ export default class DefaultCommand extends Command {
],
})

if (readyToLaunch == 'Yes') {
if (readyToLaunch === 'Yes') {
// Launch the example app
outro('🏎️ Launching your example app...')
clack.outro('🏎️ Launching your example app...')

try {
process.chdir(projectName)
Expand All @@ -99,7 +110,7 @@ export default class DefaultCommand extends Command {
}
} else {
// Don't launch the example app. Explain how to launch it manually.
note(`
clack.note(`
You don't have to launch the example app right now. You can do it later. It's easy!

Here's how to launch the example app manually, when you're ready:
Expand All @@ -108,7 +119,7 @@ export default class DefaultCommand extends Command {
3. Open ${bgBlue('http://localhost:3000')} in your browser
4. 🎉 Enjoy!
`)
outro(`${bgBlue(`🙏 Thanks and happy coding!`)}`)
clack.outro(`${bgBlue(`🙏 Thanks and happy coding!`)}`)
}
}
}
7 changes: 7 additions & 0 deletions src/hooks/init/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {Hook} from '@oclif/core'

const hook: Hook.CommandNotFound = async function (opts) {
await opts.config.runCommand('clone')
}

export default hook;
9 changes: 1 addition & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
import {Command} from '@oclif/core'

export default class DefaultCommand extends Command {
async run(): Promise<void> {
this.log('Running the default command...')
// Add your app creation logic here
}
}
export {run} from '@oclif/core'
15 changes: 11 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
{
"compilerOptions": {
"declaration": true,
"module": "commonjs",
"module": "Node16",
"outDir": "dist",
"rootDir": "src",
"strict": true,
"target": "es2022"
"target": "es2022",
"moduleResolution": "node16",
"esModuleInterop": true
},
"include": ["src/**/*"]
}
"include": [
"./src/**/*"
],
"ts-node": {
"esm": true
}
}