@roots/bud-cache 5.0.0-next.9 → 5.0.0

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/README.md CHANGED
@@ -1,41 +1,25 @@
1
1
  <p align="center">
2
- <img alt="Bud" src="https://cdn.roots.io/app/uploads/logo-bud.svg" height="100" />
2
+ <img src="https://cdn.roots.io/app/uploads/logo-bud.svg" height="100" alt="Bud" />
3
3
  </p>
4
4
 
5
5
  <p align="center">
6
- <img
7
- alt="MIT License"
8
- src="https://img.shields.io/github/license/roots/bud?color=%23525ddc&style=flat-square"
9
- />
10
- <a href="https://app.fossa.com/projects/git%2Bgithub.com%2Froots%2Fbud?ref=badge_small" alt="FOSSA Status">
11
- <img src="https://app.fossa.com/api/projects/git%2Bgithub.com%2Froots%2Fbud.svg?type=small"/>
12
- </a>
13
- <a href="https://www.npmjs.com/package/@roots/bud">
14
- <img src="https://img.shields.io/npm/v/@roots/bud.svg?color=%23525ddc&style=flat-square" />
15
- </a>
16
- <a href="https://codecov.io/gh/roots/bud">
17
- <img src="https://codecov.io/gh/roots/bud/branch/next/graph/badge.svg?token=DRJ28OD8XD"/>
18
- </a>
19
- <a href="https://twitter.com/rootswp">
20
- <img
21
- alt="Follow Roots"
22
- src="https://img.shields.io/twitter/follow/rootswp.svg?color=%23525ddc&style=flat-square"
23
- />
24
- </a>
6
+ <img alt="MIT License" src="https://img.shields.io/github/license/roots/bud?color=%23525ddc&style=flat-square" /> <img alt="npm" src="https://img.shields.io/npm/v/@roots/bud.svg?color=%23525ddc&style=flat-square" /> <img alt="Follow Roots" src="https://img.shields.io/twitter/follow/rootswp.svg?color=%23525ddc&style=flat-square" />
25
7
  </p>
26
8
 
27
-
28
9
  <h1 align="center">
29
10
  <strong>@roots/bud-cache</strong>
30
11
  </h1>
31
12
 
32
- > Config caching
13
+ <p align="center">
14
+ Config caching
15
+ </p>
16
+
33
17
  ## Installation
34
18
 
35
19
  Install **@roots/bud-cache** to your project.
36
20
 
37
21
  ```shell
38
- yarn add @roots/bud-cache
22
+ yarn add @roots/bud-cache --dev
39
23
  ```
40
24
 
41
25
  ## Documentation
@@ -67,8 +51,4 @@ Help support our open-source development efforts by [becoming a patron](https://
67
51
  <a href="https://carrot.com/"><img src="https://cdn.roots.io/app/uploads/carrot.svg" alt="Carrot" width="200" height="150"/></a>
68
52
  <a href="https://www.c21redwood.com/"><img src="https://cdn.roots.io/app/uploads/c21redwood.svg" alt="C21 Redwood Realty" width="200" height="150"/></a>
69
53
  <a href="https://wordpress.com/"><img src="https://cdn.roots.io/app/uploads/wordpress.svg" alt="WordPress.com" width="200" height="150"/></a>
70
- <a href="https://icons8.com/"><img src="https://cdn.roots.io/app/uploads/icons8.svg" alt="Icons8" width="200" height="150"/></a>
71
- <a href="https://www.harnessup.com/"><img src="https://cdn.roots.io/app/uploads/harness-software.svg" alt="Harness Software" width="200" height="150"/></a>
72
- <a href="https://www.codersclan.com/"><img src="https://cdn.roots.io/app/uploads/coders-clan.svg" alt="Coders Clan" width="200" height="150"/></a>
73
- <a href="https://generodigital.com/"><img src="https://cdn.roots.io/app/uploads/genero.svg" alt="Genero" width="200" height="150"/></a>
74
- <a href="https://motto.ca/roots"><img src="https://cdn.roots.io/app/uploads/motto.svg" alt="Motto" width="200" height="150"/></a>
54
+ <a href="https://pantheon.io/"><img src="https://cdn.roots.io/app/uploads/pantheon.svg" alt="Pantheon" width="200" height="150"/></a>
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.writeFile = exports.writeJson = exports.remove = exports.readJson = exports.readFile = exports.ensureFile = exports.createHash = exports.globby = exports.bind = exports.Bud = void 0;
3
+ exports.Bud = exports.writeFile = exports.writeJson = exports.remove = exports.readJson = exports.readFile = exports.ensureFile = exports.createHash = exports.globby = exports.bind = void 0;
4
4
  const tslib_1 = require("tslib");
5
- exports.Bud = (0, tslib_1.__importStar)(require("@roots/bud-framework"));
5
+ const Bud = (0, tslib_1.__importStar)(require("@roots/bud-framework"));
6
+ exports.Bud = Bud;
6
7
  var bud_support_1 = require("@roots/bud-support");
7
8
  Object.defineProperty(exports, "bind", { enumerable: true, get: function () { return bud_support_1.bind; } });
8
9
  Object.defineProperty(exports, "globby", { enumerable: true, get: function () { return bud_support_1.globby; } });
@@ -1 +1 @@
1
- {"version":3,"file":"cache.dependencies.js","sourceRoot":"","sources":["../../../src/Cache/cache.dependencies.ts"],"names":[],"mappings":";;;;AAAA,yEAA2C;AAC3C,kDAA+C;AAAvC,mGAAA,IAAI,OAAA;AAAE,qGAAA,MAAM,OAAA;AACpB,iCAAiC;AAAzB,oGAAA,UAAU,OAAA;AAElB,oDAAqC;AAEnC,kBAAU,GAMR,gBAAE,aALJ,gBAAQ,GAKN,gBAAE,WAJJ,gBAAQ,GAIN,gBAAE,WAHJ,cAAM,GAGJ,gBAAE,SAFJ,iBAAS,GAEP,gBAAE,YADJ,iBAAS,GACP,gBAAE,WAAA"}
1
+ {"version":3,"file":"cache.dependencies.js","sourceRoot":"","sources":["../../../src/Cache/cache.dependencies.ts"],"names":[],"mappings":";;;;AAAA,uEAA2C;AAanC,kBAAG;AAZX,kDAA+C;AAAvC,mGAAA,IAAI,OAAA;AAAE,qGAAA,MAAM,OAAA;AACpB,iCAAiC;AAAzB,oGAAA,UAAU,OAAA;AAElB,oDAAqC;AAEnC,kBAAU,GAMR,gBAAE,aALJ,gBAAQ,GAKN,gBAAE,WAJJ,gBAAQ,GAIN,gBAAE,WAHJ,cAAM,GAGJ,gBAAE,SAFJ,iBAAS,GAEP,gBAAE,YADJ,iBAAS,GACP,gBAAE,WAAA"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Cache = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const fs_extra_1 = require("fs-extra");
5
6
  const helpful_decorators_1 = require("helpful-decorators");
6
7
  const lodash_1 = require("lodash");
7
8
  const cache_dependencies_1 = require("./cache.dependencies");
@@ -17,21 +18,13 @@ class Cache extends cache_dependencies_1.Bud.Cache.Abstract {
17
18
  * @public
18
19
  */
19
20
  get enabled() {
20
- if (this.app.store.is('cli.flags.cache', true)) {
21
- this.log('info', {
22
- message: '--cache',
23
- suffix: this.app.store.get('cli.flags.cache'),
24
- });
25
- return this.app.store.get('cli.flags.cache');
26
- }
27
- if (this.app.store.is('features.cache', true)) {
28
- this.log('info', {
29
- message: 'bud.store',
30
- suffix: this.app.store.get('features.cache'),
31
- });
32
- return this.app.store.get('features.cache');
33
- }
34
- return false;
21
+ this.log('info', {
22
+ message: `cache feature flag: ${this.app.store.get('features.cache')}`,
23
+ });
24
+ this.log('info', {
25
+ message: `--cache flag: ${this.app.store.get('cli.flags.cache')}`,
26
+ });
27
+ return this.app.store.get('features.cache') ? true : false;
35
28
  }
36
29
  /**
37
30
  * Type
@@ -42,14 +35,14 @@ class Cache extends cache_dependencies_1.Bud.Cache.Abstract {
42
35
  const flags = this.app.store.get('cli.flags');
43
36
  const cache = this.app.store.get('cache');
44
37
  if (!(0, lodash_1.isUndefined)(flags['cache.type'])) {
45
- this.log('info', {
38
+ this.log('log', {
46
39
  message: '--cache.type flag',
47
40
  suffix: flags['cache.type'],
48
41
  });
49
42
  return flags['cache.type'];
50
43
  }
51
44
  if (!(0, lodash_1.isUndefined)(cache.type)) {
52
- this.log('info', {
45
+ this.log('log', {
53
46
  message: 'bud.store',
54
47
  suffix: cache.type,
55
48
  });
@@ -61,21 +54,20 @@ class Cache extends cache_dependencies_1.Bud.Cache.Abstract {
61
54
  /**
62
55
  * @public
63
56
  */
64
- register() {
57
+ boot() {
65
58
  return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
66
- this.version = yield this.hashFileContents(this.app.project.get('dependencies'));
59
+ this.version = yield this.hashFileContents();
67
60
  if (this.enabled) {
68
- this.app.persist(this.type);
61
+ this.app.api.call('persist', this.type);
69
62
  }
70
63
  });
71
64
  }
72
65
  /**
73
66
  * @public
74
67
  */
75
- hashFileContents(filePaths) {
76
- var _a;
68
+ hashFileContents() {
77
69
  return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
78
- const hash = (str) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
70
+ const makeHash = (str) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
79
71
  return (0, cache_dependencies_1.createHash)('sha1')
80
72
  .update(str)
81
73
  .digest('base64')
@@ -83,12 +75,18 @@ class Cache extends cache_dependencies_1.Bud.Cache.Abstract {
83
75
  .toLowerCase();
84
76
  });
85
77
  try {
86
- const project = JSON.stringify(this.app.store.get('cli'));
87
- const str = yield Promise.all(filePaths.map((filePath) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
88
- return yield (0, cache_dependencies_1.readFile)(filePath, 'utf8');
89
- })));
90
- const finalHash = yield hash((_a = str.join('').concat(project)) !== null && _a !== void 0 ? _a : '');
91
- return finalHash;
78
+ const paths = this.app.project.get('dependencies');
79
+ const strings = yield Promise.all(paths.map((path) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { return (0, fs_extra_1.readFile)(path, 'utf8'); })));
80
+ const hash = yield makeHash(`${strings}${JSON.stringify(this.app.project.get('cli'))}`);
81
+ this.log('info', {
82
+ message: 'cache hash generated',
83
+ suffix: hash,
84
+ });
85
+ this.app.hooks.async('event.project.write', (project) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
86
+ project.set('cache.hash', hash);
87
+ return project;
88
+ }));
89
+ return hash;
92
90
  }
93
91
  catch (e) {
94
92
  this.app.error('error hashing file contents for cache');
@@ -99,7 +97,7 @@ class Cache extends cache_dependencies_1.Bud.Cache.Abstract {
99
97
  }
100
98
  (0, tslib_1.__decorate)([
101
99
  helpful_decorators_1.bind
102
- ], Cache.prototype, "register", null);
100
+ ], Cache.prototype, "boot", null);
103
101
  (0, tslib_1.__decorate)([
104
102
  helpful_decorators_1.bind
105
103
  ], Cache.prototype, "hashFileContents", null);
@@ -1 +1 @@
1
- {"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
9
9
  * @see https://roots.io/bud
10
10
  * @see https://github.com/roots/bud
11
11
  *
12
- * @packageDocumentation @betaDocumentation
12
+ * @packageDocumentation
13
13
  */
14
14
  var Cache_1 = require("./Cache");
15
15
  Object.defineProperty(exports, "Cache", { enumerable: true, get: function () { return Cache_1.Cache; } });
@@ -1,6 +1,7 @@
1
- export * as Bud from '@roots/bud-framework';
1
+ import * as Bud from '@roots/bud-framework';
2
2
  export { bind, globby } from '@roots/bud-support';
3
3
  export { createHash } from 'crypto';
4
4
  import { fs } from '@roots/bud-support';
5
5
  export const { ensureFile, readFile, readJson, remove, writeJson, writeFile, } = fs;
6
+ export { Bud };
6
7
  //# sourceMappingURL=cache.dependencies.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cache.dependencies.js","sourceRoot":"","sources":["../../../src/Cache/cache.dependencies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,sBAAsB,CAAA;AAC3C,OAAO,EAAC,IAAI,EAAE,MAAM,EAAC,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAC,UAAU,EAAC,MAAM,QAAQ,CAAA;AAEjC,OAAO,EAAC,EAAE,EAAC,MAAM,oBAAoB,CAAA;AACrC,MAAM,CAAC,MAAM,EACX,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,SAAS,EACT,SAAS,GACV,GAAG,EAAE,CAAA"}
1
+ {"version":3,"file":"cache.dependencies.js","sourceRoot":"","sources":["../../../src/Cache/cache.dependencies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,sBAAsB,CAAA;AAC3C,OAAO,EAAC,IAAI,EAAE,MAAM,EAAC,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAC,UAAU,EAAC,MAAM,QAAQ,CAAA;AAEjC,OAAO,EAAC,EAAE,EAAC,MAAM,oBAAoB,CAAA;AACrC,MAAM,CAAC,MAAM,EACX,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,SAAS,EACT,SAAS,GACV,GAAG,EAAE,CAAA;AACN,OAAO,EAAC,GAAG,EAAC,CAAA"}
@@ -1,7 +1,8 @@
1
1
  import { __awaiter, __decorate } from "tslib";
2
+ import { readFile } from 'fs-extra';
2
3
  import { bind } from 'helpful-decorators';
3
4
  import { isUndefined } from 'lodash';
4
- import { Bud, createHash, readFile } from './cache.dependencies';
5
+ import { Bud, createHash } from './cache.dependencies';
5
6
  /**
6
7
  * Cache service class
7
8
  *
@@ -14,21 +15,13 @@ export class Cache extends Bud.Cache.Abstract {
14
15
  * @public
15
16
  */
16
17
  get enabled() {
17
- if (this.app.store.is('cli.flags.cache', true)) {
18
- this.log('info', {
19
- message: '--cache',
20
- suffix: this.app.store.get('cli.flags.cache'),
21
- });
22
- return this.app.store.get('cli.flags.cache');
23
- }
24
- if (this.app.store.is('features.cache', true)) {
25
- this.log('info', {
26
- message: 'bud.store',
27
- suffix: this.app.store.get('features.cache'),
28
- });
29
- return this.app.store.get('features.cache');
30
- }
31
- return false;
18
+ this.log('info', {
19
+ message: `cache feature flag: ${this.app.store.get('features.cache')}`,
20
+ });
21
+ this.log('info', {
22
+ message: `--cache flag: ${this.app.store.get('cli.flags.cache')}`,
23
+ });
24
+ return this.app.store.get('features.cache') ? true : false;
32
25
  }
33
26
  /**
34
27
  * Type
@@ -39,14 +32,14 @@ export class Cache extends Bud.Cache.Abstract {
39
32
  const flags = this.app.store.get('cli.flags');
40
33
  const cache = this.app.store.get('cache');
41
34
  if (!isUndefined(flags['cache.type'])) {
42
- this.log('info', {
35
+ this.log('log', {
43
36
  message: '--cache.type flag',
44
37
  suffix: flags['cache.type'],
45
38
  });
46
39
  return flags['cache.type'];
47
40
  }
48
41
  if (!isUndefined(cache.type)) {
49
- this.log('info', {
42
+ this.log('log', {
50
43
  message: 'bud.store',
51
44
  suffix: cache.type,
52
45
  });
@@ -58,21 +51,20 @@ export class Cache extends Bud.Cache.Abstract {
58
51
  /**
59
52
  * @public
60
53
  */
61
- register() {
54
+ boot() {
62
55
  return __awaiter(this, void 0, void 0, function* () {
63
- this.version = yield this.hashFileContents(this.app.project.get('dependencies'));
56
+ this.version = yield this.hashFileContents();
64
57
  if (this.enabled) {
65
- this.app.persist(this.type);
58
+ this.app.api.call('persist', this.type);
66
59
  }
67
60
  });
68
61
  }
69
62
  /**
70
63
  * @public
71
64
  */
72
- hashFileContents(filePaths) {
73
- var _a;
65
+ hashFileContents() {
74
66
  return __awaiter(this, void 0, void 0, function* () {
75
- const hash = (str) => __awaiter(this, void 0, void 0, function* () {
67
+ const makeHash = (str) => __awaiter(this, void 0, void 0, function* () {
76
68
  return createHash('sha1')
77
69
  .update(str)
78
70
  .digest('base64')
@@ -80,12 +72,18 @@ export class Cache extends Bud.Cache.Abstract {
80
72
  .toLowerCase();
81
73
  });
82
74
  try {
83
- const project = JSON.stringify(this.app.store.get('cli'));
84
- const str = yield Promise.all(filePaths.map((filePath) => __awaiter(this, void 0, void 0, function* () {
85
- return yield readFile(filePath, 'utf8');
86
- })));
87
- const finalHash = yield hash((_a = str.join('').concat(project)) !== null && _a !== void 0 ? _a : '');
88
- return finalHash;
75
+ const paths = this.app.project.get('dependencies');
76
+ const strings = yield Promise.all(paths.map((path) => __awaiter(this, void 0, void 0, function* () { return readFile(path, 'utf8'); })));
77
+ const hash = yield makeHash(`${strings}${JSON.stringify(this.app.project.get('cli'))}`);
78
+ this.log('info', {
79
+ message: 'cache hash generated',
80
+ suffix: hash,
81
+ });
82
+ this.app.hooks.async('event.project.write', (project) => __awaiter(this, void 0, void 0, function* () {
83
+ project.set('cache.hash', hash);
84
+ return project;
85
+ }));
86
+ return hash;
89
87
  }
90
88
  catch (e) {
91
89
  this.app.error('error hashing file contents for cache');
@@ -96,7 +94,7 @@ export class Cache extends Bud.Cache.Abstract {
96
94
  }
97
95
  __decorate([
98
96
  bind
99
- ], Cache.prototype, "register", null);
97
+ ], Cache.prototype, "boot", null);
100
98
  __decorate([
101
99
  bind
102
100
  ], Cache.prototype, "hashF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CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAA;gBACvD,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,CAAA;aACnB;QACH,CAAC;KAAA;CACF;AArDC;IADC,IAAI;iCAOJ;AAMD;IADC,IAAI;6CAyCJ"}
package/lib/esm/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * @see https://roots.io/bud
7
7
  * @see https://github.com/roots/bud
8
8
  *
9
- * @packageDocumentation @betaDocumentation
9
+ * @packageDocumentation
10
10
  */
11
11
  export { Cache } from './Cache';
12
12
  //# sourceMappingURL=index.js.map