Skip to content

Commit

Permalink
add command, ts config tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
samifouad committed Sep 8, 2024
1 parent 0d9cc35 commit e900bdb
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
41 changes: 41 additions & 0 deletions core/add/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { $ } from 'bun'
import { createSpinner } from 'nanospinner'
import { sleep } from '@/core'

export async function add(repo, version) {
const spinner = createSpinner(' task: add remote package').start();

await sleep(1000)

if (repo.startsWith('https://') || repo.startsWith('github.com')) {
repo = repo.replace('https://', '')
repo = repo.replace('http://', '')
repo = repo.replace('github.com/', '')
}

let [user, pkg] = repo.split('/')

let source

if (user.includes(':')) {
[source, user] = user.split(':')
}

console.log('\nsource: '+ source)

if (source !== undefined && pkg === undefined) {
pkg = user
user = undefined
}
console.log('user: '+ user)
console.log('pkg: '+ pkg)

if (version !== undefined) {
console.log('version requested: '+ version)
} else {
console.log('version requested: latest')
}

spinner.success()
process.exit(0)
}
1 change: 1 addition & 0 deletions core/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { status } from './status/status'
export { check } from './check/check'
export { init } from './new/new'
export { add } from './add/add'


export const sleep = (ms = 2000) => new Promise((resolve) => setTimeout(resolve, ms));
2 changes: 1 addition & 1 deletion core/new/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { check_existing } from './lib/check_existing'
import { create_directory } from './lib/create_directory'
import { create_file } from './lib/create_file'

export async function init() {
export async function init() { // can't use "new" as it's a reserved word
const spinner = createSpinner('task: create .gild folder').start();

// check for existing folder
Expand Down
15 changes: 12 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,30 @@ program

program
.command('new')
.description('create a new .gild folder')
.description('create a new gild project')
.action(async () => {
await core.init()
})

program
.command('add')
.description('fetch remote package')
.argument('<repo>', 'github <user>/<repo> containing a package')
.argument('[version]', 'requested version for package, default is latest')
.action(async (repo, version) => {
await core.add(repo, version)
})

program
.command('status')
.description('check current configuration')
.description('sanity check current project')
.action(async () => {
await core.status()
})

program
.command('check')
.description('sanity check for current system')
.description('sanity check your system')
.action(async () => {
await core.check()
})
Expand Down
6 changes: 6 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
"jsx": "react-jsx",
"allowJs": true,

// imports
"paths": {
"@/core": ["./core/index.ts"],
"@/*": ["./core/*"]
},

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
Expand Down

0 comments on commit e900bdb

Please sign in to comment.