@jdeighan/coffee-utils 4.0.3 → 4.0.7

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "4.0.3",
4
+ "version": "4.0.7",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -3,11 +3,11 @@
3
3
  import {strict as assert} from 'assert'
4
4
  import {
5
5
  dirname, resolve, parse as parsePath,
6
- } from 'path';
7
- import {fileURLToPath} from 'url';
6
+ } from 'path'
7
+ import {fileURLToPath} from 'url'
8
8
  import {
9
9
  existsSync, copyFileSync, readFileSync, writeFileSync, readdirSync,
10
- createReadStream, mkdirSync, renameSync,
10
+ createReadStream, mkdirSync, renameSync, statSync,
11
11
  } from 'fs'
12
12
 
13
13
  import {
@@ -23,7 +23,7 @@ import {debug} from '@jdeighan/coffee-utils/debug'
23
23
 
24
24
  export mydir = (url) ->
25
25
 
26
- return mkpath(dirname(fileURLToPath(url)));
26
+ return mkpath(dirname(fileURLToPath(url.replace(/\@/g, '%40'))))
27
27
 
28
28
  # ---------------------------------------------------------------------------
29
29
 
@@ -102,8 +102,8 @@ export withExt = (filename, newExt) ->
102
102
  export getSubDirs = (dir) ->
103
103
 
104
104
  return readdirSync(dir, {withFileTypes: true}) \
105
- .filter((d) => d.isDirectory()) \
106
- .map((d) => mkpath(d.name)) \
105
+ .filter((d) -> d.isDirectory()) \
106
+ .map((d) -> mkpath(d.name)) \
107
107
  .sort()
108
108
 
109
109
  # ---------------------------------------------------------------------------
@@ -128,7 +128,7 @@ export forEachFile = (dir, cb, filt=undef, level=0) ->
128
128
  if ent.isDirectory()
129
129
  lSubDirectories.push ent
130
130
  else if ent.isFile()
131
- if not filt?
131
+ if ! filt?
132
132
  cb(ent.name, dir, level)
133
133
  else if isRegExp(filt)
134
134
  if ent.name.match(filt)
@@ -184,3 +184,24 @@ export allPathsTo = (fname, searchDir) ->
184
184
  return lPaths
185
185
  else
186
186
  return []
187
+
188
+ # ---------------------------------------------------------------------------
189
+
190
+ export newerDestFileExists = (srcPath, destPath) ->
191
+
192
+ debug "enter newerDestFileExists()"
193
+ if ! existsSync(destPath)
194
+ debug "return false from newerDestFileExists() - no file"
195
+ return false
196
+ srcModTime = statSync(srcPath).mtimeMs
197
+ destModTime = statSync(destPath).mtimeMs
198
+ debug "srcModTime = #{srcModTime}"
199
+ debug "destModTime = #{destModTime}"
200
+ if destModTime >= srcModTime
201
+ debug "#{destPath} is up to date"
202
+ debug "return true from newerDestFileExists()"
203
+ return true
204
+ else
205
+ debug "#{destPath} is old"
206
+ debug "return false from newerDestFileExists()"
207
+ return false
package/src/fs_utils.js CHANGED
@@ -22,7 +22,8 @@ import {
22
22
  readdirSync,
23
23
  createReadStream,
24
24
  mkdirSync,
25
- renameSync
25
+ renameSync,
26
+ statSync
26
27
  } from 'fs';
27
28
 
28
29
  import {
@@ -48,7 +49,7 @@ import {
48
49
  // mydir() - pass argument `import.meta.url` and it will return
49
50
  // the directory your file is in
50
51
  export var mydir = function(url) {
51
- return mkpath(dirname(fileURLToPath(url)));
52
+ return mkpath(dirname(fileURLToPath(url.replace(/\@/g, '%40'))));
52
53
  };
53
54
 
54
55
  // ---------------------------------------------------------------------------
@@ -132,9 +133,9 @@ export var withExt = function(filename, newExt) {
132
133
  export var getSubDirs = function(dir) {
133
134
  return readdirSync(dir, {
134
135
  withFileTypes: true
135
- }).filter((d) => {
136
+ }).filter(function(d) {
136
137
  return d.isDirectory();
137
- }).map((d) => {
138
+ }).map(function(d) {
138
139
  return mkpath(d.name);
139
140
  }).sort();
140
141
  };
@@ -238,3 +239,26 @@ export var allPathsTo = function(fname, searchDir) {
238
239
  return [];
239
240
  }
240
241
  };
242
+
243
+ // ---------------------------------------------------------------------------
244
+ export var newerDestFileExists = function(srcPath, destPath) {
245
+ var destModTime, srcModTime;
246
+ debug("enter newerDestFileExists()");
247
+ if (!existsSync(destPath)) {
248
+ debug("return false from newerDestFileExists() - no file");
249
+ return false;
250
+ }
251
+ srcModTime = statSync(srcPath).mtimeMs;
252
+ destModTime = statSync(destPath).mtimeMs;
253
+ debug(`srcModTime = ${srcModTime}`);
254
+ debug(`destModTime = ${destModTime}`);
255
+ if (destModTime >= srcModTime) {
256
+ debug(`${destPath} is up to date`);
257
+ debug("return true from newerDestFileExists()");
258
+ return true;
259
+ } else {
260
+ debug(`${destPath} is old`);
261
+ debug("return false from newerDestFileExists()");
262
+ return false;
263
+ }
264
+ };
@@ -48,4 +48,5 @@ export logPrivEnv = () ->
48
48
  log "PRIVATE ENVIRONMENT:"
49
49
  for key,value of hPrivEnv
50
50
  log " #{key} = '#{value}'"
51
+ log '-'.repeat(40)
51
52
  return
@@ -59,4 +59,5 @@ export var logPrivEnv = function() {
59
59
  value = hPrivEnv[key];
60
60
  log(` ${key} = '${value}'`);
61
61
  }
62
+ log('-'.repeat(40));
62
63
  };