Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
build(script): start dev use common script
Dushusir58bbbd4c2950
diff --git a/.github/contributing-zh.md b/.github/contributing-zh.mdindex 4ce5d52a9d..de45d06492 100644--- a/.github/contributing-zh.md+++ b/.github/contributing-zh.md@@ -64,6 +64,7 @@ npm run api```shnpm run clean```+PS: 如果失败请重新clean一下## 脚本diff --git a/examples/univer-sheet-ts/scripts/build.ts b/examples/univer-sheet-ts/scripts/build.tsindex 7f04fa2c71..4702a6295b 100644--- a/examples/univer-sheet-ts/scripts/build.ts+++ b/examples/univer-sheet-ts/scripts/build.ts@@ -1,7 +1,7 @@// scripts/build.ts-import { build } from "esbuild";-import { promises } from "fs";-import { commonBuildOptions, hasFolder, paths } from "./common";+import { build } from 'esbuild';+import { promises } from 'fs';+import { commonBuildOptions, hasFolder, paths } from './common';if (hasFolder(paths.outDev)) {promises.rm(paths.out, { recursive: true });@@ -10,7 +10,7 @@ if (hasFolder(paths.outDev)) {build({...commonBuildOptions,outdir: paths.out,- define: { ["process.env.NODE_ENV"]: '"production"' },+ define: { 'process.env.NODE_ENV': '"production"' },format: 'iife',globalName: 'UniverCore',// minify: true,@@ -19,4 +19,4 @@ build({sourcemap: false,}).then(() => {promises.copyFile(paths.index, `${paths.out}/index.html`);-});\ No newline at end of file+});diff --git a/examples/univer-sheet-ts/scripts/common.ts b/examples/univer-sheet-ts/scripts/common.tsindex c468bd3ab9..fb2230193a 100644--- a/examples/univer-sheet-ts/scripts/common.ts+++ b/examples/univer-sheet-ts/scripts/common.ts@@ -1,55 +1,52 @@// scripts/common.ts-import { BuildOptions } from "esbuild";-import stylePlugin from 'esbuild-style-plugin'-import path, { resolve } from "path";-import { existsSync, lstatSync } from "fs";+import { BuildOptions } from 'esbuild';+import stylePlugin from 'esbuild-style-plugin';+import { resolve, join } from 'path';+import { existsSync, lstatSync } from 'fs';++// resolve(__dirname, `../packages/${target}/src/index.ts`)const root = process.cwd();export const paths = {- entry: resolve(root, "./src/main.tsx"),- // cssEntry: resolve(root, "./src/index.css"),- index: resolve(root, "./public/index.html"),- out: resolve(root, "./dist"),- outDev: resolve(root, "./local"),+ entry: resolve(root, './src/main.tsx'),+ // cssEntry: resolve(root, "./src/index.css"),+ index: resolve(root, './public/index.html'),+ out: resolve(root, './dist'),+ outDev: resolve(root, './local'),};const preactCompatPlugin = {- name: "preact-compat",- setup(build) {- const path = require("path");- const preact = path.join(process.cwd(), "node_modules", "preact", "compat", "dist", "compat.module.js");+ name: 'preact-compat',+ setup(build) {+ const preact = join(process.cwd(), 'node_modules', 'preact', 'compat', 'dist', 'compat.module.js');- build.onResolve({filter: /^(react-dom|react)$/}, args => {- return {path: preact};- });- }-}+ build.onResolve({ filter: /^(react-dom|react)$/ }, (args) => ({ path: preact }));+ },+};export const commonBuildOptions: BuildOptions = {- entryPoints: [paths.entry],- bundle: true,- color: true,- loader: {- ".svg": "file",- },- sourcemap: true,- plugins: [- preactCompatPlugin,- stylePlugin({- cssModulesOptions: {- localsConvention: 'camelCaseOnly',- generateScopedName: 'univer-[local]',- }- })- ]+ entryPoints: [paths.entry],+ bundle: true,+ color: true,+ loader: {+ '.svg': 'file',+ },+ sourcemap: true,+ plugins: [+ preactCompatPlugin,+ stylePlugin({+ cssModulesOptions: {+ localsConvention: 'camelCaseOnly',+ generateScopedName: 'univer-[local]',+ },+ }),+ ],};export function hasFolder(target) {-- if (existsSync(target)) {- if (lstatSync(target).isDirectory()) {- return true+ if (existsSync(target)) {+ if (lstatSync(target).isDirectory()) {+ return true;+ }}- }- return false--}\ No newline at end of file+ return false;+}diff --git a/examples/univer-sheet-ts/scripts/start.ts b/examples/univer-sheet-ts/scripts/start.tsindex 6a08bec078..7a54a8295a 100644--- a/examples/univer-sheet-ts/scripts/start.ts+++ b/examples/univer-sheet-ts/scripts/start.ts@@ -1,6 +1,7 @@import * as esbuild from 'esbuild';-import { commonBuildOptions, hasFolder, paths } from './common';import { promises } from 'fs';+import { exec } from 'child_process';+import { commonBuildOptions, hasFolder, paths } from './common';import { Bright, FgCyan, FgGreen, Reset } from './color';(async () => {@@ -26,6 +27,6 @@ import { Bright, FgCyan, FgGreen, Reset } from './color';console.log(`${Bright}${FgGreen}Local server: ${FgCyan}${url}${Reset}`);- var start = process.platform == 'darwin' ? 'open' : process.platform == 'win32' ? 'start' : 'xdg-open';- require('child_process').exec(start + ' ' + url);+ let start = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open';+ exec(`${start} ${url}`);})();diff --git a/package.json b/package.jsonindex 678ce00bea..438913beae 100644--- a/package.json+++ b/package.json@@ -9,6 +9,7 @@"dev": "node scripts/dev","dev:sheet": "pnpm run --filter univer-sheet-ts dev","start:sheet": "pnpm run --filter univer-sheet-ts start",+ "start:sheets": "node scripts/start","dev:all": "pnpm run --filter univer-vanilla-ts dev","dev:preact": "pnpm run --filter univer-sheet-preact dev","dev:doc": "pnpm run --filter univer-doc-ts dev",@@ -50,6 +51,8 @@"@typescript-eslint/eslint-plugin": "^5.54.0","@typescript-eslint/parser": "^5.54.0","cross-env": "^7.0.3",+ "esbuild": "^0.18.11",+ "esbuild-style-plugin": "^1.6.1","eslint": "^8.35.0","eslint-config-airbnb-base": "^15.0.0","eslint-config-airbnb-typescript": "^17.0.0",@@ -64,20 +67,19 @@"jest": "29.0.0","lighthouse": "^9.4.0","lint-staged": "^13.0.3",+ "minimist": "^1.2.8","nodemon": "^2.0.3","prettier": "^2.3.2","rimraf": "^3.0.2","tree-kill": "^1.2.2","ts-jest": "29.0.1","ts-node": "^10.9.1",- "tsc-files": "^1.1.3","typescript": "^4.4.1-rc"},"lint-staged": {"packages/**/src/**/*.ts?(x)": ["eslint --fix"- ],- "**/*.ts": "tsc-files --noEmit"+ ]},"dependencies": {"pnpm": "^8.6.4"diff --git a/packages/sheets-plugin-operation/src/Domain/Paste.ts b/packages/sheets-plugin-operation/src/Domain/Paste.tsindex a130c311b2..f9abeb2310 100644--- a/packages/sheets-plugin-operation/src/Domain/Paste.ts+++ b/packages/sheets-plugin-operation/src/Domain/Paste.ts@@ -1,4 +1,4 @@-import { SelectionControl } from '@univerjs/base-sheets/src/Controller/Selection/SelectionController';+import { SelectionControl, ISetSelectionValueActionData, SelectionModel, SetSelectionValueAction, SheetPlugin } from '@univerjs/base-sheets';import {SheetContext,PLUGIN_NAMES,@@ -19,7 +19,6 @@ import {DEFAULT_SELECTION,DEFAULT_CELL,} from '@univerjs/core';-import { ISetSelectionValueActionData, SelectionModel, SetSelectionValueAction, SheetPlugin } from '@univerjs/base-sheets';import { handleTableMergeData, Prompt } from '@univerjs/base-ui';import { RightMenuProps, SheetUIPlugin, SHEET_UI_PLUGIN_NAME } from '@univerjs/ui-plugin-sheets';diff --git a/scripts/build.js b/scripts/build.jsindex 52b0f7af6a..6dc81cad34 100644--- a/scripts/build.js+++ b/scripts/build.js@@ -64,3 +64,26 @@ async function runParallel(maxConcurrency, source, iteratorFn) {async function build(target) {await execa('pnpm', ['run', '--filter', target, 'build'], { stdio: 'inherit' });}++// // scripts/build.ts+// import { build } from 'esbuild';+// import { promises } from 'fs';+// import { commonBuildOptions, hasFolder, paths } from './common';++// if (hasFolder(paths.outDev)) {+// promises.rm(paths.out, { recursive: true });+// }++// build({+// ...commonBuildOptions,+// outdir: paths.out,+// define: { 'process.env.NODE_ENV': '"production"' },+// format: 'iife',+// globalName: 'UniverCore',+// // minify: true,+// // outExtension:{'.js':'.cjs'}, // esm => .js, cjs => .cjs, iife => .iife.js+// packages: 'external',+// sourcemap: false,+// }).then(() => {+// promises.copyFile(paths.index, `${paths.out}/index.html`);+// });diff --git a/scripts/color.js b/scripts/color.jsnew file mode 100644index 0000000000..053712cb75--- /dev/null+++ b/scripts/color.js@@ -0,0 +1,27 @@+// colors reference of text to command when running node.js application+// https://stackoverflow.com/a/41407246+exports.Reset = '\x1b[0m';+exports.Bright = '\x1b[1m';+exports.Dim = '\x1b[2m';+exports.Underscore = '\x1b[4m';+exports.Blink = '\x1b[5m';+exports.Reverse = '\x1b[7m';+exports.Hidden = '\x1b[8m';++exports.FgBlack = '\x1b[30m';+exports.FgRed = '\x1b[31m';+exports.FgGreen = '\x1b[32m';+exports.FgYellow = '\x1b[33m';+exports.FgBlue = '\x1b[34m';+exports.FgMagenta = '\x1b[35m';+exports.FgCyan = '\x1b[36m';+exports.FgWhite = '\x1b[37m';++exports.BgBlack = '\x1b[40m';+exports.BgRed = '\x1b[41m';+exports.BgGreen = '\x1b[42m';+exports.BgYellow = '\x1b[43m';+exports.BgBlue = '\x1b[44m';+exports.BgMagenta = '\x1b[45m';+exports.BgCyan = '\x1b[46m';+exports.BgWhite = '\x1b[47m';diff --git a/scripts/common.js b/scripts/common.jsnew file mode 100644index 0000000000..82b664acea--- /dev/null+++ b/scripts/common.js@@ -0,0 +1,59 @@+// scripts/common.ts+// import stylePlugin from 'esbuild-style-plugin';+// import { resolve, join } from 'path';+// import { existsSync, lstatSync } from 'fs';+const stylePlugin = require('esbuild-style-plugin');+const { resolve, join } = require('path');+const { existsSync, lstatSync } = require('fs');++// resolve(__dirname, `../packages/${target}/src/index.ts`)+// const root = process.cwd();+const paths = {+ entry: resolve(__dirname, '../examples/univer-sheet-ts/src/main.tsx'),+ // cssEntry: resolve(root, "./src/index.css"),+ index: resolve(__dirname, '../examples/univer-sheet-ts/public/index.html'),+ out: resolve(__dirname, '../examples/univer-sheet-ts/dist'),+ outDev: resolve(__dirname, '../examples/univer-sheet-ts/local'),+};++const preactCompatPlugin = {+ name: 'preact-compat',+ setup(build) {+ // const preact = join(process.cwd(), 'node_modules', 'preact', 'compat', 'dist', 'compat.module.js');+ const preact = join(process.cwd(), 'node_modules', '.pnpm', '[email protected]', 'node_modules', 'preact', 'compat', 'dist', 'compat.module.js');++ build.onResolve({ filter: /^(react-dom|react)$/ }, (args) => ({ path: preact }));+ },+};++const commonBuildOptions = {+ entryPoints: [paths.entry],+ bundle: true,+ color: true,+ loader: {+ '.svg': 'file',+ },+ sourcemap: true,+ plugins: [+ preactCompatPlugin,+ stylePlugin({+ cssModulesOptions: {+ localsConvention: 'camelCaseOnly',+ generateScopedName: 'univer-[local]',+ },+ }),+ ],+};++function hasFolder(target) {+ if (existsSync(target)) {+ if (lstatSync(target).isDirectory()) {+ return true;+ }+ }+ return false;+}++exports.paths = paths;+exports.commonBuildOptions = commonBuildOptions;+exports.hasFolder = hasFolder;diff --git a/scripts/start.js b/scripts/start.jsnew file mode 100644index 0000000000..1e86e4fbd8--- /dev/null+++ b/scripts/start.js@@ -0,0 +1,42 @@+// import * as esbuild from 'esbuild';+// import { promises } from 'fs';+// import { exec } from 'child_process';+// import minimist from 'minimist';+// import { commonBuildOptions, hasFolder, paths } from './common';+// import { Bright, FgCyan, FgGreen, Reset } from './color';+const esbuild = require('esbuild');+const { promises } = require('fs');+const { exec } = require('child_process');+const minimist = require('minimist');+const { commonBuildOptions, hasFolder, paths } = require('./common');+const { Bright, FgCyan, FgGreen, Reset } = require('./color');++(async () => {+ const args = minimist(process.argv.slice(2));+ const target = args.t;+ console.info('target====', target, paths);+ if (hasFolder(paths.outDev)) {+ await promises.rm(paths.outDev, { recursive: true });+ }+ await promises.mkdir(paths.outDev);+ await promises.copyFile(paths.index, `${paths.outDev}/index.html`);++ let ctx = await esbuild.context({+ ...commonBuildOptions,+ outdir: paths.outDev,+ });++ await ctx.watch();++ let { host, port } = await ctx.serve({+ servedir: paths.outDev,+ port: 3002,+ });++ let url = `http://localhost:${port}`;++ console.log(`${Bright}${FgGreen}Local server: ${FgCyan}${url}${Reset}`);++ let start = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open';+ exec(`${start} ${url}`);+})();