项目原始demo,不改动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 

35 lines
662 B

  1. 'use strict';
  2. const path = require('path');
  3. const commonDir = require('commondir');
  4. const pkgDir = require('pkg-dir');
  5. const makeDir = require('make-dir');
  6. module.exports = options => {
  7. const name = options.name;
  8. let dir = options.cwd;
  9. if (options.files) {
  10. dir = commonDir(dir, options.files);
  11. } else {
  12. dir = dir || process.cwd();
  13. }
  14. dir = pkgDir.sync(dir);
  15. if (dir) {
  16. dir = path.join(dir, 'node_modules', '.cache', name);
  17. if (dir && options.create) {
  18. makeDir.sync(dir);
  19. }
  20. if (options.thunk) {
  21. return function () {
  22. return path.join.apply(path, [dir].concat(Array.prototype.slice.call(arguments)));
  23. };
  24. }
  25. }
  26. return dir;
  27. };