mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-06 04:21:09 +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:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,10 +1,13 @@
|
||||
.DS_Store
|
||||
|
||||
node_modules/
|
||||
nodejs/
|
||||
|
||||
coverage/
|
||||
.vscode/
|
||||
|
||||
yarn.lock
|
||||
dist/
|
||||
lib/
|
||||
lib/
|
||||
|
||||
*.tar.gz
|
||||
5574
package-lock.json
generated
5574
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",
|
||||
"prettier": "npx prettier --write \"**/*.{ts,js}\"",
|
||||
"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": {
|
||||
"openapi": "lib/cli.js"
|
||||
@@ -43,10 +45,15 @@
|
||||
"@types/node-fetch": "^2.5.7",
|
||||
"@types/yargs": "^15.0.5",
|
||||
"jest": "^26.0.1",
|
||||
"null-loader": "^4.0.0",
|
||||
"outdent": "^0.7.1",
|
||||
"prettier": "^2.0.5",
|
||||
"shebang-loader": "0.0.1",
|
||||
"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": {
|
||||
"@redocly/ajv": "^6.12.3",
|
||||
@@ -60,6 +67,7 @@
|
||||
"minimatch": "^3.0.4",
|
||||
"node-fetch": "^2.6.0",
|
||||
"portfinder": "^1.0.26",
|
||||
"readline": "^1.3.0",
|
||||
"simple-websocket": "^9.0.0",
|
||||
"typescript": "^3.9.5",
|
||||
"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 { ReadStream } from 'fs';
|
||||
|
||||
const SocketServer = require('simple-websocket/server');
|
||||
const SocketServer = require('simple-websocket/server.js');
|
||||
|
||||
export const mimeTypes = {
|
||||
'.html': 'text/html',
|
||||
|
||||
@@ -190,7 +190,7 @@ export class LintConfig {
|
||||
|
||||
if (fs.existsSync(ignoreFile)) {
|
||||
// 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
|
||||
for (const fileName of Object.keys(this.ignore)) {
|
||||
@@ -403,7 +403,7 @@ export async function loadConfig(configPath?: string, customExtends?: string[]):
|
||||
|
||||
if (configPath !== undefined) {
|
||||
try {
|
||||
rawConfig = await loadYaml(configPath);
|
||||
rawConfig = await loadYaml(configPath) as RawConfig;
|
||||
} catch (e) {
|
||||
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