arcadible 0.1.49 → 0.1.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -79,5 +79,5 @@
79
79
  "scripts": {
80
80
  "test": "node --test \"test/**/*.test.js\""
81
81
  },
82
- "version": "0.1.49"
82
+ "version": "0.1.50"
83
83
  }
@@ -22,6 +22,7 @@ const ArcError = error.ArcError;
22
22
  const detectVersion = manifest.detectVersion;
23
23
  const join = path.join;
24
24
  const prepare = manifest.prepare;
25
+ const readdir = fs.readdir;
25
26
  const remove = fs.remove;
26
27
  const resolve = path.resolve;
27
28
 
@@ -37,6 +38,28 @@ const removeLicense = function (dest) {
37
38
 
38
39
  // [function]
39
40
 
41
+ const unavailable = function (src, cause) {
42
+ return new ArcError(
43
+ cfgcode.TEMPLATE_UNAVAILABLE,
44
+ phrase.templateUnavailable(src),
45
+ { cause },
46
+ );
47
+ };
48
+
49
+ // [function]
50
+
51
+ // degit copies nothing, without failing, from a folder a repository doesn't
52
+ // have, so an empty project fails as a missing repository does.
53
+ const ensureCopied = async function (src, dest) {
54
+ const names = await readdir(dest).catch(() => []);
55
+ if (names.length === 0) {
56
+ await remove(dest);
57
+ throw unavailable(src);
58
+ }
59
+ };
60
+
61
+ // [function]
62
+
40
63
  const scaffold = function (src, dest, { onInitBegin }) {
41
64
  if (onInitBegin) {
42
65
  onInitBegin({ dest, src });
@@ -44,14 +67,9 @@ const scaffold = function (src, dest, { onInitBegin }) {
44
67
  return degit(src, { cache: false, force: true, verbose: false })
45
68
  .clone(dest)
46
69
  .catch((ex) => {
47
- throw new ArcError(
48
- cfgcode.TEMPLATE_UNAVAILABLE,
49
- phrase.templateUnavailable(src),
50
- {
51
- cause: ex,
52
- },
53
- );
54
- });
70
+ throw unavailable(src, ex);
71
+ })
72
+ .then(() => ensureCopied(src, dest));
55
73
  };
56
74
 
57
75
  // [function]