mirror of
https://github.com/akveo/ngx-admin.git
synced 2025-12-17 07:50:12 +01:00
fix(app):add gulpfile for docs
This commit is contained in:
parent
d6e92b4139
commit
8e66b07eb9
8 changed files with 3146 additions and 17 deletions
12
gulpfile.js
Normal file
12
gulpfile.js
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
'use strict';
|
||||||
|
/**
|
||||||
|
* Load the TypeScript compiler and then load the tasks from 'scripts/gulp'.
|
||||||
|
*/
|
||||||
|
const path = require('path');
|
||||||
|
const gulpPath = path.join(__dirname, 'scripts/gulp');
|
||||||
|
const tsconfigPath = path.join(gulpPath, 'tsconfig.json');
|
||||||
|
const tsconfig = require(tsconfigPath);
|
||||||
|
|
||||||
|
// Register TypeScript.
|
||||||
|
require('ts-node').register({ project: tsconfigPath });
|
||||||
|
require(path.join(gulpPath, 'gulpfile'));
|
||||||
3023
package-lock.json
generated
3023
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -27,9 +27,10 @@
|
||||||
"pree2e": "webdriver-manager update --standalone false --gecko false",
|
"pree2e": "webdriver-manager update --standalone false --gecko false",
|
||||||
"e2e": "ng e2e",
|
"e2e": "ng e2e",
|
||||||
"docs": "compodoc -p src/tsconfig.app.json -d docs",
|
"docs": "compodoc -p src/tsconfig.app.json -d docs",
|
||||||
"docs:build": "npm run build -- docs --prod --aot --base-href /ngx-admin/",
|
"docs:build": "npm-run-all docs:prepare docs:dir",
|
||||||
|
"docs:dirs": "gulp create-docs-dirs",
|
||||||
"docs:parse": "gulp docs",
|
"docs:parse": "gulp docs",
|
||||||
"docs:prepare": "npm-run-all docs:parse",
|
"docs:prepare": "npm run build -- docs --prod --aot --base-href /ngx-admin/",
|
||||||
"docs:serve": "npm start -- docs --port 4100",
|
"docs:serve": "npm start -- docs --port 4100",
|
||||||
"docs:gh-pages": "ts-node -P ./scripts/docs/tsconfig.json ./scripts/docs/build-docs.ts",
|
"docs:gh-pages": "ts-node -P ./scripts/docs/tsconfig.json ./scripts/docs/build-docs.ts",
|
||||||
"prepush": "npm run lint:ci",
|
"prepush": "npm run lint:ci",
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,6 @@ async function buildDocs(versions: Version[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function prepareVersion(version: Version, distDir: string, ghspaScript: string) {
|
async function prepareVersion(version: Version, distDir: string, ghspaScript: string) {
|
||||||
console.log(version);
|
|
||||||
const projectDir = join(WORK_DIR, `${version.name}`);
|
const projectDir = join(WORK_DIR, `${version.name}`);
|
||||||
|
|
||||||
await copyToBuildDir(MASTER_BRANCH_DIR, projectDir);
|
await copyToBuildDir(MASTER_BRANCH_DIR, projectDir);
|
||||||
|
|
@ -111,10 +110,10 @@ async function buildDocsApp(projectDir: string, baseHref: string) {
|
||||||
if (!baseHref.endsWith('/')) {
|
if (!baseHref.endsWith('/')) {
|
||||||
baseHref = baseHref + '/';
|
baseHref = baseHref + '/';
|
||||||
}
|
}
|
||||||
await runCommand('npm run docs:prepare', { cwd: projectDir });
|
await runCommand('npm run build -- docs --prod --aot --base-href /ngx-admin/', { cwd: projectDir });
|
||||||
await runCommand(`npm run build -- docs --prod --base-href '${baseHref}'`, { cwd: projectDir });
|
// await runCommand(`npm run build -- docs --prod --base-href '${baseHref}'`, { cwd: projectDir });
|
||||||
await runCommand('npm run docs:dirs', { cwd: projectDir });
|
// await runCommand('npm run docs:dirs', { cwd: projectDir });
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deploy(distDir: string) {
|
async function deploy(distDir: string) {
|
||||||
await runCommand(
|
await runCommand(
|
||||||
|
|
@ -122,3 +121,4 @@ async function deploy(distDir: string) {
|
||||||
{ cwd: distDir, showLog: true },
|
{ cwd: distDir, showLog: true },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
1
scripts/gulp/gulpfile.ts
Normal file
1
scripts/gulp/gulpfile.ts
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
import './tasks/docs/docs';
|
||||||
1
scripts/gulp/tasks/config.ts
Normal file
1
scripts/gulp/tasks/config.ts
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
export const DOCS_DIST = './docs/dist';
|
||||||
88
scripts/gulp/tasks/docs/docs.ts
Normal file
88
scripts/gulp/tasks/docs/docs.ts
Normal file
|
|
@ -0,0 +1,88 @@
|
||||||
|
import { task, series } from 'gulp';
|
||||||
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
||||||
|
import { isAbsolute, join, resolve, sep } from 'path';
|
||||||
|
|
||||||
|
import './example';
|
||||||
|
import { structure as DOCS } from '../../../../docs/structure';
|
||||||
|
import { DOCS_DIST } from '../config';
|
||||||
|
|
||||||
|
task(
|
||||||
|
'docs',
|
||||||
|
series(
|
||||||
|
'generate-doc-json-and-parse-themes',
|
||||||
|
'find-full-examples',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
task('create-docs-dirs', (done) => {
|
||||||
|
const docsStructure = flatten('docs', routesTree(DOCS));
|
||||||
|
createDirsStructure(docsStructure);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
function routesTree(structure) {
|
||||||
|
return structure
|
||||||
|
.filter((page: any) => ['section', 'page', 'tabs'].includes(page.type))
|
||||||
|
.map((page: any) => {
|
||||||
|
if (page.type === 'tabs') {
|
||||||
|
page.children = ['overview', 'api', 'theme', 'examples']
|
||||||
|
.map(name => ({ name, type: 'page'}));
|
||||||
|
}
|
||||||
|
return page;
|
||||||
|
})
|
||||||
|
.map((page: any) => {
|
||||||
|
return {
|
||||||
|
path: prepareSlag(page.name),
|
||||||
|
children: page.children ? routesTree(page.children) : [],
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function prepareSlag(name) {
|
||||||
|
return name.replace(/[^a-zA-Z0-9\s]+/g, '')
|
||||||
|
.replace(/\s/g, '-')
|
||||||
|
.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
function flatten(root, arr) {
|
||||||
|
let res: any[] = [];
|
||||||
|
arr.forEach((item: any) => {
|
||||||
|
const path = `${root}/${item.path}`;
|
||||||
|
res.push(path);
|
||||||
|
if (item.children) {
|
||||||
|
res = res.concat(flatten(path, item.children));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createDirsStructure(dirs) {
|
||||||
|
const index = readFileSync(join(DOCS_DIST, 'index.html'), 'utf8');
|
||||||
|
dirs.forEach((dir: any) => {
|
||||||
|
const fullPath = join(DOCS_DIST, dir);
|
||||||
|
if (!existsSync(fullPath)) {
|
||||||
|
mkDirByPathSync(fullPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
writeFileSync(join(fullPath, 'index.html'), index);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function mkDirByPathSync(targetDir, {isRelativeToScript = false} = {}) {
|
||||||
|
const initDir = isAbsolute(targetDir) ? sep : '';
|
||||||
|
const baseDir = isRelativeToScript ? __dirname : '.';
|
||||||
|
|
||||||
|
targetDir.split(sep).reduce((parentDir, childDir) => {
|
||||||
|
const curDir = resolve(baseDir, parentDir, childDir);
|
||||||
|
try {
|
||||||
|
mkdirSync(curDir);
|
||||||
|
} catch (err) {
|
||||||
|
if (err.code !== 'EEXIST') {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return curDir;
|
||||||
|
}, initDir);
|
||||||
|
}
|
||||||
23
scripts/gulp/tsconfig.json
Normal file
23
scripts/gulp/tsconfig.json
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"lib": [
|
||||||
|
"es2017"
|
||||||
|
],
|
||||||
|
"module": "commonjs",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"strictNullChecks": true,
|
||||||
|
"target": "es5",
|
||||||
|
"typeRoots": [
|
||||||
|
"node_modules/@types"
|
||||||
|
],
|
||||||
|
"types": [
|
||||||
|
"node"
|
||||||
|
],
|
||||||
|
"baseUrl": "."
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"gulpfile.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue