-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
239 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,7 @@ | |
"options": { | ||
"useTabs": true, | ||
"lineWidth": 101, | ||
"indentWidth": 2, | ||
"singleQuote": true | ||
"indentWidth": 2 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Oops, something went wrong.