diff --git a/bin/dev.cmd b/bin/dev.cmd index 077b57a..cec553b 100644 --- a/bin/dev.cmd +++ b/bin/dev.cmd @@ -1,3 +1,3 @@ @echo off -node "%~dp0\dev" %* \ No newline at end of file +node --loader ts-node/esm --no-warnings=ExperimentalWarning "%~dp0\dev" %* diff --git a/bin/dev.js b/bin/dev.js index 93e1c6a..dd74804 100755 --- a/bin/dev.js +++ b/bin/dev.js @@ -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}) diff --git a/bin/run.js b/bin/run.js index 405685d..92b78ec 100755 --- a/bin/run.js +++ b/bin/run.js @@ -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 }) diff --git a/package.json b/package.json index 64daf28..6922601 100644 --- a/package.json +++ b/package.json @@ -9,17 +9,17 @@ "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", @@ -27,11 +27,12 @@ "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" }, @@ -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": { @@ -74,4 +72,4 @@ "oclif" ], "types": "dist/index.d.ts" -} +} \ No newline at end of file diff --git a/src/commands/clone/index.ts b/src/commands/clone/index.ts index df861df..7aa83b2 100644 --- a/src/commands/clone/index.ts +++ b/src/commands/clone/index.ts @@ -1,16 +1,22 @@ -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 { 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, @@ -18,7 +24,7 @@ export default class DefaultCommand extends Command { // bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite const getProjectName = async (message: string, defaultName: string): Promise => { - const projectName = await text({ + const projectName = await clack.text({ message, placeholder: defaultName, validate(value: string = ''): string | void { @@ -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() @@ -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...')) @@ -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: [ @@ -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) @@ -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: @@ -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!`)}`) } } } diff --git a/src/hooks/init/index.ts b/src/hooks/init/index.ts new file mode 100644 index 0000000..af3ded1 --- /dev/null +++ b/src/hooks/init/index.ts @@ -0,0 +1,7 @@ +import {Hook} from '@oclif/core' + +const hook: Hook.CommandNotFound = async function (opts) { + await opts.config.runCommand('clone') +} + +export default hook; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index dc66216..e32b0b2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1 @@ -import {Command} from '@oclif/core' - -export default class DefaultCommand extends Command { - async run(): Promise { - this.log('Running the default command...') - // Add your app creation logic here - } -} +export {run} from '@oclif/core' diff --git a/tsconfig.json b/tsconfig.json index d01c414..aa478b6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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 + } +} \ No newline at end of file