Full Code of staticfile/cli for AI

master 4c8ee8728a0b cached
6 files
11.7 KB
3.4k tokens
1 requests
Download .txt
Repository: staticfile/cli
Branch: master
Commit: 4c8ee8728a0b
Files: 6
Total size: 11.7 KB

Directory structure:
gitextract_68jodr4t/

├── .gitignore
├── LICENSE
├── README.md
├── bin/
│   └── sfile
├── lib/
│   └── index.js
└── package.json

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
node_modules/
.idea/


================================================
FILE: LICENSE
================================================
The MIT License (MIT)

Copyright (c) 2013 staticfile

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


================================================
FILE: README.md
================================================
# 介绍

[staticfile.org](http://staticfile.org)命令行工具

# 安装

```
npm install -g sfile
```

# 使用

## 快捷搜索

快速搜索关键字

```
sfile [library]
```

![快速搜索](https://github.com/staticfile/cli/raw/master/docs/quicksearch.png)

## 搜索

搜索关键字

```
sfile search [library]

Options:
  -s, --ssl      Output HTTPS link
  -h, --html     Output HTML
  -j, --jade     Output Jade Markup
  -n, --no-link  Do not show the link for latest version
```

## 获取链接

获取一个库的所有文件链接

```
sfile get [library]

Options:
  -s, --ssl      Output HTTPS link
  -h, --html     Output HTML
  -j, --jade     Output Jade Markup
  -v, --version  Use given version, leave empty if you want to see all supported version
  -c, --copy     Copy to your system clipboard
```

## 查看版本

```
sfile --version
```


================================================
FILE: bin/sfile
================================================
#!/usr/bin/env node
var sfile = require('../lib')
  , clip = require('cliparoo')
  , opt = require('optimist')
  , argv = opt
    .usage("[Usage]\n\nsfile [command|library]\n\nCommands:\n\n  s, search [library]\tTo search the library...\n  g, get [library]\tTo get the library assets links...")
    .argv;

switch (argv._[0]) {
  case 'i':
  case 'info':
    var prettyjson = require('prettyjson')
    var keyword = argv._[1];
    if (!keyword || argv.help) {
      opt.showHelp();
      return;
    }
    keyword = keyword.trim();

    sfile.info(keyword, function (err, data) {
      if (err) {
        return sfile.error(err);
      }

      if (data.assets) {
        data.assets = [data.assets[0]]
      }

      console.log(prettyjson.render(data));
    })
    break;
  case 'search':
  case 's':
    argv = opt
      .usage("sfile " + argv._[0] + " [library]")
      .alias('s', 'ssl')
      .alias('h', 'html')
      .alias('j', 'jade')
      .alias('n', 'no-link')
      .describe('s', 'Output HTTPS link')
      .describe('h', 'Output HTML')
      .describe('j', 'Output Jade Markup')
      .describe('n', 'Do not show the link for latest version')
      .argv;

    var keyword = argv._[1];
    if (!keyword || argv.help) {
      opt.showHelp();
      return;
    }
    keyword = keyword.trim();

    sfile.search(keyword, function (err, data) {
      if (err) return sfile.error(err);

      if (!data.total) {
        return printLn("没有结果");
      }

      printLn(("搜索 " + keyword.bold + " 共有 " + (data.total + "").bold + " 个库,当前列出 " + (data.libs.length + "").bold + " 个:"));
      printLn("");

      data.libs.forEach(function (lib, index) {
        printLn(((index > 9 ? index : " " + index) + ")").grey + " " + lib.name.replace(keyword, keyword.bold) + " [" + lib.version.green + "]");

        if (!argv.n) {
          var url = sfile.url("/" + lib.name + "/" + lib.version + "/" + lib.filename, argv.ssl);

          if (argv.html) {
            url = sfile.html(url);
          } else if (argv.jade) {
            url = sfile.jade(url);
          }

          printLn(("    " + url).grey);
        }

        printLn("");
      });
    });
    break;
  case "get":
  case "g":
    argv = opt
      .usage("sfile " + argv._[0] + " [library]")
      .alias('h', 'html')
      .alias('j', 'jade')
      .alias('s', 'ssl')
      .alias('c', 'copy')
      .alias('v', 'version')
      .describe('v', 'Use given version, leave empty if you want to see all supported version ')
      .describe('h', 'Output HTML')
      .describe('j', 'Output Jade Markup')
      .describe('s', 'Output HTTPS link')
      .describe('c', 'Copy to your system clipboard')
      .argv;

    var keyword = argv._[1];
    if (!keyword || argv.help) {
      opt.showHelp();
      return;
    }
    keyword = keyword.trim();
    sfile.get(keyword, function (err, lib, suggest) {
      if (err) return sfile.error(err);

      if (!lib) {
        printLn("未找到库: " + keyword);
        // 搜索建议
        if (suggest.length > 0) {
          printLn("");
          for (var i in suggest) {
            suggest[i] = suggest[i].underline;
          }
          printLn("你是不是要找: ".cyan + suggest.slice(0, 5).join(" "));
        }
        return;
      }

      var version = (argv.version && argv.version !== true) ? argv.version : "" + lib.version;
      var matched = false;

      // 匹配package.json给出的版本
      lib.assets.forEach(function (asset) {
        if (asset.version == version) {
          if (matched) return;
          matched = asset;
        }
      });

      // 未匹配容错
      if (!matched && lib.assets[0] && !argv.version) {
        matched = lib.assets[0];
      }

      if (!matched) {
        printLn("未找到 " + keyword + " [" + (argv.version + "").red + "]");
      } else {
        printLn("找到 " + lib.name.bold + " [" + version.green + "]:");
        printLn("");

        var urls = [];
        matched.files.forEach(function (file) {
          var path = "/" + lib.name + "/" + version + "/" + file;
          var url = sfile.url(path, argv.ssl);
          if (argv.html) {
            url = sfile.html(url);
          } else if (argv.jade) {
            url = sfile.jade(url);
          }

          url && printLn(url) && urls.push(url);
        });

        // 复制到剪贴板
        if (argv.copy) {
          clip(urls.join(argv.html || argv.jade ? "\n" : "\\\\n"), function (err) {
            if (err) return sfile.error(err);

            printLn("✔ 已复制到剪贴板".green);
          });
        }
      }
      printLn("");
      if (argv.version)
        printLn("支持的版本号: ".cyan + lib.assets.map(function (asset) {
          return asset.version.underline
        }).join(" "));
    });
    break
  default:
    if (argv.version || argv.v) {
      var json = require("../package.json");
      printLn(json.version);
    } else if (argv._[0]) {
      var List = require('term-list')
        , list = new List({ marker: '\033[36m› \033[0m', markerLength: 2 })
        , styles = ['', 'html', 'jade']
        , current_style_index = 0

      keyword = argv._[0].trim();

      sfile.search(keyword, function (err, data) {
        if (err) return sfile.error(err);

        if (!data.total) {
          return printLn("没有结果");
        }

        printLn(("搜索 " + keyword.bold + " 共有 " + (data.total + "").bold + " 个库,当前列出 " + (data.libs.length + "").bold + " 个:"));

        data.libs.forEach(function (lib, index) {
          var url = sfile.url("/" + lib.name + "/" + lib.version + "/" + lib.filename);
          lib.index = index;
          lib.base = lib.name.replace(keyword, keyword.bold) + " [" + lib.version.green + "] ";
          lib.url = url;
          lib.to_copy = url;
          lib.subLabel = lib.filename;
          lib.current = 'url';
          list.add(lib, lib.base + lib.subLabel.grey);
        });

        var changeStyle = function (reverse) {
          if (reverse) {
            current_style_index = current_style_index - 1 < 0 ? 2 : current_style_index - 1;
          } else {
            current_style_index = current_style_index + 1 > 2 ? 0 : current_style_index + 1;
          }
          var current_style = styles[current_style_index];

          list.items.forEach(function (it, i) {
            var current = list.at(i);
            current.label = it.id.base + it.id.subLabel.grey + (current_style && (' [' + current_style + ']').red);
            current.id.to_copy = current_style ? sfile[current_style](it.id.url) : it.id.url;
          });
          list.draw();
        }

        list.start();

        list.on("keypress", function (key, item) {
          switch (key.name) {
            case "return":
              clip(item.to_copy, function (err) {
                if (err) return sfile.error(err);

                printLn("✔ 已复制到剪贴板".green);
              });
              list.stop();
              break;
            case "left":
              changeStyle(true);
              break;
            case "right":
              changeStyle(false);
              break;
          }
        });

        list.on('empty', function () {
          list.stop();
        });
      });
    } else {
      opt.showHelp();
    }
}

function printLn() {
  var args = Array.prototype.slice.call(arguments, 0);
  args[0] = " " + args[0];
  console.log.apply(this, args);
  return true;
}


================================================
FILE: lib/index.js
================================================
var request = require('request')
  , colors = require('colors')
  , url = "http://api.staticfile.org/v1/search?count=10&q="
  , show_url = "http://api.staticfile.org/v1/packages/"

exports.search = function (keyword, cb) {
  request.get({url: url + encodeURIComponent(keyword), json: true}, function (err, response, data) {
    return cb(err, data);
  });
};

exports.get = function (keyword, cb) {
  request.get({url: url + encodeURIComponent(keyword), json: true}, function (err, response, data) {
    if (err) return cb(err);

    if (!data.libs) return cb(null, false);

    var matched_lib = false;
    var suggest = [];

    data.libs.forEach(function (lib) {
      if (lib.name.toLowerCase() == keyword.toLowerCase()) matched_lib = lib;
      suggest.push(lib.name);
    });

    return cb(null, matched_lib, suggest);
  });
};

exports.info = function (keyword, cb) {
  request.get({url: show_url + encodeURIComponent(keyword), json: true}, function (err, response, data) {
    if (err) return cb(err);

    if (data.hasOwnProperty('success') && !data.success) return cb(new Error("Package '" + keyword + "' not exist"));

    return cb(null, data);
  });
}

exports.error = function (e) {
  console.log("错误".redBG + " " + (e instanceof Object ? e.message : e));
};

exports.loading = function () {
  console.log("加载中...".grey);
};

exports.html = function (file) {
  var ext = exports.ext(file);
  switch (ext) {
    case "js":
      return '<script type="text/javascript" src="' + file + '"></script>';
      break;
    case 'css':
      return '<link type="text/css" rel="stylesheet" href="' + file + '"/>';
      break;
    default:
      return false;
  }
};

exports.jade = function (file) {
  var ext = exports.ext(file);
  switch (ext) {
    case "js":
      return 'script(type="text/javascript" src="' + file + '")'
      break;
    case 'css':
      return 'link(type="text/css" rel="stylesheet" href="' + file + '")';
      break;
    default:
      return false;
  }
};

exports.ext = function (filename) {
  var i = filename.lastIndexOf('.');
  return (i < 0) ? '' : filename.substr(i + 1);
};

exports.url = function (path, ssl) {
  ssl = ssl || false;

  return (ssl ? '//dn-staticfile.qbox.me' : 'http://cdn.staticfile.org') + path;
};


================================================
FILE: package.json
================================================
{
  "name": "sfile",
  "version": "0.1.2",
  "description": "The static library search and cli for staticfile.org.",
  "author": "hfcorriez <hfcorriez@gmail.com>",
  "licenses": [
    {
      "type": "MIT",
      "url": "https://github.com/staticfile/cli/blob/master/LICENSE"
    }
  ],
  "homepage": "http://staticfile.org",
  "engines": {
    "node": "*"
  },
  "dependencies": {
    "optimist": "0.6.0",
    "colors": "0.6.2",
    "request": "2.27.0",
    "cliparoo": "1.0.0",
    "term-list": "0.2.0",
    "prettyjson": "~0.12.0"
  },
  "bin": {
    "sfile": "bin/sfile"
  }
}
Download .txt
gitextract_68jodr4t/

├── .gitignore
├── LICENSE
├── README.md
├── bin/
│   └── sfile
├── lib/
│   └── index.js
└── package.json
Condensed preview — 6 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (13K chars).
[
  {
    "path": ".gitignore",
    "chars": 21,
    "preview": "node_modules/\n.idea/\n"
  },
  {
    "path": "LICENSE",
    "chars": 1077,
    "preview": "The MIT License (MIT)\n\nCopyright (c) 2013 staticfile\n\nPermission is hereby granted, free of charge, to any person obtain"
  },
  {
    "path": "README.md",
    "chars": 757,
    "preview": "# 介绍\n\n[staticfile.org](http://staticfile.org)命令行工具\n\n# 安装\n\n```\nnpm install -g sfile\n```\n\n# 使用\n\n## 快捷搜索\n\n快速搜索关键字\n\n```\nsfil"
  },
  {
    "path": "bin/sfile",
    "chars": 7317,
    "preview": "#!/usr/bin/env node\nvar sfile = require('../lib')\n  , clip = require('cliparoo')\n  , opt = require('optimist')\n  , argv "
  },
  {
    "path": "lib/index.js",
    "chars": 2261,
    "preview": "var request = require('request')\n  , colors = require('colors')\n  , url = \"http://api.staticfile.org/v1/search?count=10&"
  },
  {
    "path": "package.json",
    "chars": 581,
    "preview": "{\n  \"name\": \"sfile\",\n  \"version\": \"0.1.2\",\n  \"description\": \"The static library search and cli for staticfile.org.\",\n  \""
  }
]

About this extraction

This page contains the full source code of the staticfile/cli GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 6 files (11.7 KB), approximately 3.4k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!