Skip to content

Instantly share code, notes, and snippets.

@Ljzn
Last active February 28, 2019 11:11
Show Gist options
  • Save Ljzn/24c6c7e57731d9cbaf4cc9709af431b9 to your computer and use it in GitHub Desktop.
Save Ljzn/24c6c7e57731d9cbaf4cc9709af431b9 to your computer and use it in GitHub Desktop.
// A tool for creating new deno project.
//
// Download this file, then add `alias bone="deno -A bone.ts"` to your ~/.bashrc.
//
// Usage: bone [task]
//
// Examples:
//
// bone new PATH - Creates a new deno project at the given path
//
const { Process, args, run, writeFile, chdir, cwd } = Deno;
let path = args[1];
let encoder = new TextEncoder();
async function createDir() {
await run({args: ["mkdir", path]}).status();
// change current dir to project file
chdir(path);
let fullpath = cwd();
let name = path.split("/").slice(-1)[0];
console.log("Creating project " + name + " at " + fullpath);
function createFile(filename, data) {
let encodedData = encoder.encode(data);
writeFile(filename, encodedData);
}
// travis ci
createFile(".travis.yml", `install:
- curl -fsSL https://deno.land/x/install/install.sh | sh
- export PATH="$HOME/.deno/bin:$PATH"
script:
- deno test.ts
`);
// systemd service
createFile(name + ".service", `[Unit]
Description=${name}
After=network.target
[Service]
ExecStart=${fullpath + name}.ts
Restart=always
User=nobody
# Use 'nogroup' group for Ubuntu/Debian
# use 'nobody' group for Fedora
Group=nogroup
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=${fullpath}
`);
// project entry
createFile(`mod.ts`, `#!/usr/bin/env deno
console.log("Hello, world!");
`);
run({args: ["chmod", "+x", "mod.ts"]});
// test
createFile("test.ts", `#!/usr/bin/env deno -A`);
console.log("Done");
};
createDir();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment