!39 [inula-dev-tools]<feat> inula-dev-tools 项目工程初始化

Merge pull request !39 from 涂旭辉/master
This commit is contained in:
涂旭辉 2023-10-13 07:17:06 +00:00 committed by Gitee
commit 31e77e25a1
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
9 changed files with 383 additions and 0 deletions

View File

View File

@ -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,
};
};

19
packages/inula-dev-tools/externals.d.ts vendored Normal file
View File

@ -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;
}

21
packages/inula-dev-tools/global.d.ts vendored Normal file
View File

@ -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;

View File

@ -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"
}
}

View File

@ -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": [
"<all_urls>"
],
"js": [
"contentScript.js"
],
"run_at": "document_start"
}
],
"web_accessible_resources": [
"injector.js",
"background.js"
]
}

View File

@ -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"
]
}

View File

@ -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;

View File

@ -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,
}
};