@sewing-kit/core
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -31,2 +31,8 @@ "use strict"; | ||
async append(file, contents) { | ||
const resolved = this.resolvePath(file); | ||
await (0, _fsExtra.mkdirp)((0, _path.dirname)(resolved)); | ||
await (0, _fsExtra.appendFile)(resolved, contents); | ||
} | ||
async remove(file) { | ||
@@ -33,0 +39,0 @@ const resolved = this.resolvePath(file); |
import { CopyOptions } from 'fs-extra'; | ||
import { IOptions as GlobOptions } from 'glob'; | ||
export declare class FileSystem { | ||
import type { FileSystem as FSType } from '../types'; | ||
export declare class FileSystem implements FSType { | ||
readonly root: string; | ||
@@ -8,2 +9,3 @@ constructor(root: string); | ||
write(file: string, contents: string): Promise<void>; | ||
append(file: string, contents: string): Promise<void>; | ||
remove(file: string): Promise<void>; | ||
@@ -10,0 +12,0 @@ copy(from: string, to: string, options?: CopyOptions): Promise<void>; |
@@ -22,2 +22,7 @@ "use strict"; | ||
} | ||
async append(file, contents) { | ||
const resolved = this.resolvePath(file); | ||
await fs_extra_1.mkdirp(path_1.dirname(resolved)); | ||
await fs_extra_1.appendFile(resolved, contents); | ||
} | ||
async remove(file) { | ||
@@ -24,0 +29,0 @@ const resolved = this.resolvePath(file); |
@@ -11,3 +11,3 @@ export { Runtime, ProjectKind } from './types'; | ||
export declare type Project = import('./package').Package | import('./web-app').WebApp | import('./service').Service; | ||
export type { Log, LogFormatter, LogOptions, Loggable, Step, StepResources, StepRunner, StepStdio, } from './types'; | ||
export type { FileSystem, Log, LogFormatter, LogOptions, Loggable, Step, StepResources, StepRunner, StepStdio, } from './types'; | ||
export { LogLevel } from './types'; | ||
@@ -14,0 +14,0 @@ export { DiagnosticError, isDiagnosticError } from './errors'; |
@@ -0,1 +1,3 @@ | ||
import { CopyOptions } from 'fs-extra'; | ||
import { IOptions as GlobOptions } from 'glob'; | ||
export declare enum Runtime { | ||
@@ -51,3 +53,15 @@ Node = "node", | ||
} | ||
export interface FileSystem { | ||
read(file: string): Promise<string>; | ||
write(file: string, contents: string): Promise<void>; | ||
append(file: string, contents: string): Promise<void>; | ||
remove(file: string): Promise<void>; | ||
copy(from: string, to: string, options?: CopyOptions): Promise<void>; | ||
hasFile(file: string): Promise<boolean>; | ||
hasDirectory(dir: string): Promise<boolean>; | ||
glob(pattern: string, options: Omit<GlobOptions, 'cwd'>): Promise<string[]>; | ||
buildPath(...paths: string[]): string; | ||
resolvePath(...paths: string[]): string; | ||
} | ||
export {}; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -10,2 +10,9 @@ # Changelog | ||
## [0.2.1] - 2021-04-06 | ||
### Added | ||
- Add `append` to `FileSystem` class ([#129](https://github.com/Shopify/sewing-kit-next/pull/129)) | ||
- Expose `FileSystem` type ([#128](https://github.com/Shopify/sewing-kit-next/pull/128)) | ||
## [0.2.0] - 2021-03-30 | ||
@@ -15,3 +22,3 @@ | ||
Add `remove` to `fs` api ([#124](https://github.com/Shopify/sewing-kit-next/pull/124)) | ||
- Add `remove` to `fs` api ([#124](https://github.com/Shopify/sewing-kit-next/pull/124)) | ||
@@ -18,0 +25,0 @@ ## [0.1.5] |
{ | ||
"name": "@sewing-kit/core", | ||
"license": "MIT", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"sideEffects": false, | ||
@@ -19,3 +19,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "21aa22517dc984dd2562a15cfb6547125c90ead2" | ||
"gitHead": "88b2abd0de97863b14edd4cc29c5c97aa977e778" | ||
} |
import {resolve, dirname} from 'path'; | ||
import { | ||
writeFile, | ||
appendFile, | ||
readFile, | ||
@@ -10,6 +10,9 @@ mkdirp, | ||
remove, | ||
writeFile, | ||
} from 'fs-extra'; | ||
import glob, {IOptions as GlobOptions} from 'glob'; | ||
export class FileSystem { | ||
import type {FileSystem as FSType} from '../types'; | ||
export class FileSystem implements FSType { | ||
constructor(public readonly root: string) {} | ||
@@ -27,2 +30,8 @@ | ||
async append(file: string, contents: string) { | ||
const resolved = this.resolvePath(file); | ||
await mkdirp(dirname(resolved)); | ||
await appendFile(resolved, contents); | ||
} | ||
async remove(file: string) { | ||
@@ -29,0 +38,0 @@ const resolved = this.resolvePath(file); |
@@ -10,2 +10,3 @@ import {join} from 'path'; | ||
readFile: mockReadFile, | ||
appendFile: mockAppendFile, | ||
mkdirp: mockMkdirp, | ||
@@ -25,2 +26,3 @@ copy: mockCopy, | ||
mockReadFile.mockReset(); | ||
mockAppendFile.mockReset(); | ||
mockMkdirp.mockReset(); | ||
@@ -78,2 +80,28 @@ mockCopy.mockReset(); | ||
describe('append', () => { | ||
it('appends file', async () => { | ||
const fileName = 'something.txt'; | ||
const contents = 'hi, world'; | ||
await fileSystem.append(fileName, contents); | ||
expect(mockMkdirp).toHaveBeenCalledWith(root); | ||
expect(mockAppendFile).toHaveBeenCalledWith( | ||
join(root, fileName), | ||
contents, | ||
); | ||
}); | ||
it('appends nested file', async () => { | ||
const fileName = 'some/thing.txt'; | ||
const contents = 'hi, world'; | ||
await fileSystem.append(fileName, contents); | ||
expect(mockMkdirp).toHaveBeenCalledWith(join(root, 'some')); | ||
expect(mockAppendFile).toHaveBeenCalledWith( | ||
join(root, fileName), | ||
contents, | ||
); | ||
}); | ||
}); | ||
describe('copy', () => { | ||
@@ -80,0 +108,0 @@ it('copies file', async () => { |
@@ -21,2 +21,3 @@ export {Runtime, ProjectKind} from './types'; | ||
export type { | ||
FileSystem, | ||
Log, | ||
@@ -23,0 +24,0 @@ LogFormatter, |
@@ -0,1 +1,4 @@ | ||
import {CopyOptions} from 'fs-extra'; | ||
import {IOptions as GlobOptions} from 'glob'; | ||
export enum Runtime { | ||
@@ -72,1 +75,15 @@ Node = 'node', | ||
} | ||
// When passing this around to plugins we need to maintain type integrity | ||
export interface FileSystem { | ||
read(file: string): Promise<string>; | ||
write(file: string, contents: string): Promise<void>; | ||
append(file: string, contents: string): Promise<void>; | ||
remove(file: string): Promise<void>; | ||
copy(from: string, to: string, options?: CopyOptions): Promise<void>; | ||
hasFile(file: string): Promise<boolean>; | ||
hasDirectory(dir: string): Promise<boolean>; | ||
glob(pattern: string, options: Omit<GlobOptions, 'cwd'>): Promise<string[]>; | ||
buildPath(...paths: string[]): string; | ||
resolvePath(...paths: string[]): string; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
446231
2502