Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Extension api #594

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6,246 changes: 3,623 additions & 2,623 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"url": "[email protected]:diplodoc-platform/cli.git"
},
"bin": {
"yfm": "build/index.js"
"yfm": "build/index.js",
"docs": "build/index.js"
},
"main": "build/index.js",
"files": [
Expand All @@ -27,8 +28,8 @@
"lint": "eslint \"src/**/*.{js,jsx,ts,tsx}\"",
"lint:fix": "npm run lint -- --fix",
"typecheck": "tsc --noEmit",
"prepublishOnly": "npm run lint && npm run build",
"git:head": "git checkout master && git pull"
"test": "vitest",
"prepublishOnly": "npm run lint && npm run build"
},
"engines": {
"node": ">=18.*"
Expand Down Expand Up @@ -59,14 +60,16 @@
"@types/json-stringify-safe": "^5.0.3",
"@types/lodash": "4.14.195",
"@types/mime-types": "2.1.4",
"@types/node": "14.*",
"@types/node": "^18.19.4",
"@types/shelljs": "0.8.15",
"@types/tar-stream": "^2.2.2",
"@types/yargs": "17.0.24",
"@vitest/coverage-v8": "^1.2.1",
"ajv": "^8.11.0",
"async": "^3.2.4",
"axios": "^1.6.7",
"chalk": "^4.1.2",
"commander": "^12.0.0",
"esbuild": "^0.20.0",
"glob": "^8.0.3",
"html-escaper": "^3.0.3",
Expand All @@ -77,10 +80,14 @@
"mime-types": "2.1.35",
"minimatch": "^9.0.3",
"node-html-parser": "^6.1.5",
"normalize-path": "^3.0.0",
"simple-git": "3.22.0",
"slugify": "^1.6.5",
"tapable": "^2.2.1",
"tar-stream": "^3.1.4",
"typescript": "^5.3.3",
"typescript": "^5.4.5",
"vite-tsconfig-paths": "^4.2.3",
"vitest": "^1.1.3",
"walk-sync": "^3.0.0"
},
"husky": {
Expand Down
6 changes: 5 additions & 1 deletion scripts/build.cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const {resolve, join, dirname} = require('path');
const esbuild = require('esbuild');
const tsPaths = require('./ts-paths');
const shell = require('shelljs');

const CLIENT_PATH = dirname(require.resolve('@diplodoc/client/manifest'));
Expand All @@ -21,6 +22,9 @@ const commonConfig = {
loader: {
'.map': 'empty',
},
plugins:[
tsPaths()
],
define: {
VERSION: JSON.stringify(version),
},
Expand All @@ -46,7 +50,7 @@ Promise.all(builds.map(([entries, outfile]) => {

currentConfig.external = [
...Object.keys(dependencies),
'package',
'@diplodoc/cli/package',
];

return esbuild.build(currentConfig);
Expand Down
49 changes: 49 additions & 0 deletions scripts/ts-paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const {resolve, join} = require('path');
const {readFileSync} = require('fs');
const {sync: glob} = require('glob');
const normalize = require('normalize-path');

function stripJsonComments(data) {
return data.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (m, g) => (g ? "" : m));
}

module.exports = (relativeTsconfigPath = './tsconfig.json') => {
const absTsconfigPath = resolve(process.cwd(), relativeTsconfigPath);

const tsconfigData = stripJsonComments(readFileSync(absTsconfigPath, 'utf8'));

const { compilerOptions } = JSON.parse(tsconfigData);

const pathKeys = Object.keys(compilerOptions.paths);
const re = new RegExp(`^(${pathKeys.join('|')})`);
return {
name: 'ts-paths',
setup(build) {
build.onResolve({ filter: re }, (args) => {
const pathKey = pathKeys.find((pkey) => new RegExp(`^${pkey}`).test(args.path));
const [pathDir] = pathKey.split('*');

let file = args.path.replace(pathDir, '');
if (file === args.path) { // if importing from root of alias
file = '';
}

for (const dir of compilerOptions.paths[pathKey]) {
const fileDir = normalize(resolve(process.cwd(), dir).replace('*', file));

let [matchedFile] = glob(`${fileDir}.+(ts|tsx|js|jsx)`);
if (!matchedFile) {
const [matchIndexFile] = glob(normalize(fileDir + '/index.+(ts|tsx|js|jsx)'));
matchedFile = matchIndexFile;
}

if (matchedFile) {
return { path: matchedFile };
}
}

return { path: args.path };
});
},
};
};
2 changes: 1 addition & 1 deletion src/cmd/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
} from '../../steps';
import {prepareMapFile} from '../../steps/processMapFile';
import {copyFiles, logger} from '../../utils';
import {upload as publishFilesToS3} from '../publish/upload';
import {upload as publishFilesToS3} from '../../commands/publish/upload';

export const build = {
command: ['build', '$0'],
Expand Down Expand Up @@ -174,7 +174,7 @@
);
}

async function handler(args: Arguments<any>) {

Check warning on line 177 in src/cmd/build/index.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
const userOutputFolder = resolve(args.output);
const tmpInputFolder = resolve(args.output, TMP_INPUT_FOLDER);
const tmpOutputFolder = resolve(args.output, TMP_OUTPUT_FOLDER);
Expand All @@ -186,7 +186,7 @@
input: tmpInputFolder,
output: tmpOutputFolder,
});
Includers.init([OpenapiIncluder as any]);

Check warning on line 189 in src/cmd/build/index.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type

const {
output: outputFolderPath,
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export {build} from './build';
export {publish} from './publish';
export {translate} from './translate';
// export {publish} from './publish';
// export {translate} from './translate';
99 changes: 0 additions & 99 deletions src/cmd/publish/index.ts

This file was deleted.

67 changes: 0 additions & 67 deletions src/cmd/publish/upload.ts

This file was deleted.

Loading
Loading