diff --git a/package.json b/package.json index b680738..38803e5 100644 --- a/package.json +++ b/package.json @@ -1,84 +1,85 @@ { - "name": "@dico/cli", - "version": "0.0.6", - "description": "Dico.app Command Line Interface", - "keywords": [ - "dico", - "cli", - "management" - ], - "repository": { - "type": "git", - "url": "ssh://git@github.com/dico-app/dico-cli.git" - }, - "license": "MIT", - "author": "Lucie Haberer (https://lihbr.com)", - "bin": { - "dico": "bin/cli.js" - }, - "files": [ - "bin", - "postinstall.js" - ], - "scripts": { - "build": "siroc build", - "dev": "siroc build --watch", - "release": "yarn build && yarn test && standard-version && git push --follow-tags && yarn build && npm publish", - "release:dry": "yarn build && yarn test && standard-version --dry-run", - "lint": "eslint --ext .js,.ts .", - "unit": "nyc --reporter=lcovonly --reporter=text --exclude-after-remap=false ava", - "test": "yarn lint && yarn unit", - "postinstall": "node postinstall.js" - }, - "husky": { - "hooks": { - "pre-commit": "yarn lint", - "commit-msg": "commitlint --env HUSKY_GIT_PARAMS" - } - }, - "dependencies": { - "@lihbr/listr-update-renderer": "^0.5.1", - "cac": "^6.7.3", - "chalk": "^4.1.1", - "consola": "^2.15.3", - "detect-indent": "^6.1.0", - "exit": "^0.1.2", - "globby": "^11.0.3", - "inquirer": "^8.1.0", - "latest-version": "^5.1.0", - "listr": "^0.14.3", - "node-fetch": "^2.6.1", - "rc9": "^1.2.0", - "rxjs": "^7.1.0", - "semver": "^7.3.5" - }, - "devDependencies": { - "@commitlint/cli": "12.1.4", - "@commitlint/config-conventional": "12.1.4", - "@types/exit": "0.1.31", - "@types/inquirer": "7.3.1", - "@types/listr": "0.14.3", - "@types/node-fetch": "2.5.10", - "@types/semver": "7.3.6", - "@typescript-eslint/eslint-plugin": "4.26.0", - "@typescript-eslint/parser": "4.26.0", - "ava": "3.15.0", - "eslint": "7.27.0", - "eslint-config-prettier": "8.3.0", - "eslint-plugin-prettier": "3.4.0", - "husky": "4.3.8", - "nyc": "15.1.0", - "prettier": "2.3.0", - "siroc": "0.11.0", - "standard-version": "9.3.0", - "ts-eager": "2.0.2", - "ts-essentials": "7.0.1", - "typescript": "4.3.2" - }, - "engines": { - "node": ">=12.0.0" - }, - "publishConfig": { - "access": "public" - } + "name": "@dico/cli", + "version": "0.0.6", + "description": "Dico.app Command Line Interface", + "keywords": [ + "dico", + "cli", + "management" + ], + "repository": { + "type": "git", + "url": "ssh://git@github.com/dico-app/dico-cli.git" + }, + "license": "MIT", + "author": "Lucie Haberer (https://lihbr.com)", + "bin": { + "dico": "bin/cli.js" + }, + "files": [ + "bin", + "postinstall.js" + ], + "scripts": { + "build": "siroc build", + "dev": "siroc build --watch", + "release": "yarn build && yarn test && standard-version && git push --follow-tags && yarn build && npm publish", + "release:dry": "yarn build && yarn test && standard-version --dry-run", + "lint": "eslint --ext .js,.ts .", + "unit": "nyc --reporter=lcovonly --reporter=text --exclude-after-remap=false ava", + "test": "yarn lint && yarn unit", + "postinstall": "node postinstall.js" + }, + "husky": { + "hooks": { + "pre-commit": "yarn lint", + "commit-msg": "commitlint --env HUSKY_GIT_PARAMS" + } + }, + "dependencies": { + "@lihbr/listr-update-renderer": "^0.5.1", + "cac": "^6.7.3", + "chalk": "^4.1.1", + "consola": "^2.15.3", + "detect-indent": "^6.1.0", + "execa": "^5.1.1", + "exit": "^0.1.2", + "globby": "^11.0.3", + "inquirer": "^8.1.0", + "latest-version": "^5.1.0", + "listr": "^0.14.3", + "node-fetch": "^2.6.1", + "rc9": "^1.2.0", + "rxjs": "^7.1.0", + "semver": "^7.3.5" + }, + "devDependencies": { + "@commitlint/cli": "12.1.4", + "@commitlint/config-conventional": "12.1.4", + "@types/exit": "0.1.31", + "@types/inquirer": "7.3.1", + "@types/listr": "0.14.3", + "@types/node-fetch": "2.5.10", + "@types/semver": "7.3.6", + "@typescript-eslint/eslint-plugin": "4.26.0", + "@typescript-eslint/parser": "4.26.0", + "ava": "3.15.0", + "eslint": "7.27.0", + "eslint-config-prettier": "8.3.0", + "eslint-plugin-prettier": "3.4.0", + "husky": "4.3.8", + "nyc": "15.1.0", + "prettier": "2.3.0", + "siroc": "0.11.0", + "standard-version": "9.3.0", + "ts-eager": "2.0.2", + "ts-essentials": "7.0.1", + "typescript": "4.3.2" + }, + "engines": { + "node": ">=12.0.0" + }, + "publishConfig": { + "access": "public" + } } diff --git a/src/cli.ts b/src/cli.ts index 1fb16a2..01defd5 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -52,6 +52,15 @@ cli await commands.push(cli, options); }); +cli + .command( + "fetch [base]", + "Fetch current dico from Dico.app using `@dico/client`" + ) + .action(async options => { + await commands.fetch(cli, options); + }); + cli.version(VERSION); cli.help(commands.help); diff --git a/src/commands/fetch.ts b/src/commands/fetch.ts new file mode 100644 index 0000000..4c92dac --- /dev/null +++ b/src/commands/fetch.ts @@ -0,0 +1,19 @@ +import { CAC } from "cac"; +import execa from "execa"; +import exit from "exit"; +import { logger } from "../lib"; +import * as messages from "../messages"; + +export const fetch = async (_: CAC, base = "./"): Promise => { + try { + execa.sync("dico-fetch", [base], { + stdin: process.stdin, + stdout: process.stdout, + stderr: process.stderr + }); + } catch (error) { + logger.fatal(error.message); + logger.info(messages.IsDicoClientInstalled); + exit(1); + } +}; diff --git a/src/commands/index.ts b/src/commands/index.ts index afc1c55..f1fcdb8 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -5,6 +5,7 @@ export * from "./whoami"; export * from "./init"; export * from "./build"; export * from "./push"; +export * from "./fetch"; export * from "./help"; export * from "./default"; diff --git a/src/messages.ts b/src/messages.ts index 0121f05..42dda4c 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -26,3 +26,6 @@ export const CommandWithFlagCommand = `Running \`${NAME} %s\` with \`%s\` flag, export const NowStartingCommand = `Now starting command \`${NAME} %s\`:`; export const ProductionDicoNotInSync = `Production dico is not in sync with local \`${CONFIG_FILE}\``; + +export const IsDicoClientInstalled = + "Are you sure `@dico/client` is installed in your project?"; diff --git a/yarn.lock b/yarn.lock index 8983ed8..e8621c0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1984,6 +1984,21 @@ esutils@^2.0.2, esutils@^2.0.3: resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64" integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g== +execa@5.1.1: + version "5.1.1" + resolved "https://registry.yarnpkg.com/execa/-/execa-5.1.1.tgz#f80ad9cbf4298f7bd1d4c9555c21e93741c411dd" + integrity sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg== + dependencies: + cross-spawn "^7.0.3" + get-stream "^6.0.0" + human-signals "^2.1.0" + is-stream "^2.0.0" + merge-stream "^2.0.0" + npm-run-path "^4.0.1" + onetime "^5.1.2" + signal-exit "^3.0.3" + strip-final-newline "^2.0.0" + execa@^5.0.1: version "5.1.0" resolved "https://registry.yarnpkg.com/execa/-/execa-5.1.0.tgz#3ea50ee863d226bfa323528cce1684e7481dfe46"