-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(export-static): add --export-static
option
#33
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
bfc7a82
feat: add exporter
Himenon 22780b3
fix: add process.setMaxListeners
Himenon 04136a4
feat: success assets load
Himenon da9457a
feat: generate svg elements
Himenon fddc0a2
feat: update router
Himenon d9fba54
feat: update react router hoc
Himenon 27139d8
feat: add useHistory
Himenon 381157e
feat: change query pathname
Himenon 0995b52
feat: restore element by reopen window
Himenon af0d05d
feat: seperate project view
Himenon 393e68c
refactor: use flat state
Himenon 485541b
feat: start csr after page loaded
Himenon fb3e1d7
feat: change output directory to project
Himenon 8c50ca6
feat: force reload static link
Himenon e17068c
fix: current pathname title
Himenon 8b6a330
feat: open current directory child paths
Himenon 24aefa5
feat: add error boundary
Himenon 8124e22
fix: Error: Invariant failed
Himenon b7f7f66
feat: update routing
Himenon 4d775c5
feat: update routing
Himenon ab61c47
feat: add invalidUrl check
Himenon 0f340ec
feat: update async loop
Himenon cdf5ca4
feat: add assets base path
Himenon 7fa1f34
fix: cruise path
Himenon de2d124
feat: add dry run
Himenon 2e67036
refactor: path option
Himenon 6efc144
refactor: rename props key names
Himenon d0492b7
refactor(cli): change routing path to const
Himenon a52ca70
docs: update document
Himenon 9796b39
chore: add generate docs script
Himenon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -8,3 +8,4 @@ package-lock.json | |
private_npm_cache | ||
data | ||
dist | ||
output |
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
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export const routes = { | ||
project: { | ||
path: "/project", | ||
}, | ||
assets: { | ||
path: "/assets", | ||
}, | ||
api: { | ||
path: "/api", | ||
}, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as rimraf from "rimraf"; | ||
import * as fs from "fs"; | ||
|
||
export interface DryRunCache { | ||
[pathname: string]: "done" | "pending"; | ||
} | ||
|
||
export const create = (filename: string, dryRun: boolean) => { | ||
const getDryRunCache = (): DryRunCache => { | ||
if (dryRun && fs.existsSync(filename)) { | ||
return JSON.parse(fs.readFileSync(filename, { encoding: "utf-8" })); | ||
} else { | ||
return {}; | ||
} | ||
}; | ||
|
||
const updateDryRunCache = (cache: DryRunCache) => { | ||
if (dryRun) { | ||
fs.writeFileSync(filename, JSON.stringify(cache, null, 2), { encoding: "utf-8" }); | ||
} | ||
}; | ||
|
||
const deleteDryRunCache = () => { | ||
if (dryRun) { | ||
rimraf.sync(filename); | ||
} | ||
}; | ||
|
||
return { | ||
getDryRunCache, | ||
updateDryRunCache, | ||
deleteDryRunCache, | ||
}; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import * as ReactDOM from "react-dom/server"; | ||
import * as Service from "../service"; | ||
import * as Config from "../config"; | ||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
import * as View from "./view"; | ||
import { find } from "../utils"; | ||
import { routes } from "../constants/router"; | ||
import * as DryRun from "./DryRun"; | ||
import manifest from "@code-dependency/view/dist/manifest.json"; | ||
|
||
export const create = (service: Service.Type, config: Config.Type, isDryRun: boolean) => { | ||
process.setMaxListeners(config.filePathList.length); | ||
const generateStaticHtml = async (pathname: string, publicPath: string, assets: View.Assets): Promise<string> => { | ||
const url = path.join("/", pathname.replace(path.extname(pathname), "")); | ||
const dotSource = service.dependencyCruiser.getDependenciesDot(path.join(config.absoluteRootDirPath, pathname)); | ||
const view = await View.create(url, publicPath, pathname, dotSource, config.filePathList, assets); | ||
return "<!DOCTYPE html>" + ReactDOM.renderToStaticMarkup(view); | ||
}; | ||
|
||
const writePage = (dist: string, html: string) => { | ||
if (!fs.existsSync(path.dirname(dist))) { | ||
fs.mkdirSync(path.dirname(dist), { recursive: true }); | ||
} | ||
fs.writeFileSync(dist, html, { encoding: "utf-8" }); | ||
}; | ||
|
||
const copyAssets = async (distDir: string): Promise<View.Assets> => { | ||
const assets: View.Assets = JSON.parse(JSON.stringify(manifest)); | ||
const promises = Object.entries(manifest).map(([key, assetsPath]) => { | ||
if (path.extname(assetsPath) === ".html") { | ||
return; | ||
} | ||
return new Promise((resolve, reject) => { | ||
const src = find("@code-dependency/view/dist/" + assetsPath, false); | ||
const dist = path.join(distDir, assetsPath); | ||
if (!fs.existsSync(path.dirname(dist))) { | ||
fs.mkdirSync(path.dirname(dist), { recursive: true }); | ||
} | ||
fs.copyFile(src, dist, error => { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
assets[key] = path.join(routes.assets.path, assetsPath); | ||
}); | ||
}); | ||
await Promise.all(promises); | ||
return assets; | ||
}; | ||
|
||
return { | ||
generateStaticHtml: async (publicPath: string, outputBaseDir: string) => { | ||
const assets = await copyAssets(path.join(outputBaseDir, routes.assets.path)); | ||
const dryRunCacheFilename = path.join(outputBaseDir, ".code-dependency.json"); | ||
const dryRun = DryRun.create(dryRunCacheFilename, isDryRun); | ||
const dryRunCache = dryRun.getDryRunCache(); | ||
for await (const filePath of config.filePathList) { | ||
const pathname = filePath.source; | ||
if (dryRunCache[pathname] === "done") { | ||
continue; | ||
} | ||
if (dryRunCache[pathname] === "pending") { | ||
continue; | ||
} else { | ||
dryRunCache[pathname] = "pending"; | ||
} | ||
dryRun.updateDryRunCache(dryRunCache); | ||
const outputFilePath = path.join(outputBaseDir, "project", pathname).replace(path.extname(pathname), ".html"); | ||
const html = await generateStaticHtml(filePath.source, publicPath, assets); | ||
writePage(outputFilePath, html); | ||
dryRunCache[pathname] = "done"; | ||
} | ||
dryRun.deleteDryRunCache(); | ||
}, | ||
}; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new !