forked from NOVASland/NOVAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compiled file is written only when older than source file
- Loading branch information
1 parent
3631db7
commit 5fa94df
Showing
7 changed files
with
86 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,6 @@ | |
``` | ||
novas create my-app | ||
cd my-app | ||
novas build | ||
novas dev | ||
``` | ||
- After running <code>novas dev</code>, open <a href=http://localhost:3000>http://localhost:3000</a> to see your app.</p> | ||
|
@@ -29,17 +28,25 @@ novas dev | |
- Install NOVAS | ||
|
||
``` | ||
deno install --allow-net --allow-read --allow-write --unstable https://deno.land/x/novas/cli.ts | ||
deno install --allow-net --allow-read --allow-write --allow-run --unstable https://deno.land/x/novas/cli.ts | ||
``` | ||
<details><summary>About Permissions</summary> | ||
<ul> | ||
<li>--allow-net: Required for the dev server. </li> | ||
<li> --allow-read: Allows NOVAS to compile svelte files.</li> | ||
<li> --allow-write: Allows NOVAS to write to files it creates during the <code>novas build</code> process</li> | ||
<li> --allow-run: Allows NOVAS to run shell command.</li> | ||
<li> --unstable: Allows the use of Deno's standard modules which might not be stable yet.</li> | ||
</ul> | ||
Read more about <a href="https://deno.land/[email protected]/getting_started/permissions">permissions</a> or <a href="https://deno.land/manual/runtime/stability">stability</a> here | ||
</details> | ||
or simply, | ||
|
||
``` | ||
deno install -A https://deno.land/x/novas/cli.ts | ||
``` | ||
|
||
|
||
|
||
## ⭐ How to use NOVAS | ||
|
||
|
@@ -48,19 +55,23 @@ Read more about <a href="https://deno.land/[email protected]/getting_started/permis | |
``` | ||
novas create [project name] | ||
``` | ||
- To compile, first change directories to the root of the project (<code>cd [project name]</code>) then type: | ||
|
||
- To start developing, type: | ||
|
||
``` | ||
novas build | ||
novas dev | ||
``` | ||
|
||
- To start developing, type: | ||
- This will rebuild the source, start up the development server and will open a websocket listening for any changes to the <code>./src</code> folder. Upon saving changes, your svelte code will be compiled again and transpiled code are saved in<code>./build</code> and the browser will reload to reflect the changes. | ||
|
||
- To compile, first change directories to the root of the project (<code>cd [project name]</code>) then type: | ||
|
||
``` | ||
novas dev | ||
novas build | ||
``` | ||
- At at end <code>novas build</code> will invoke <code>deno bundle</code> to pack all files in <code>./build</code> and create a stand alone <code>./public/bundle.js</code>. | ||
- deploy <code>index.bundle.html</code> + <code>bundle.js</code> if ES6 module loading is not available, e.g, serving via file:// protocol . | ||
|
||
- This will start up the development server and will open a websocket listening for any changes to the <code>./src</code> folder. Upon saving changes, your svelte code will be compiled again and the browser will reload to reflect the changes. | ||
|
||
## Read More | ||
- <a href='https://medium.com/codex/novas-accelerating-svelte-and-deno-application-generation-3371c395461a'>NOVAS: Accelerating Svelte and Deno Application Creation </a> | ||
|
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,10 +1,21 @@ | ||
import flags from "./flags.ts"; | ||
import { ensureFile } from "https://deno.land/[email protected]/fs/mod.ts"; | ||
import { ensureFile,existsSync } from "https://deno.land/[email protected]/fs/mod.ts"; | ||
import { join } from "https://deno.land/[email protected]/path/mod.ts"; | ||
import { compiler } from "../compiler/compiler.ts"; | ||
import boilerplate from "../templates/build.ts"; | ||
import denofy from "../compiler/compiler.ts"; | ||
|
||
const updateNeeded=async (srcfn: string, buildfn: string)=>{ | ||
const buildexists=await existsSync(buildfn); | ||
await ensureFile(buildfn); | ||
|
||
const srcstat=await Deno.fstatSync( Deno.openSync(srcfn, { read: true }).rid); | ||
const buildstat=await Deno.fstatSync( Deno.openSync(buildfn, { read: true }).rid); | ||
const srcmtime=srcstat?.mtime || 0; | ||
const buildmtime=buildstat?.mtime || -1; | ||
|
||
return (!buildexists || srcmtime>buildmtime); | ||
} | ||
// Function to run when given build command | ||
export const BuildProject = async (flag: string, cwd = Deno.cwd(), path = '/src/App.svelte') => { // C:\\Users\\Tanner\\Documents\\GitHub\\NOVAS2\\tests\\src\\App.svelte | ||
const sveltePath = "https://cdn.skypack.dev/[email protected]"; | ||
|
@@ -19,40 +30,42 @@ export const BuildProject = async (flag: string, cwd = Deno.cwd(), path = '/src/ | |
|
||
await ensureFile("./build/index.js"); | ||
Deno.writeFile("./build/index.js", encoder.encode(boilerplate.indexJs)); | ||
|
||
const buildImports = async (filePath: string) => { | ||
let buildfn=join("./build", filePath.replace(cwd, "")); | ||
buildfn += filePath.endsWith(".svelte") ? '.js':''; | ||
|
||
filePath.endsWith(".svelte") ? await handleSvelte() : handleOther(); | ||
|
||
async function handleSvelte() { | ||
const { js, ast } = await compiler(filePath); | ||
const data = encoder.encode(js); | ||
|
||
await ensureFile(join("./build", filePath.replace(cwd, "")) + ".js"); | ||
await Deno.writeFile( | ||
join("./build", filePath.replace(cwd, "")) + ".js", | ||
data, | ||
); | ||
|
||
if (await updateNeeded(filePath,buildfn)) { | ||
console.log('updating',filePath); | ||
const data = encoder.encode(js); | ||
await Deno.writeFile(buildfn,data); | ||
} | ||
const nestedImports = ast.instance?.content?.body?.filter(( | ||
script: { type: string; source: { value: string } }, | ||
) => script.type === "ImportDeclaration"); | ||
if (!nestedImports) return; | ||
for (const nested of nestedImports) { | ||
for await (const nested of nestedImports) { | ||
if (memoized[nested.source.value] === true) continue; | ||
memoized[nested.source.value] = true; | ||
buildImports(join(cwd, nested.source.value.replace(".", "src/"))); | ||
await buildImports(join(cwd, nested.source.value.replace(".", "src/"))); | ||
} | ||
} | ||
|
||
async function handleOther() { | ||
try { | ||
const currentFile = await Deno.readTextFile(filePath); | ||
const denofiedFile = await denofy(currentFile, sveltePath); | ||
const data = encoder.encode(denofiedFile); | ||
await ensureFile("./build" + filePath.replace(cwd, '')); | ||
await Deno.writeFile("./build" + filePath.replace(cwd, ''), data); | ||
if (await updateNeeded(filePath,buildfn)) { | ||
const currentFile = await Deno.readTextFile(filePath); | ||
const denofiedFile = await denofy(currentFile, sveltePath); | ||
const data = encoder.encode(denofiedFile); | ||
await Deno.writeFile(buildfn, data); | ||
} | ||
} | ||
catch { | ||
catch(e) { | ||
console.log(e); | ||
return; | ||
} | ||
} | ||
|
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
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