add ensureFile and ensureFileSync
This commit is contained in:
		
							
								
								
									
										24
									
								
								dist/smartfile.fs.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										24
									
								
								dist/smartfile.fs.d.ts
									
									
									
									
										vendored
									
									
								
							| @@ -21,6 +21,14 @@ export declare let isDirectory: (pathArg: any) => boolean; | ||||
|  * Checks if a given path points to an existing file | ||||
|  */ | ||||
| export declare let isFile: (pathArg: any) => boolean; | ||||
| /** | ||||
|  * copies a file from A to B on the local disk | ||||
|  */ | ||||
| export declare let copy: (fromArg: string, toArg: string) => plugins.q.Promise<{}>; | ||||
| /** | ||||
|  * copies a file SYNCHRONOUSLY from A to B on the local disk | ||||
|  */ | ||||
| export declare let copySync: (fromArg: string, toArg: string) => boolean; | ||||
| /** | ||||
|  * ensures that a directory is in place | ||||
|  */ | ||||
| @@ -30,13 +38,21 @@ export declare let ensureDir: (dirPathArg: string) => plugins.q.Promise<{}>; | ||||
|  */ | ||||
| export declare let ensureDirSync: (dirPathArg: string) => void; | ||||
| /** | ||||
|  * copies a file from A to B on the local disk | ||||
|  * ensures that a file is on disk | ||||
|  * @param filePath the filePath to ensureDir | ||||
|  * @param the fileContent to place into a new file in case it doesn't exist yet | ||||
|  * @returns Promise<void> | ||||
|  * @exec ASYNC | ||||
|  */ | ||||
| export declare let copy: (fromArg: string, toArg: string) => plugins.q.Promise<{}>; | ||||
| export declare let ensureFile: (filePathArg: any, initFileStringArg: any) => plugins.q.Promise<void>; | ||||
| /** | ||||
|  * copies a file SYNCHRONOUSLY from A to B on the local disk | ||||
|  * ensures that a file is on disk | ||||
|  * @param filePath the filePath to ensureDir | ||||
|  * @param the fileContent to place into a new file in case it doesn't exist yet | ||||
|  * @returns Promise<void> | ||||
|  * @exec SYNC | ||||
|  */ | ||||
| export declare let copySync: (fromArg: string, toArg: string) => boolean; | ||||
| export declare let ensureFileSync: (filePathArg: string, initFileStringArg: string) => void; | ||||
| /** | ||||
|  * removes a file or folder from local disk | ||||
|  */ | ||||
|   | ||||
							
								
								
									
										59
									
								
								dist/smartfile.fs.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										59
									
								
								dist/smartfile.fs.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| @@ -31,7 +31,7 @@ | ||||
|     "@types/vinyl": "^1.1.29", | ||||
|     "beautylog": "^5.0.23", | ||||
|     "fs-extra": "^0.30.0", | ||||
|     "glob": "^7.0.6", | ||||
|     "glob": "^7.1.0", | ||||
|     "gulp": "^3.9.1", | ||||
|     "gulp-remote-src": "^0.4.1", | ||||
|     "js-yaml": "^3.6.1", | ||||
|   | ||||
| @@ -2,7 +2,7 @@ import 'typings-global' | ||||
|  | ||||
| import plugins = require('./smartfile.plugins') | ||||
| import SmartfileInterpreter = require('./smartfile.interpreter') | ||||
|  | ||||
| import * as memory from './smartfile.memory' | ||||
| /*=============================================================== | ||||
| ============================ Checks ============================= | ||||
| ===============================================================*/ | ||||
| @@ -54,22 +54,6 @@ export let isFile = function(pathArg): boolean{ | ||||
| ============================ FS ACTIONS ========================= | ||||
| ===============================================================*/ | ||||
|  | ||||
| /** | ||||
|  * ensures that a directory is in place | ||||
|  */ | ||||
| export let ensureDir = (dirPathArg: string) => { | ||||
|     let done = plugins.q.defer() | ||||
|     plugins.fsExtra.ensureDir(dirPathArg,done.resolve) | ||||
|     return done.promise | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * ensures that a directory is in place | ||||
|  */ | ||||
| export let ensureDirSync = (dirPathArg: string) => { | ||||
|     plugins.fsExtra.ensureDirSync(dirPathArg) | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * copies a file from A to B on the local disk | ||||
|  */ | ||||
| @@ -89,9 +73,54 @@ export let copySync = function(fromArg: string,toArg: string): boolean{ | ||||
|     return true | ||||
| } | ||||
|  | ||||
|  /** | ||||
|   * removes a file or folder from local disk | ||||
|   */ | ||||
| /** | ||||
|  * ensures that a directory is in place | ||||
|  */ | ||||
| export let ensureDir = (dirPathArg: string) => { | ||||
|     let done = plugins.q.defer() | ||||
|     plugins.fsExtra.ensureDir(dirPathArg,done.resolve) | ||||
|     return done.promise | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * ensures that a directory is in place | ||||
|  */ | ||||
| export let ensureDirSync = (dirPathArg: string) => { | ||||
|     plugins.fsExtra.ensureDirSync(dirPathArg) | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * ensures that a file is on disk | ||||
|  * @param filePath the filePath to ensureDir | ||||
|  * @param the fileContent to place into a new file in case it doesn't exist yet | ||||
|  * @returns Promise<void> | ||||
|  * @exec ASYNC | ||||
|  */ | ||||
| export let ensureFile = (filePathArg, initFileStringArg): plugins.q.Promise<void> => { | ||||
|     let done = plugins.q.defer<void>() | ||||
|     ensureFileSync(filePathArg, initFileStringArg) | ||||
|     done.resolve() | ||||
|     return done.promise | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * ensures that a file is on disk | ||||
|  * @param filePath the filePath to ensureDir | ||||
|  * @param the fileContent to place into a new file in case it doesn't exist yet | ||||
|  * @returns Promise<void> | ||||
|  * @exec SYNC | ||||
|  */ | ||||
| export let ensureFileSync = (filePathArg: string, initFileStringArg: string): void => { | ||||
|     if (fileExistsSync(filePathArg)) { | ||||
|         return null | ||||
|     } else { | ||||
|         memory.toFsSync(initFileStringArg, filePathArg) | ||||
|     } | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * removes a file or folder from local disk | ||||
|  */ | ||||
| export let remove = function(pathArg: string){ | ||||
|     let done = plugins.q.defer() | ||||
|     plugins.fsExtra.remove(pathArg,function(){ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user