Skip to content

Commit

Permalink
feat: Rewrite publish and translate commands on extension api
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3 committed Apr 12, 2024
1 parent c9722d5 commit 131ce5f
Show file tree
Hide file tree
Showing 49 changed files with 6,778 additions and 3,475 deletions.
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
4 changes: 4 additions & 0 deletions 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 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 @@ import {
} 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
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

0 comments on commit 131ce5f

Please sign in to comment.