Skip to content

Commit 543e380

Browse files
authored
Merge pull request #33 from Himenon/feature/export-static
feat(export-static): add `--export-static` option
2 parents e2ec392 + 9796b39 commit 543e380

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+945
-230
lines changed

.vscode/launch.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313
"program": "${workspaceFolder}/packages/cli/bin/code-dependency.js",
1414
"outFiles": ["${workspaceFolder}/**/*.js"],
1515
"args": ["--source", "src"]
16+
},
17+
{
18+
"type": "node",
19+
"request": "launch",
20+
"name": "export static",
21+
"skipFiles": ["<node_internals>/**"],
22+
"cwd": "${workspaceFolder}/packages/cli",
23+
"program": "${workspaceFolder}/packages/cli/bin/code-dependency.js",
24+
"outFiles": ["${workspaceFolder}/**/*.js"],
25+
"args": ["--source", "src", "--export-static", "${workspaceFolder}/packages/cli/output"]
1626
}
1727
]
1828
}

lerna.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,10 @@
1111
"publish": {
1212
"access": "public",
1313
"allowBranch": "master",
14-
"ignoreChanges": [
15-
"CHANGELOG.md"
16-
]
14+
"ignoreChanges": ["CHANGELOG.md"]
1715
}
1816
},
19-
"packages": [
20-
"packages/*"
21-
],
17+
"packages": ["packages/*"],
2218
"version": "0.3.6",
2319
"npmClient": "yarn",
2420
"registry": "https://registry.npmjs.org/",

packages/cli/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ package-lock.json
88
private_npm_cache
99
data
1010
dist
11+
output

packages/cli/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,29 @@ cruise ignore pattern (default: "node_modules"). [see](https://github.com/sverwe
5151
code-dependency --source ./src --exclude node_modules
5252
```
5353

54+
**--export-static**
55+
56+
generate static site.
57+
58+
```bash
59+
code-dependency --source ./src --exclude node_modules --export-static ./docs
60+
```
61+
62+
**--public-path**
63+
64+
```bash
65+
code-dependency --source ./src --exclude node_modules --export-static ./docs --public-path /docs
66+
code-dependency --source ./src --exclude node_modules --export-static ./docs --public-path https://himenon.github.io/code-dependency/
67+
```
68+
69+
**--dry-run** (experimental)
70+
71+
if failed generate static file and retry generate static file only unfinished path.
72+
73+
```bash
74+
code-dependency --source ./src --exclude node_modules --export-static ./docs --dry-run
75+
```
76+
5477
## License
5578

5679
@code-dependency/cli is [MIT licensed](https://github.com/Himenon/code-dependency/blob/master/LICENSE).

packages/cli/package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
"build:webpack": "webpack --config ./scripts/build.ts",
3434
"clean": "rimraf ./lib ./build ./dist",
3535
"develop": "cross-env NODE_ENV=development yarn build:webpack --watch",
36+
"export:static": "node ./bin/code-dependency.js --source ./src --exclude node_modules --export-static ./output --public-path http://localhost:5000/output",
37+
"generate:docs": "node ./bin/code-dependency.js --source ./src --exclude node_modules --export-static ../../docs --public-path https://himenon.github.io/code-dependency/",
3638
"server": "nodemon ./bin/code-dependency.js --source ./src --exclude node_modules",
3739
"start": "run-p develop server",
38-
"test": "jest -c jest.config.json",
40+
"test": "jest -c jest.config.json && yarn export:static",
3941
"test:depcruise": "depcruise --validate .dependency-cruiser.json src",
4042
"ts": "ts-node -P tsconfig.json"
4143
},
@@ -56,7 +58,9 @@
5658
"react-router-dom": "^5.1.2",
5759
"recursive-readdir": "^2.2.2",
5860
"resolve-pkg": "^2.0.0",
59-
"tsconfig": "^7.0.0"
61+
"rimraf": "^3.0.1",
62+
"tsconfig": "^7.0.0",
63+
"urljoin": "^0.1.5"
6064
},
6165
"devDependencies": {
6266
"@types/compression": "^1.0.1",
@@ -65,7 +69,8 @@
6569
"@types/fs-extra": "^8.0.1",
6670
"@types/pretty": "^2.0.0",
6771
"@types/react": "^16.9.17",
68-
"@types/react-dom": "^16.9.4"
72+
"@types/react-dom": "^16.9.4",
73+
"@types/rimraf": "^2.0.3"
6974
},
7075
"publishConfig": {
7176
"access": "public"

packages/cli/scripts/webpack.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as path from "path";
22
import * as webpack from "webpack";
3+
import { CleanWebpackPlugin } from "clean-webpack-plugin";
34

45
const ProgressBarPlugin = require("progress-bar-webpack-plugin");
56
const FriendlyErrorsWebpackPlugin = require("friendly-errors-webpack-plugin");
@@ -47,6 +48,7 @@ export const generateConfig = ({ isProduction }: Option): webpack.Configuration[
4748
plugins: [
4849
new ProgressBarPlugin(),
4950
new FriendlyErrorsWebpackPlugin(),
51+
new CleanWebpackPlugin(),
5052
new webpack.DefinePlugin({
5153
"process.env.NODE_ENV": JSON.stringify("production"),
5254
"process.env.isProduction": JSON.stringify(isProduction),

packages/cli/src/cli/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ interface CLIArguments {
1010
tsConfig?: PathFactory.Type;
1111
exclude?: string;
1212
webpackConfig?: PathFactory.Type;
13+
exportStatic?: PathFactory.Type;
14+
publicPath?: string;
15+
dryRun: boolean;
1316
}
1417

1518
export const validateCliArguments = (args: commander.Command): CLIArguments => {
@@ -25,6 +28,9 @@ export const validateCliArguments = (args: commander.Command): CLIArguments => {
2528
tsConfig: args["tsConfig"] && PathFactory.create({ source: args["tsConfig"] }),
2629
exclude: args["exclude"],
2730
webpackConfig: args["webpackConfig"] && PathFactory.create({ source: args["webpackConfig"] }),
31+
exportStatic: args["exportStatic"] && PathFactory.create({ source: args["exportStatic"] }),
32+
publicPath: args["publicPath"],
33+
dryRun: !!args["dryRun"],
2834
};
2935
};
3036

@@ -36,6 +42,9 @@ export const executeCommandLine = (): CLIArguments => {
3642
.option("--ts-config [path]", "tsconfig.json path", undefined)
3743
.option("--webpack-config [path]", "webpack.config.js path (only js file)")
3844
.option("--exclude [string pattern]", "cruise exclude pattern", "node_modules")
45+
.option("--export-static [static directory]", "static file hosting directory")
46+
.option("--public-path [host public path]", "the base path for all the assets")
47+
.option("--dry-run", "only use --export-static option")
3948
.parse(process.argv);
4049
return validateCliArguments(commander);
4150
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const routes = {
2+
project: {
3+
path: "/project",
4+
},
5+
assets: {
6+
path: "/assets",
7+
},
8+
api: {
9+
path: "/api",
10+
},
11+
};

packages/cli/src/controller/StylesheetsController.tsx renamed to packages/cli/src/controller/AssetController.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { find } from "../utils";
33

44
export const create = () => {
55
const router = express.Router();
6-
router.use("/", express.static(find("@code-dependency/view/dist/stylesheets")));
6+
router.use("/", express.static(find("@code-dependency/view/dist/")));
77
return router;
88
};

packages/cli/src/controller/IndexController.tsx renamed to packages/cli/src/controller/ProjectController.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import express from "express";
22
import ReactDOMServer from "react-dom/server";
3-
import { IndexView } from "../view";
3+
import { ProjectView } from "../view";
44
import * as Service from "../service";
55
import * as Config from "../config";
66

@@ -9,8 +9,16 @@ export const create = (service: Service.Type, config: Config.Type) => {
99
router.get("/", async (req, res) => {
1010
const serverUrl = `${req.protocol}://${req.hostname}:${config.server.port}`;
1111
try {
12-
const props: IndexView.Props = { serverUrl, url: req.url, context: {}, service, filePathList: config.filePathList };
13-
const html = ReactDOMServer.renderToString(await IndexView.create(props));
12+
const props: ProjectView.Props = {
13+
serverUrl,
14+
publicPath: serverUrl,
15+
url: req.url,
16+
pathname: req.query.pathname,
17+
context: {},
18+
service,
19+
filePathList: config.filePathList,
20+
};
21+
const html = ReactDOMServer.renderToString(await ProjectView.create(props));
1422
res.send(html);
1523
res.end();
1624
} catch (error) {

0 commit comments

Comments
 (0)