Skip to content

Commit

Permalink
task: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
zaiste committed Oct 19, 2022
1 parent 002725f commit b0cd442
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 243 deletions.
46 changes: 23 additions & 23 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

import { Command } from "cliffy";

import * as init from './cli/init.ts';
import * as deploy from './cli/deploy.ts';
import * as start from './cli/start.ts';
import * as init from "./cli/init.ts";
import * as deploy from "./cli/deploy.ts";
import * as start from "./cli/start.ts";

import Version from './version.json' assert { type: "json" }
import Version from "./version.json" assert { type: "json" };

await new Command()
.name("kretes")
.version(Version)
.description("Web Framework for Deno")
.command(
"init [name:string]",
"Create a new Kretes project"
)
.action(init.action)
.command(
"start",
"Start the project in development mode"
)
.action(start.action)
.command(
"deploy",
"Deploy the project to Deno Deploy"
)
.action(deploy.action)
.parse(Deno.args);
.name("kretes")
.version(Version)
.description("Web Framework for Deno")
.command(
"init [name:string]",
"Create a new Kretes project",
)
.action(init.action)
.command(
"start",
"Start the project in development mode",
)
.action(start.action)
.command(
"deploy",
"Deploy the project to Deno Deploy",
)
.action(deploy.action)
.parse(Deno.args);
35 changes: 17 additions & 18 deletions cli/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import { IAction } from "cliffy";

import { parse } from "path"
import { parse } from "path";

export const action: IAction = async (_options) => {
// TODO brittle as hell :)
// TODO brittle as hell :)

// TODO check if installed
// deno install --allow-read --allow-write --allow-env --allow-net --allow-run --no-check -r -f https://deno.land/x/deploy/deployctl.ts
// TODO check if installed
// deno install --allow-read --allow-write --allow-env --allow-net --allow-run --no-check -r -f https://deno.land/x/deploy/deployctl.ts

// TODO check if root e.g. deno.json
// TODO check if root e.g. deno.json

const { base } = parse(Deno.cwd());
const { base } = parse(Deno.cwd());

const p = Deno.run({
cmd: [
"deployctl",
"deploy",
`--project=${base}`,
"--import-map=import_map.json",
"main.ts"
]
});

await p.status();
}
const p = Deno.run({
cmd: [
"deployctl",
"deploy",
`--project=${base}`,
"--import-map=import_map.json",
"main.ts",
],
});

await p.status();
};
183 changes: 91 additions & 92 deletions cli/init.ts
Original file line number Diff line number Diff line change
@@ -1,107 +1,106 @@
import { IAction } from "cliffy";
import * as path from 'path';
import * as fs from 'fs';
import * as path from "path";
import * as fs from "fs";

export const action: IAction = async (options, name?: string) => {
console.log(
`\n%c 🦋 Kretes %c`,
'background-color: #60A5FA; color: black; font-weight: bold',
'',
);
console.log(
'A programming environment for %cTypeScript%c & Deno\n',
'color: #60A5FA',
'',
);

const projectName = name || 'my-kretes-project';
const projectPath = path.resolve(projectName);

try {
const dir = [...Deno.readDirSync(projectPath)];
const isEmpty = dir.length === 0 ||
dir.length === 1 && dir[0].name === '.git';
if (!isEmpty) {
error('Directory is not empty.');
}
} catch (err) {
if (!(err instanceof Deno.errors.NotFound)) {
throw err;
}
}

await Deno.mkdir(projectName, { recursive: true });

for (const el of InitTemplate) {
await download(template(el), path.join(projectName, el));
}

if (options.vscode) {
await Deno.mkdir(path.join(projectPath, '.vscode'), { recursive: true });

const VSCodeSettings = {
'deno.enable': true,
'deno.lint': true,
'editor.defaultFormatter': 'denoland.vscode-deno',
};

await Deno.writeTextFile(
path.join(projectPath, '.vscode', 'settings.json'),
JSON.stringify(VSCodeSettings, null, 2) + '\n',
);

const VSCodeExtensions = {
recommendations: ['denoland.vscode-deno'],
};

await Deno.writeTextFile(
path.join(projectPath, '.vscode', 'extensions.json'),
JSON.stringify(VSCodeExtensions, null, 2) + '\n',
);
}

console.log('\n%cProject initialized and ready.\n', 'color: green; font-weight: bold');
console.log(
`Enter the project directory using %ccd ${projectName}%c.`,
'color: cyan',
'',
);
console.log(
'Run %ckretes start%c or %cdeno task start%c to start the project. %cCTRL-C%c to stop.',
'color: cyan',
'',
'color: cyan',
'',
'color: cyan',
'',
);
}

console.log(
`\n%c 🦋 Kretes %c`,
"background-color: #60A5FA; color: black; font-weight: bold",
"",
);
console.log(
"A programming environment for %cTypeScript%c & Deno\n",
"color: #60A5FA",
"",
);

const projectName = name || "my-kretes-project";
const projectPath = path.resolve(projectName);

try {
const dir = [...Deno.readDirSync(projectPath)];
const isEmpty = dir.length === 0 ||
dir.length === 1 && dir[0].name === ".git";
if (!isEmpty) {
error("Directory is not empty.");
}
} catch (err) {
if (!(err instanceof Deno.errors.NotFound)) {
throw err;
}
}

await Deno.mkdir(projectName, { recursive: true });

for (const el of InitTemplate) {
await download(template(el), path.join(projectName, el));
}

if (options.vscode) {
await Deno.mkdir(path.join(projectPath, ".vscode"), { recursive: true });

const VSCodeSettings = {
"deno.enable": true,
"deno.lint": true,
"editor.defaultFormatter": "denoland.vscode-deno",
};

await Deno.writeTextFile(
path.join(projectPath, ".vscode", "settings.json"),
JSON.stringify(VSCodeSettings, null, 2) + "\n",
);

const VSCodeExtensions = {
recommendations: ["denoland.vscode-deno"],
};

await Deno.writeTextFile(
path.join(projectPath, ".vscode", "extensions.json"),
JSON.stringify(VSCodeExtensions, null, 2) + "\n",
);
}

console.log("\n%cProject initialized and ready.\n", "color: green; font-weight: bold");
console.log(
`Enter the project directory using %ccd ${projectName}%c.`,
"color: cyan",
"",
);
console.log(
"Run %ckretes start%c or %cdeno task start%c to start the project. %cCTRL-C%c to stop.",
"color: cyan",
"",
"color: cyan",
"",
"color: cyan",
"",
);
};

const template = (element: string) =>
`https://raw.githubusercontent.com/kreteshq/init/main/${element}`;
`https://raw.githubusercontent.com/kreteshq/init/main/${element}`;

const InitTemplate = [
'components/.gitkeep',
'routes/index.page.tsx',
'routes/posts.ts',
'static/.gitkeep',
'.gitignore',
'deno.json',
'import_map.json',
'main.ts'
"components/.gitkeep",
"routes/index.page.tsx",
"routes/posts.ts",
"static/.gitkeep",
".gitignore",
"deno.json",
"import_map.json",
"main.ts",
];

const download = async (url: string, path: string) => {
const response = await fetch(url);
const text = await response.text()
const response = await fetch(url);
const text = await response.text();

await fs.ensureFile(path);
await fs.ensureFile(path);

Deno.writeTextFile(path, text);
Deno.writeTextFile(path, text);
};

const error = (message: string) => {
console.error(`%cerror%c: ${message}`, 'color: red; font-weight: bold', '');
Deno.exit(1);
};
console.error(`%cerror%c: ${message}`, "color: red; font-weight: bold", "");
Deno.exit(1);
};
53 changes: 26 additions & 27 deletions cli/start.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
import type { IAction } from "cliffy";
import { expandGlob } from 'fs'
import { expandGlob } from "fs";
import { Manifest } from "../types.ts";

import { convertFilenameToPathname, generate } from "../util.ts";

export const action: IAction = async (_options) => {
// (re-) generate manifest

const entries = [];
for await (const entry of expandGlob("routes/**/*.{ts,tsx}")) {
const filename = entry.path.split('routes/').pop()!
const pathname = convertFilenameToPathname(filename);

entries.push({ filename, pathname, })
}

await generate(entries);

const p = Deno.run({
cmd: [
"deno",
"run",
"-A",
"--unstable",
"--watch=static/,routes/",
"main.ts"
]
});

await p.status();
}

// (re-) generate manifest

const entries = [];
for await (const entry of expandGlob("routes/**/*.{ts,tsx}")) {
const filename = entry.path.split("routes/").pop()!;
const pathname = convertFilenameToPathname(filename);

entries.push({ filename, pathname });
}

await generate(entries);

const p = Deno.run({
cmd: [
"deno",
"run",
"-A",
"--unstable",
"--watch=static/,routes/",
"main.ts",
],
});

await p.status();
};
3 changes: 1 addition & 2 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"options": {
"useTabs": true,
"lineWidth": 101,
"indentWidth": 2,
"singleQuote": true
"indentWidth": 2
}
}
}
28 changes: 14 additions & 14 deletions import_map.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"imports": {
"preact": "https://esm.sh/[email protected]",
"preact/": "https://esm.sh/[email protected]/",
"preact-render-to-string": "https://esm.sh/[email protected]?external=preact",
"twind": "https://esm.sh/[email protected]",
"twind/": "https://esm.sh/[email protected]/",
"http/": "https://deno.land/[email protected]/http/",
"fs": "https://deno.land/[email protected]/fs/mod.ts",
"path": "https://deno.land/[email protected]/path/mod.ts",
"wren": "https://deno.land/x/[email protected]/mod.ts",
"wren/": "https://deno.land/x/[email protected]/",
"cliffy": "https://deno.land/x/[email protected]/command/mod.ts",
"cli": "https://deno.land/[email protected]/flags/mod.ts"
}
"imports": {
"preact": "https://esm.sh/[email protected]",
"preact/": "https://esm.sh/[email protected]/",
"preact-render-to-string": "https://esm.sh/[email protected]?external=preact",
"twind": "https://esm.sh/[email protected]",
"twind/": "https://esm.sh/[email protected]/",
"http/": "https://deno.land/[email protected]/http/",
"fs": "https://deno.land/[email protected]/fs/mod.ts",
"path": "https://deno.land/[email protected]/path/mod.ts",
"wren": "https://deno.land/x/[email protected]/mod.ts",
"wren/": "https://deno.land/x/[email protected]/",
"cliffy": "https://deno.land/x/[email protected]/command/mod.ts",
"cli": "https://deno.land/[email protected]/flags/mod.ts"
}
}
Loading

0 comments on commit b0cd442

Please sign in to comment.