Skip to content

Commit

Permalink
feat: initial v1
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-forster committed Dec 31, 2019
0 parents commit c88fdec
Show file tree
Hide file tree
Showing 8 changed files with 13,518 additions and 0 deletions.
90 changes: 90 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
version: 2.1

jobs:
install:
docker:
- image: &node_image circleci/node:lts
steps:
- checkout
- restore_cache:
keys:
- &install_cache_key npm-install-v1-{{ checksum "package-lock.json" }}
- npm-install-v1-
- run:
name: Install Dependencies
command: npm ci --no-audit
- persist_to_workspace:
root: .
paths:
- node_modules
- build
- save_cache:
key: *install_cache_key
paths:
- ~/.npm/_cacache

audit:
docker:
- image: *node_image
steps:
- checkout
- attach_workspace:
at: .
- run:
name: NPM Audit
command: |
npm -v
npm audit --audit-level=moderate
test:
docker:
- image: *node_image
steps:
- checkout
- attach_workspace:
at: .
- run:
name: Test Packages
command: npm run test -- --ci

publish:
docker:
- image: *node_image
steps:
- checkout
- attach_workspace:
at: .
- run:
name: npmrc
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
- deploy:
name: Publish
when: on_success
command: |
git config --global user.name Bot Vance
git config --global user.email bot@autovance.com
npx semantic-release
workflows:
version: 2

test:
jobs:
- install:
context: org-global
- audit:
context: org-global
requires:
- install
- test:
context: org-global
requires:
- install
- publish:
context: org-global
requires:
- test
- audit
filters:
branches:
only: master
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/
node_modules/
.vscode/
25 changes: 25 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testRegex: 'tests/.*\\.ts$',
// automock: true,
moduleFileExtensions: ['ts', 'js'],
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100
}
},
transform: {
'^.+\\.tsx?$': ['ts-jest'],
'\\.ts$': ['ts-jest']
},
rootDir: '.',
globals: {
'ts-jest': {
tsConfig: 'tsconfig.json'
}
}
};
63 changes: 63 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* eslint-disable no-restricted-syntax */

import { extname, basename, dirname, sep } from 'path';

class FilePath {
/** The string representing the file name excluding the extension */
public filename: string | undefined;

/** An ordered array of folder names. folders[0] represents the root of the path.
* If absolute, it will be empty '' (required), if relative, it will be the folder reference '.' or '..'
*/
public folders: string[] = [];

private _extension: string | undefined;

/** Set a up path to be manipulated */
public constructor(path: string) {
this.path = path;
}

/** Set: up a path to be manipulated */
public set path(path: string) {
this.extension = extname(path);
this.filename = basename(path, `.${this.extension}`);
this.folders = dirname(path).split(sep);
}

/** Get: the current path */
public get path() {
return `${this.folders.join(sep)}${sep}${this.file ? this.file : ''}`;
}

/** Set: the full file name including the extension */
public set file(file: string | undefined) {
if (file) {
this.extension = extname(file);
this.filename = basename(file, `.${this.extension}`);
} else {
this.extension = undefined;
this.filename = undefined;
}
}

/** Get: the full file with the extension included */
public get file(): string | undefined {
if (this.filename) {
return `${this.filename}${this.extension ? `.${this.extension}` : ''}`;
} else return undefined;
}

/** Set: the extension */
public set extension(extension: string | undefined) {
if (extension) this._extension = extension.replace(/^\./g, '');
else this._extension = undefined;
}

/** Get: the extension. Does not include the `.` delimiter */
public get extension(): string | undefined {
return this._extension;
}
}

export default FilePath;
Loading

0 comments on commit c88fdec

Please sign in to comment.