/shelljs/shelljs-tests.ts

https://github.com/vilic/DefinitelyTyped · TypeScript · 127 lines · 84 code · 33 blank · 10 comment · 5 complexity · 306f8957389d0de7789d1dba6043c8d8 MD5 · raw file

  1. // Tests for shelljs.d.ts
  2. // Project: http://shelljs.org
  3. // Definitions by: Niklas Mollenhauer <https://github.com/nikeee>
  4. // Definitions: https://github.com/borisyankov/DefinitelyTyped
  5. // Tests taken from documentation samples.
  6. ///<reference path="../node/node.d.ts" />
  7. ///<reference path="../shelljs/shelljs.d.ts" />
  8. import shell = require("shelljs");
  9. if (!shell.which("git"))
  10. {
  11. shell.echo("Sorry, this script requires git");
  12. shell.exit(1);
  13. }
  14. // Copy files to release dir
  15. shell.mkdir("-p", "out/Release");
  16. shell.cp("-R", "stuff/*", "out/Release");
  17. // Replace macros in each .js file
  18. shell.cd("lib");
  19. shell.ls("*.js").forEach( file => {
  20. shell.sed("-i", "BUILD_VERSION", "v0.1.2", file);
  21. shell.sed("-i", /.*REMOVE_THIS_LINE.*\n/, "", file);
  22. shell.sed("-i", /.*REPLACE_LINE_WITH_MACRO.*\n/, shell.cat("macro.js"), file);
  23. });
  24. shell.cd("..");
  25. // Run external tool synchronously
  26. if (shell.exec('git commit -am "Auto-commit"').code !== 0)
  27. {
  28. shell.echo("Error: Git commit failed");
  29. shell.exit(1);
  30. }
  31. shell.ls("projs/*.js");
  32. shell.ls("-R", "/users/me", "/tmp");
  33. shell.ls("-R", ["/users/me", "/tmp"]); // same as above
  34. shell.find("src", "lib");
  35. shell.find(["src", "lib"]); // same as above
  36. shell.find(".").filter((file, i, n) => !!file.match(/\.js$/));
  37. shell.cp("file1", "dir1");
  38. shell.cp("-Rf", ["/tmp/*", "/usr/local/*"], "/home/tmp"); // same as aboveshell.
  39. shell.rm("-rf", "/tmp/*");
  40. shell.rm("some_file.txt", "another_file.txt");
  41. shell.rm(["some_file.txt", "another_file.txt"]); // same as above
  42. shell.mv(["file1", "file2"], "dir/"); // same as above
  43. shell.mkdir("-p", "/tmp/a/b/c/d", "/tmp/e/f/g");
  44. shell.mkdir("-p", ["/tmp/a/b/c/d", "/tmp/e/f/g"]); // same as above
  45. if (shell.test("-d", "/tmp/a/b/c/d")) { /* do something with dir */ }
  46. if (!shell.test("-f", "/tmp/a/b/c/d")) { /* do something with dir */ }
  47. var str = shell.cat("file*.txt");
  48. str = shell.cat("file1", "file2");
  49. str = shell.cat(["file1", "file2"]); // same as above
  50. shell.sed("-i", "PROGRAM_VERSION", "v0.1.3", "source.js");
  51. shell.sed(/.*DELETE_THIS_LINE.*\n/, "", "source.js");
  52. shell.grep("-v", "GLOBAL_VARIABLE", "*.js");
  53. shell.grep("GLOBAL_VARIABLE", "*.js");
  54. var nodeExec = shell.which("node");
  55. shell.pushd("/etc"); // Returns /etc /usr
  56. shell.pushd("+1"); // Returns /usr /etc
  57. shell.echo(process.cwd()); // '/usr'
  58. shell.pushd("/etc"); // '/etc /usr'
  59. shell.echo(process.cwd()); // '/etc'
  60. shell.popd(); // '/usr'
  61. shell.echo(process.cwd()); // '/usr'
  62. shell.ln("file", "newlink");
  63. shell.ln("-sf", "file", "existing");
  64. var testPath = shell.env["path"];
  65. import child = require("child_process");
  66. var version = shell.exec("node --version").output;
  67. var version2 = <shell.ExecOutputReturnValue>shell.exec("node --version", { async: false });
  68. var output = version2.output;
  69. var asyncVersion3 = <child.ChildProcess>shell.exec("node --version", { async: true });
  70. var pid = asyncVersion3.pid;
  71. shell.exec("node --version", { silent: true }, function (code, output) {
  72. var version = output;
  73. });
  74. shell.exec("node --version", { silent: true, async: true }, function (code, output) {
  75. var version = output;
  76. });
  77. shell.exec("node --version", function (code, output) {
  78. var version = output;
  79. });
  80. shell.exec("node --version", function (code: number) {
  81. var num: number = code;
  82. });
  83. var childProc = shell.exec("node --version", function (code: number) {
  84. var num: number = code;
  85. });
  86. var pid = childProc.pid;
  87. shell.chmod(755, "/Users/brandon");
  88. shell.chmod("755", "/Users/brandon"); // same as above
  89. shell.chmod("u+x", "/Users/brandon");
  90. shell.exit(0);
  91. var tmp = shell.tempdir(); // "/tmp" for most *nix platforms
  92. var errorlol = shell.error();
  93. shell.config.fatal = true;
  94. shell.config.silent = true;