Skip to content
This repository was archived by the owner on Jul 13, 2022. It is now read-only.

Commit 1f4a863

Browse files
committed
docs onfig
1 parent c418077 commit 1f4a863

File tree

5 files changed

+3975
-298
lines changed

5 files changed

+3975
-298
lines changed

docs/component-docs.config.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,17 @@ const mapToObject = (filePath, group) =>
4444
fs
4545
.readdirSync(filePath, { withFileTypes: true })
4646
.map(file => {
47-
if (fs.lstatSync(path.resolve(filePath, file)).isDirectory()) {
47+
const name = typeof file === 'string' ? file : file.name;
48+
//fs.lstatSync(path.resolve(filePath, file)).isDirectory()
49+
if (file.isDirectory()) {
4850
return mapToObject(
49-
path.join(filePath, file),
50-
nameToGroupTitle(file)
51+
path.join(filePath, name),
52+
nameToGroupTitle(name)
5153
);
5254
} else {
5355
const result = {
54-
file: path.join(filePath, file),
55-
type: getType(file),
56+
file: path.join(filePath, name),
57+
type: getType(name),
5658
};
5759
if (group) {
5860
result.group = group;
@@ -70,5 +72,5 @@ module.exports = {
7072
pages: docs,
7173
output: dist,
7274
github,
73-
//open: true
75+
open: true
7476
};

docs/package.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
"description": "Documentation for React Native Reanimated Canavs",
55
"private": true,
66
"scripts": {
7-
"start": "component-docs serve",
8-
"build": "component-docs build && npm run patch",
7+
"serve": "npm run build && webpack-dev-server",
8+
"build": "component-docs build && npm run patch && webpack",
99
"patch": "node patch.js",
1010
"clean": "del dist/",
11-
"prestart1": "npm run clean",
1211
"deploy": "npm run build && gh-pages -d dist"
1312
},
1413
"devDependencies": {
@@ -18,18 +17,25 @@
1817
"@babel/preset-env": "^7.2.3",
1918
"@babel/preset-flow": "^7.0.0",
2019
"@babel/preset-react": "^7.0.0",
20+
"@webpack-cli/serve": "^0.2.0",
2121
"babel-plugin-module-resolver": "^4.0.0",
22+
"command-line-args": "^5.1.1",
2223
"core-js": "^2.6.8",
24+
"css-loader": "^3.4.0",
2325
"del-cli": "^1.1.0",
2426
"file-loader": "^1.1.11",
2527
"gh-pages": "^2.1.1",
26-
"url-loader": "^1.0.1"
28+
"style-loader": "^1.1.1",
29+
"url-loader": "^1.0.1",
30+
"webpack": "^4.41.4",
31+
"webpack-cli": "^3.3.10",
32+
"webpack-dev-server": "^3.10.1"
2733
},
2834
"author": "",
2935
"license": "MIT",
3036
"dependencies": {
3137
"color": "^2.0.1",
32-
"component-docs": "^0.19.5",
38+
"component-docs": "^0.20.3",
3339
"linaria": "^1.2.4",
3440
"react-native-vector-icons": "^6.4.2"
3541
}

docs/patch.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22
const path = require('path');
33
const fs = require('fs');
44

5+
const pn = path.resolve(__dirname, 'node_modules').replace(/\\/g, '/');
6+
const p = path.resolve(__dirname).replace(/\\/g, '/');
7+
58
function patch() {
69
const needsPatch = path.resolve(__dirname, 'dist', 'app.src.js');
7-
const newContent = fs.readFileSync(needsPatch).toString().replace(/\\/g, '/');
8-
fs.writeFileSync(needsPatch, newContent);
10+
let rawContent = fs.readFileSync(needsPatch).toString();
11+
rawContent = rawContent.replace(/\\/g, '/');
12+
rawContent = rawContent.replace(new RegExp(`${pn}/`, 'g'), '');
13+
rawContent = rawContent.replace(new RegExp(`${p}/`, 'g'), '../');
14+
15+
fs.writeFileSync(needsPatch, rawContent);
916
}
1017

1118
patch();

docs/webpack.config.js

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/* @flow weak */
2+
3+
const webpack = require('webpack');
4+
const path = require('path');
5+
const fs = require('fs');
6+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
7+
8+
const babelrc = require('component-docs/dist/utils/getBabelOptions')({
9+
modules: false,
10+
targets: {
11+
browsers: ['last 2 versions', 'safari >= 7'],
12+
},
13+
});
14+
15+
const createWebpackConfig = require('component-docs/dist/utils/configureWebpack').default;
16+
17+
//const componentDocsConfig = require('./component-docs.config');
18+
//const pathToCSS = componentDocsConfig.style
19+
20+
fs.copyFileSync(path.resolve(__dirname, './assets/styles.css'), path.resolve(__dirname, 'dist', 'app.css'));
21+
22+
const config = {
23+
root: path.resolve(__dirname, '..'),
24+
entry: path.resolve(__dirname, './dist/app.src.js'),
25+
output: {
26+
path: path.resolve(__dirname, 'dist'),
27+
bundle: 'app.bundle.js',
28+
style: 'app.css',
29+
},
30+
production: true
31+
}
32+
33+
function mergeConfig() {
34+
const { production, entry, root, output } = config;
35+
const componentDocsWebpackConfig = createWebpackConfig(config);
36+
const patch = {
37+
context: root,
38+
mode: production ? 'production' : 'development',
39+
devtool: 'source-map',
40+
entry: production
41+
? entry
42+
: [require.resolve('webpack-hot-middleware/client'), entry],
43+
output: {
44+
path: output.path,
45+
filename: output.bundle,
46+
publicPath: '/',
47+
},
48+
optimization: {
49+
minimize: production,
50+
namedModules: true,
51+
concatenateModules: true,
52+
},
53+
plugins: [
54+
new webpack.DefinePlugin({
55+
'process.env': {
56+
NODE_ENV: JSON.stringify(production ? 'production' : 'development'),
57+
},
58+
}),
59+
new MiniCssExtractPlugin({
60+
filename: output.style,
61+
}),
62+
].concat(
63+
production
64+
? [new webpack.LoaderOptionsPlugin({ minimize: true, debug: false })]
65+
: [
66+
new webpack.HotModuleReplacementPlugin(),
67+
new webpack.NoEmitOnErrorsPlugin(),
68+
]
69+
),
70+
module: {
71+
rules: [
72+
{
73+
test: /\.(js|tsx?)$/,
74+
exclude: /node_modules/,
75+
use: [
76+
{
77+
loader: require.resolve('babel-loader'),
78+
options: babelrc,
79+
},
80+
{
81+
loader: require.resolve('linaria/loader'),
82+
options: { sourceMap: !production, babelOptions: babelrc },
83+
},
84+
],
85+
},
86+
{
87+
test: /\.css$/,
88+
use: [
89+
'css-loader',
90+
{ loader: require.resolve('css-hot-loader') },
91+
{
92+
loader: MiniCssExtractPlugin.loader,
93+
options: {
94+
sourceMap: !production,
95+
publicPath: (resourcePath, context) => {
96+
// publicPath is the relative path of the resource to the context
97+
// e.g. for ./css/admin/main.css the publicPath will be ../../
98+
// while for ./css/main.css the publicPath will be ../
99+
return resourcePath
100+
//return path.relative(path.dirname(resourcePath), context) + '/';
101+
},
102+
},
103+
},
104+
{
105+
loader: require.resolve('css-loader'),
106+
options: { sourceMap: !production },
107+
},
108+
],
109+
},
110+
{
111+
test: /\.(bmp|gif|jpg|jpeg|png|svg|webp|eot|woff|woff2|ttf)$/,
112+
use: {
113+
loader: require.resolve('file-loader'),
114+
options: {
115+
outputPath: 'assets/',
116+
publicPath: 'assets/',
117+
},
118+
},
119+
},
120+
],
121+
},
122+
}
123+
124+
return patch;
125+
}
126+
127+
128+
129+
130+
131+
module.exports = {
132+
...createWebpackConfig(config),
133+
134+
devServer: {
135+
contentBase: path.join(__dirname, 'dist'),
136+
compress: true,
137+
port: 9000
138+
}
139+
};

0 commit comments

Comments
 (0)