From a1be6f19acd6125f09cd8376fe386fc5b549bd36 Mon Sep 17 00:00:00 2001 From: Ken Date: Tue, 4 Jun 2019 15:02:29 -0700 Subject: [PATCH] WIP:adding some basics --- .gitignore | 2 ++ .npmignore | 4 ++++ package.json | 14 +++++++++++++- src/changefile.ts | 0 src/cli.ts | 0 src/git.ts | 5 +++++ src/index.ts | 0 src/paths.ts | 45 +++++++++++++++++++++++++++++++++++++++++++++ tsconfig.json | 13 +++++++++++++ yarn.lock | 36 ++++++++++++++++++++++++++++++++++++ 10 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 .npmignore create mode 100644 src/changefile.ts create mode 100644 src/cli.ts create mode 100644 src/git.ts create mode 100644 src/index.ts create mode 100644 src/paths.ts create mode 100644 tsconfig.json create mode 100644 yarn.lock diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..c18ed016 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +lib/ \ No newline at end of file diff --git a/.npmignore b/.npmignore new file mode 100644 index 00000000..a27a2bc0 --- /dev/null +++ b/.npmignore @@ -0,0 +1,4 @@ +src/ +node_modules/ +tsconfig.json +yarn.lock diff --git a/package.json b/package.json index 89ce65b2..464f838c 100644 --- a/package.json +++ b/package.json @@ -2,5 +2,17 @@ "name": "beachball", "version": "1.0.0", "main": "index.js", - "license": "MIT" + "license": "MIT", + "scripts": { + "build": "tsc", + "start": "tsc -w --preserveWatchOutput" + }, + "dependencies": { + "prompts": "~2.1.0" + }, + "devDependencies": { + "@types/node": "^12.0.4", + "@types/prompts": "~2.0.0", + "typescript": "^3.5.1" + } } diff --git a/src/changefile.ts b/src/changefile.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/cli.ts b/src/cli.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/git.ts b/src/git.ts new file mode 100644 index 00000000..646361cf --- /dev/null +++ b/src/git.ts @@ -0,0 +1,5 @@ +import { spawnSync } from 'child_process'; + +export function git(args: string[]) { + return spawnSync('git', args); +} diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/paths.ts b/src/paths.ts new file mode 100644 index 00000000..322cee3e --- /dev/null +++ b/src/paths.ts @@ -0,0 +1,45 @@ +import path from 'path'; +import fs from 'fs'; + +function searchUp(pathName: string, cwd?: string) { + if (!cwd) { + cwd = process.cwd(); + } + + const root = path.parse(cwd).root; + + let found = false; + + while (!found && cwd !== root) { + if (fs.existsSync(path.join(cwd, pathName))) { + found = true; + break; + } + + cwd = path.dirname(cwd); + } + + if (found) { + return cwd; + } + + return null; +} + +export function findGitRoot(cwd?: string) { + return searchUp('.git', cwd); +} + +export function findPackageRoot(cwd?: string) { + return searchUp('package.json', cwd); +} + +export function getChangeFilePath(cwd?: string) { + const gitRoot = findGitRoot(cwd); + + if (gitRoot) { + return path.join(gitRoot, 'beachbump'); + } + + return null; +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..f555ca82 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "outDir": "./lib", + "target": "es2016", + "module": "commonjs", + "moduleResolution": "node", + "declaration": true, + "declarationMap": true, + "strict": true, + "esModuleInterop": true + }, + "include": ["src/**/*"] +} diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 00000000..a9f86a01 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,36 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@types/node@^12.0.4": + version "12.0.4" + resolved "https://registry.yarnpkg.com/@types/node/-/node-12.0.4.tgz#46832183115c904410c275e34cf9403992999c32" + integrity sha512-j8YL2C0fXq7IONwl/Ud5Kt0PeXw22zGERt+HSSnwbKOJVsAGkEz3sFCYwaF9IOuoG1HOtE0vKCj6sXF7Q0+Vaw== + +"@types/prompts@~2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@types/prompts/-/prompts-2.0.0.tgz#28551307ae9e10f5e5b703edcd7261c84b8a5f2f" + integrity sha512-Rl7itDnYA+Eunkd8WUcB7SF8B0cuzykwDWeQ2rfZry8fqdXJ3piw5B+SgzHWBYQuHCwF7E5iyozQf3BziCuXhA== + +kleur@^3.0.2: + version "3.0.3" + resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e" + integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w== + +prompts@~2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/prompts/-/prompts-2.1.0.tgz#bf90bc71f6065d255ea2bdc0fe6520485c1b45db" + integrity sha512-+x5TozgqYdOwWsQFZizE/Tra3fKvAoy037kOyU6cgz84n8f6zxngLOV4O32kTwt9FcLCxAqw0P/c8rOr9y+Gfg== + dependencies: + kleur "^3.0.2" + sisteransi "^1.0.0" + +sisteransi@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.0.tgz#77d9622ff909080f1c19e5f4a1df0c1b0a27b88c" + integrity sha512-N+z4pHB4AmUv0SjveWRd6q1Nj5w62m5jodv+GD8lvmbY/83T/rpbJGZOnK5T149OldDj4Db07BSv9xY4K6NTPQ== + +typescript@^3.5.1: + version "3.5.1" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.1.tgz#ba72a6a600b2158139c5dd8850f700e231464202" + integrity sha512-64HkdiRv1yYZsSe4xC1WVgamNigVYjlssIoaH2HcZF0+ijsk5YK2g0G34w9wJkze8+5ow4STd22AynfO6ZYYLw==