From 96835ad1a3230029c54b8334c54fd9b3b21b9586 Mon Sep 17 00:00:00 2001 From: 13659257719 <819781841@qq.com> Date: Fri, 13 Oct 2023 15:14:14 +0800 Subject: [PATCH] [inula-dev-tools] inula-dev-tools project init --- packages/inula-dev-tools/README.md | 0 packages/inula-dev-tools/babel.config.js | 41 ++++++++ packages/inula-dev-tools/externals.d.ts | 19 ++++ packages/inula-dev-tools/global.d.ts | 21 ++++ packages/inula-dev-tools/package.json | 54 ++++++++++ packages/inula-dev-tools/src/manifest.json | 35 +++++++ packages/inula-dev-tools/tsconfig.json | 22 ++++ packages/inula-dev-tools/webpack.config.js | 114 +++++++++++++++++++++ packages/inula-dev-tools/webpack.dev.js | 77 ++++++++++++++ 9 files changed, 383 insertions(+) create mode 100644 packages/inula-dev-tools/README.md create mode 100644 packages/inula-dev-tools/babel.config.js create mode 100644 packages/inula-dev-tools/externals.d.ts create mode 100644 packages/inula-dev-tools/global.d.ts create mode 100644 packages/inula-dev-tools/package.json create mode 100644 packages/inula-dev-tools/src/manifest.json create mode 100644 packages/inula-dev-tools/tsconfig.json create mode 100644 packages/inula-dev-tools/webpack.config.js create mode 100644 packages/inula-dev-tools/webpack.dev.js diff --git a/packages/inula-dev-tools/README.md b/packages/inula-dev-tools/README.md new file mode 100644 index 00000000..e69de29b diff --git a/packages/inula-dev-tools/babel.config.js b/packages/inula-dev-tools/babel.config.js new file mode 100644 index 00000000..10a19b67 --- /dev/null +++ b/packages/inula-dev-tools/babel.config.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 Huawei Technologies Co.,Ltd. + * + * openInula is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +module.exports = api => { + const isTest = api.env('test'); + console.log('isTest', isTest); + + const plugins = [ + ['@babel/plugin-proposal-class-properties', { loose: false }], + ]; + + if (process.env.NODE_ENV !== 'production') { + plugins.push(['@babel/plugin-transform-react-jsx-source']); + } + + return { + presets: [ + '@babel/preset-env', + '@babel/preset-typescript', + [ + '@babel/preset-react', { + runtime: 'classic', + 'pragma': 'Inula.createElement', + 'pragmaFrag': 'Inula.Fragment', + }] + ], + plugins, + }; +}; diff --git a/packages/inula-dev-tools/externals.d.ts b/packages/inula-dev-tools/externals.d.ts new file mode 100644 index 00000000..72bdaf9d --- /dev/null +++ b/packages/inula-dev-tools/externals.d.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 Huawei Technologies Co.,Ltd. + * + * openInula is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +declare module '*.less' { + const resource: {[key: string]: string}; + export = resource; +} diff --git a/packages/inula-dev-tools/global.d.ts b/packages/inula-dev-tools/global.d.ts new file mode 100644 index 00000000..646c0399 --- /dev/null +++ b/packages/inula-dev-tools/global.d.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Technologies Co.,Ltd. + * + * openInula is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +/* + 区分是否开发者模式 + */ +declare var isDev: boolean; +declare var isTest: boolean; +declare const __VERSION__: string; diff --git a/packages/inula-dev-tools/package.json b/packages/inula-dev-tools/package.json new file mode 100644 index 00000000..3675f56d --- /dev/null +++ b/packages/inula-dev-tools/package.json @@ -0,0 +1,54 @@ +{ + "name": "inula-dev-tools", + "version": "0.0.1", + "description": "Inula chrome dev extension", + "main": "", + "scripts": { + "build": "webpack --config ./webpack.config.js", + "watch": "webpack --config ./webpack.config.js --watch", + "build-dev": "webpack --config ./webpack.dev.js", + "start": "npm run build && webpack serve --config ./webpack.dev.js", + "test": "jest" + }, + "keywords": ["inula-dev-tools"], + "license": "MulanPSL2", + "devDependencies": { + "@babel/core": "^7.12.3", + "@babel/plugin-proposal-class-properties": "^7.16.7", + "@babel/plugin-transform-react-jsx-source": "^7.18.6", + "@babel/preset-env": "^7.21.1", + "@babel/preset-react": "^7.12.1", + "@babel/preset-typescript": "^7.16.7", + "@types/chrome": "0.0.190", + "@types/jest": "27.4.1", + "@typescript-eslint/eslint-plugin": "4.8.0", + "@typescript-eslint/parser": "4.8.0", + "babel-jest": "^27.5.1", + "eslint": "7.13.0", + "eslint-config-prettier": "^6.9.0", + "eslint-plugin-jest": "^22.15.0", + "eslint-plugin-no-for-of-loops": "^1.0.0", + "eslint-plugin-no-function-declare-after-return": "^1.0.0", + "eslint-plugin-react": "7.14.3", + "babel-loader": "8.1.0", + "css-loader": "^6.7.1", + "html-webpack-plugin": "5.5.0", + "jest": "27.5.1", + "less": "4.1.2", + "less-loader": "10.2.0", + "style-loader": "^3.3.1", + "ts-jest": "27.1.4", + "ts-loader": "^9.3.1", + "typescript": "4.2.3", + "webpack": "5.70.0", + "webpack-cli": "4.9.2", + "webpack-dev-server": "^4.7.4" + }, + "dependencies": { + "openinula": "^0.0.1", + "flatted-object": "^0.1.2", + "json-decycle": "^2.0.1", + "lodash": "^4.17.21", + "object-assign": "^4.1.1" + } +} diff --git a/packages/inula-dev-tools/src/manifest.json b/packages/inula-dev-tools/src/manifest.json new file mode 100644 index 00000000..34c0f2b6 --- /dev/null +++ b/packages/inula-dev-tools/src/manifest.json @@ -0,0 +1,35 @@ +{ + "name": "Inula dev tools", + "description": "Inula chrome dev extension", + "version": "1.0", + "minimum_chrome_version": "10.0", + "manifest_version": 3, + "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'", + "background": { + "script": [ + "background.js" + ], + "persistent": true + }, + "permissions": [ + "file:///*", + "http://*/*", + "https://*/*" + ], + "devtools_page": "main.html", + "content_scripts": [ + { + "matches": [ + "" + ], + "js": [ + "contentScript.js" + ], + "run_at": "document_start" + } + ], + "web_accessible_resources": [ + "injector.js", + "background.js" + ] +} diff --git a/packages/inula-dev-tools/tsconfig.json b/packages/inula-dev-tools/tsconfig.json new file mode 100644 index 00000000..2e1cc0d6 --- /dev/null +++ b/packages/inula-dev-tools/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "outDir": "./dist", + "incremental": false, + "allowJs": true, + "strict": true, + "noImplicitAny": false, + "module": "es6", + "moduleResolution": "node", + "target": "es5", + "jsx": "preserve", + "allowSyntheticDefaultImports": true, + "lib": ["dom", "esnext", "ES2015", "ES2016", "ES2017", "ES2018", "ES2019", "ES2020"], + "baseUrl": "./", + "paths": { + "*": ["types/*"] + } + }, + "include": [ + "./src/*/*.ts", "./src/index.d.ts", "./src/*/*.tsx" + ] +} diff --git a/packages/inula-dev-tools/webpack.config.js b/packages/inula-dev-tools/webpack.config.js new file mode 100644 index 00000000..0e23a1b0 --- /dev/null +++ b/packages/inula-dev-tools/webpack.config.js @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2023 Huawei Technologies Co.,Ltd. + * + * openInula is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +import path from 'path'; +import webpack from 'webpack'; +import fs from 'fs'; + +function handleBuildDir() { + const staticDir = path.join(__dirname, 'build'); + console.log('staticDir: ', staticDir); + const isBuildExist = fs.existsSync(staticDir); + console.log('isBuildExist: ', isBuildExist); + + if (!isBuildExist) { + fs.mkdirSync(staticDir); + } + fs.copyFileSync( + path.join(__dirname, 'src', 'panel', 'panel.html'), + path.join(staticDir, 'panel.html') + ); + fs.copyFileSync( + path.join(__dirname, 'src', 'panelX', 'panel.html'), + path.join(staticDir, 'panelX.html') + ); + fs.copyFileSync( + path.join(__dirname, 'src', 'main', 'main.html'), + path.join(staticDir, 'main.html') + ); + fs.copyFileSync( + path.join(__dirname, 'src', 'manifest.json'), + path.join(staticDir, 'manifest.json') + ); + fs.copyFileSync( + path.join( + __dirname, + '../inula/build/umd', + 'inula.development.js' + ), + path.join(staticDir, 'inula.development.js') + ); +} + +handleBuildDir(); + +const config = { + entry: { + background: './src/background/index.ts', + main: './src/main/index.ts', + injector: './src/injector/index.ts', + contentScript: './sec/contentScript/index.ts', + panel: './src/panel/index.ts', + panelX: './src/panelX/index.ts', + }, + output: { + path: path.resolve(__dirname, './build'), + filename: '[name].js' + }, + mode: 'development', + devtool: 'inline-source-map', + module: { + rules: [ + { + test: /(\.ts)|(\.tsx)$/, + exclude: function (path) { + return /node_modules/.test(path) && !/inula/.test(path); + }, + use: [ + { + loader: 'babel-loader', + }, + ], + }, + { + test: /\.less/i, + use: [ + 'style-loader', + { + loader: 'css-loader', + options: { + modules: true, + }, + }, + 'less-loader', + ], + }, + ], + }, + resolve: { + extensions: ['.js', '.ts', 'tsx'], + }, + externals: { + openinula: 'Inula', + }, + plugins: [ + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': '"development"', + isDev: 'false', + }), + ], +}; + +module.exports = config; diff --git a/packages/inula-dev-tools/webpack.dev.js b/packages/inula-dev-tools/webpack.dev.js new file mode 100644 index 00000000..99cc835a --- /dev/null +++ b/packages/inula-dev-tools/webpack.dev.js @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023 Huawei Technologies Co.,Ltd. + * + * openInula is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +import path from 'path'; +import webpack from 'webpack'; + +// 用于 panel 页面开发 +module.exports = { + entry: { + panel: './src/panel/index.tsx', + mockPage: './src/devtools/mockPage/index.tsx', + }, + output: { + path: path.resolve(__dirname, './dist'), + filename: '[name].js' + }, + mode: 'development', + devtool: 'source-map', + module: { + rules: [ + { + test: /\.tsx?$/, + exclude: /node_modules/, + use: [ + { + loader: 'babel-loader', + }, + ], + }, + { + test: /\.less/i, + use: [ + 'style-loader', + { + loader: 'css-loader', + options: { + modules: true, + }, + }, + 'less-loader', + ], + }, + ], + }, + resolve: { + extensions: ['.js', '.ts', 'tsx'], + }, + externals: { + openinula: 'Inula', + }, + plugins: [ + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': '"development"', + isDev: 'true', + }), + ], + devServer: { + static: { + directory: path.join(__dirname, 'build'), + }, + open: 'panel.html', + port: 9000, + magicHtml: true, + } +};