mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-06 12:47:48 +00:00
feat: add bundling opportunity (#177)
* feat: add bundling opportunity * chore: change flag name for bundle * feat: add bundle & upload commands to build * chore: ignore simple-websocket for bundle * chore: remove net module * feat: add configurable --profile for aws cli * chore: remove externals from webpack config * chore: add websocket comment * chore: rename bundle uploading script * chore: add shebang-loader * chore: null-load fsevents * chore: remove node-loader
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,6 +1,7 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
node_modules/
|
node_modules/
|
||||||
|
nodejs/
|
||||||
|
|
||||||
coverage/
|
coverage/
|
||||||
.vscode/
|
.vscode/
|
||||||
@@ -8,3 +9,5 @@ coverage/
|
|||||||
yarn.lock
|
yarn.lock
|
||||||
dist/
|
dist/
|
||||||
lib/
|
lib/
|
||||||
|
|
||||||
|
*.tar.gz
|
||||||
5576
package-lock.json
generated
5576
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@@ -12,7 +12,9 @@
|
|||||||
"benchmark": "node --expose-gc --noconcurrent_sweeping --predictable ./benchmark/benchmark.js",
|
"benchmark": "node --expose-gc --noconcurrent_sweeping --predictable ./benchmark/benchmark.js",
|
||||||
"prettier": "npx prettier --write \"**/*.{ts,js}\"",
|
"prettier": "npx prettier --write \"**/*.{ts,js}\"",
|
||||||
"typecheck": "tsc --noEmit --skipLibCheck",
|
"typecheck": "tsc --noEmit --skipLibCheck",
|
||||||
"prepublishOnly": "npm run build"
|
"prepublishOnly": "npm run build && npm run bundle && npm run upload",
|
||||||
|
"bundle": "webpack --config webpack.config.ts",
|
||||||
|
"upload": "node scripts/archive-and-upload-bundle.js"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"openapi": "lib/cli.js"
|
"openapi": "lib/cli.js"
|
||||||
@@ -43,10 +45,15 @@
|
|||||||
"@types/node-fetch": "^2.5.7",
|
"@types/node-fetch": "^2.5.7",
|
||||||
"@types/yargs": "^15.0.5",
|
"@types/yargs": "^15.0.5",
|
||||||
"jest": "^26.0.1",
|
"jest": "^26.0.1",
|
||||||
|
"null-loader": "^4.0.0",
|
||||||
"outdent": "^0.7.1",
|
"outdent": "^0.7.1",
|
||||||
"prettier": "^2.0.5",
|
"prettier": "^2.0.5",
|
||||||
|
"shebang-loader": "0.0.1",
|
||||||
"ts-jest": "^26.1.0",
|
"ts-jest": "^26.1.0",
|
||||||
"ts-node": "^8.10.2"
|
"ts-loader": "^8.0.2",
|
||||||
|
"ts-node": "^8.10.2",
|
||||||
|
"webpack": "^4.44.1",
|
||||||
|
"webpack-cli": "^3.3.12"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@redocly/ajv": "^6.12.3",
|
"@redocly/ajv": "^6.12.3",
|
||||||
@@ -60,6 +67,7 @@
|
|||||||
"minimatch": "^3.0.4",
|
"minimatch": "^3.0.4",
|
||||||
"node-fetch": "^2.6.0",
|
"node-fetch": "^2.6.0",
|
||||||
"portfinder": "^1.0.26",
|
"portfinder": "^1.0.26",
|
||||||
|
"readline": "^1.3.0",
|
||||||
"simple-websocket": "^9.0.0",
|
"simple-websocket": "^9.0.0",
|
||||||
"typescript": "^3.9.5",
|
"typescript": "^3.9.5",
|
||||||
"yaml-ast-parser": "0.0.43",
|
"yaml-ast-parser": "0.0.43",
|
||||||
|
|||||||
24
scripts/archive-and-upload-bundle.js
Normal file
24
scripts/archive-and-upload-bundle.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
const yargs = require('yargs');
|
||||||
|
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
const package = require('../package.json');
|
||||||
|
|
||||||
|
const version = package.version;
|
||||||
|
const fileName = `openapi-cli.${version}.tar.gz`;
|
||||||
|
const fileNameLatest = `openapi-cli.latest.tar.gz`;
|
||||||
|
|
||||||
|
execSync(`tar -zcvf ${fileName} dist`);
|
||||||
|
execSync(`tar -zcvf ${fileNameLatest} dist`);
|
||||||
|
|
||||||
|
|
||||||
|
const argv = yargs
|
||||||
|
.option('aws_profile', {
|
||||||
|
alias: 'p',
|
||||||
|
type: 'string',
|
||||||
|
})
|
||||||
|
.argv;
|
||||||
|
|
||||||
|
let profile = !!argv.aws_profile ? `--profile ${argv.aws_profile}` : '';
|
||||||
|
|
||||||
|
execSync(`aws s3 cp ${fileName} s3://openapi-cli-dist ${profile}`);
|
||||||
|
execSync(`aws s3 cp ${fileNameLatest} s3://openapi-cli-dist ${profile}`);
|
||||||
@@ -2,7 +2,7 @@ import * as http from 'http';
|
|||||||
import * as zlib from 'zlib';
|
import * as zlib from 'zlib';
|
||||||
import { ReadStream } from 'fs';
|
import { ReadStream } from 'fs';
|
||||||
|
|
||||||
const SocketServer = require('simple-websocket/server');
|
const SocketServer = require('simple-websocket/server.js');
|
||||||
|
|
||||||
export const mimeTypes = {
|
export const mimeTypes = {
|
||||||
'.html': 'text/html',
|
'.html': 'text/html',
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ export class LintConfig {
|
|||||||
|
|
||||||
if (fs.existsSync(ignoreFile)) {
|
if (fs.existsSync(ignoreFile)) {
|
||||||
// TODO: parse errors
|
// TODO: parse errors
|
||||||
this.ignore = yaml.safeLoad(fs.readFileSync(ignoreFile, 'utf-8'));
|
this.ignore = yaml.safeLoad(fs.readFileSync(ignoreFile, 'utf-8')) as Record<string, Record<string, Set<string>>>;
|
||||||
|
|
||||||
// resolve ignore paths
|
// resolve ignore paths
|
||||||
for (const fileName of Object.keys(this.ignore)) {
|
for (const fileName of Object.keys(this.ignore)) {
|
||||||
@@ -403,7 +403,7 @@ export async function loadConfig(configPath?: string, customExtends?: string[]):
|
|||||||
|
|
||||||
if (configPath !== undefined) {
|
if (configPath !== undefined) {
|
||||||
try {
|
try {
|
||||||
rawConfig = await loadYaml(configPath);
|
rawConfig = await loadYaml(configPath) as RawConfig;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(`Error parsing config file at \`${configPath}\`: ${e.message}`);
|
throw new Error(`Error parsing config file at \`${configPath}\`: ${e.message}`);
|
||||||
}
|
}
|
||||||
|
|||||||
52
webpack.config.ts
Normal file
52
webpack.config.ts
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
const path = require('path');
|
||||||
|
const webpack = require('webpack');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
entry: './src/cli.ts',
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.tsx?$/,
|
||||||
|
use: [
|
||||||
|
{
|
||||||
|
loader: 'ts-loader',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
loader: 'shebang-loader'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
exclude: /node_modules/,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// we use bundling for online processing only, so no need for websockets
|
||||||
|
// which are used only in preview-docs command.
|
||||||
|
// on the other hand it was impossible to bundle this lib into a package
|
||||||
|
test: path.resolve(__dirname, 'node_modules/simple-websocket/server.js'),
|
||||||
|
use: 'null-loader',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: path.resolve(__dirname, 'node_modules/fsevents/fsevents.node'),
|
||||||
|
use: 'null-loader',
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
extensions: [ '.tsx', '.ts', '.js' ],
|
||||||
|
},
|
||||||
|
|
||||||
|
node: {
|
||||||
|
__dirname: false,
|
||||||
|
fs: 'empty',
|
||||||
|
},
|
||||||
|
|
||||||
|
plugins: [
|
||||||
|
new webpack.BannerPlugin({ banner: "#!/usr/bin/env node", raw: true }),
|
||||||
|
],
|
||||||
|
|
||||||
|
output: {
|
||||||
|
filename: 'bundle.js',
|
||||||
|
path: path.resolve(__dirname, 'dist'),
|
||||||
|
},
|
||||||
|
|
||||||
|
target: 'node',
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user