@jdeighan/coffee-utils 14.0.37 → 14.0.38

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/src/fs.coffee +8 -35
  3. package/src/fs.js +8 -29
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "14.0.37",
4
+ "version": "14.0.38",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
package/src/fs.coffee CHANGED
@@ -1,5 +1,6 @@
1
1
  # fs.coffee
2
2
 
3
+ import os from 'os'
3
4
  import pathlib from 'path'
4
5
  import urllib from 'url'
5
6
  import fs from 'fs'
@@ -30,7 +31,7 @@ export mkpath = (lParts...) =>
30
31
  if nonEmpty(part)
31
32
  lNewParts.push part
32
33
 
33
- newPath = lNewParts.join('/').replace(/\\/g, '/')
34
+ newPath = lNewParts.join('/').replaceAll('\\', '/')
34
35
  if lMatches = newPath.match(/^([A-Z])\:(.*)$/)
35
36
  [_, drive, rest] = lMatches
36
37
  return "#{drive.toLowerCase()}:#{rest}"
@@ -53,13 +54,6 @@ export mkdir = (dirpath) =>
53
54
 
54
55
  # ---------------------------------------------------------------------------
55
56
 
56
- export mkfile = (filepath, contents='') =>
57
-
58
- await writeFile filepath, contents
59
- return
60
-
61
- # ---------------------------------------------------------------------------
62
-
63
57
  export rmdir = (dirpath) =>
64
58
 
65
59
  await rm dirpath, {recursive: true}
@@ -72,19 +66,6 @@ export rmfile = (filepath) =>
72
66
  await rm filepath
73
67
  return
74
68
 
75
- # ---------------------------------------------------------------------------
76
-
77
- export cdTo = (dirpath) =>
78
-
79
- process.chdir dirpath
80
- return process.cwd()
81
-
82
- # ---------------------------------------------------------------------------
83
-
84
- export cdToUserDir = (lSubDirs...) =>
85
-
86
- return cd(mkpath('~', lSubDirs...))
87
-
88
69
  # --------------------------------------------------------------------------
89
70
 
90
71
  export execCmd = (cmdLine) =>
@@ -102,20 +83,6 @@ export cloneRepo = (user, repo, dir) =>
102
83
  git_repo = "https://github.com/#{user}/#{repo}.git"
103
84
  return execCmd "git clone #{git_repo} #{dir}"
104
85
 
105
- # ---------------------------------------------------------------------------
106
-
107
- export getPkgJson = (filepath) =>
108
-
109
- jsonTxt = fs.readFileSync(filepath, {encoding: 'utf8'})
110
- hJson = JSON.parse jsonTxt
111
- return
112
-
113
- # ---------------------------------------------------------------------------
114
-
115
- export putPkgJson = (filepath, hJson) =>
116
-
117
- return
118
-
119
86
  # ---------------------------------------------------------------------------
120
87
  # mydir() - pass argument import.meta.url and it will return
121
88
  # the directory your file is in
@@ -129,6 +96,12 @@ export mydir = (url) =>
129
96
 
130
97
  # ---------------------------------------------------------------------------
131
98
 
99
+ export homeDir = () =>
100
+
101
+ return mkpath(os.homedir())
102
+
103
+ # ---------------------------------------------------------------------------
104
+
132
105
  export projRoot = (url) =>
133
106
 
134
107
  dir = mydir(url)
package/src/fs.js CHANGED
@@ -2,6 +2,8 @@
2
2
  // fs.coffee
3
3
  var isSystemDir;
4
4
 
5
+ import os from 'os';
6
+
5
7
  import pathlib from 'path';
6
8
 
7
9
  import urllib from 'url';
@@ -72,7 +74,7 @@ export var mkpath = (...lParts) => {
72
74
  lNewParts.push(part);
73
75
  }
74
76
  }
75
- newPath = lNewParts.join('/').replace(/\\/g, '/');
77
+ newPath = lNewParts.join('/').replaceAll('\\', '/');
76
78
  if (lMatches = newPath.match(/^([A-Z])\:(.*)$/)) {
77
79
  [_, drive, rest] = lMatches;
78
80
  return `${drive.toLowerCase()}:${rest}`;
@@ -97,11 +99,6 @@ export var mkdir = (dirpath) => {
97
99
  }
98
100
  };
99
101
 
100
- // ---------------------------------------------------------------------------
101
- export var mkfile = async(filepath, contents = '') => {
102
- await writeFile(filepath, contents);
103
- };
104
-
105
102
  // ---------------------------------------------------------------------------
106
103
  export var rmdir = async(dirpath) => {
107
104
  await rm(dirpath, {
@@ -114,17 +111,6 @@ export var rmfile = async(filepath) => {
114
111
  await rm(filepath);
115
112
  };
116
113
 
117
- // ---------------------------------------------------------------------------
118
- export var cdTo = (dirpath) => {
119
- process.chdir(dirpath);
120
- return process.cwd();
121
- };
122
-
123
- // ---------------------------------------------------------------------------
124
- export var cdToUserDir = (...lSubDirs) => {
125
- return cd(mkpath('~', ...lSubDirs));
126
- };
127
-
128
114
  // --------------------------------------------------------------------------
129
115
  export var execCmd = (cmdLine) => {
130
116
  execSync(cmdLine, {}, (error, stdout, stderr) => {
@@ -143,18 +129,6 @@ export var cloneRepo = (user, repo, dir) => {
143
129
  return execCmd(`git clone ${git_repo} ${dir}`);
144
130
  };
145
131
 
146
- // ---------------------------------------------------------------------------
147
- export var getPkgJson = (filepath) => {
148
- var hJson, jsonTxt;
149
- jsonTxt = fs.readFileSync(filepath, {
150
- encoding: 'utf8'
151
- });
152
- hJson = JSON.parse(jsonTxt);
153
- };
154
-
155
- // ---------------------------------------------------------------------------
156
- export var putPkgJson = (filepath, hJson) => {};
157
-
158
132
  // ---------------------------------------------------------------------------
159
133
  // mydir() - pass argument import.meta.url and it will return
160
134
  // the directory your file is in
@@ -166,6 +140,11 @@ export var mydir = (url) => {
166
140
  return final;
167
141
  };
168
142
 
143
+ // ---------------------------------------------------------------------------
144
+ export var homeDir = () => {
145
+ return mkpath(os.homedir());
146
+ };
147
+
169
148
  // ---------------------------------------------------------------------------
170
149
  export var projRoot = (url) => {
171
150
  var dir, rootDir;