Skip to content

Commit 05bff0b

Browse files
committed
add npm plugins
1 parent 9fa454a commit 05bff0b

File tree

167 files changed

+4774
-1649
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+4774
-1649
lines changed

client/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export default {
2-
projects: ["<rootDir>/packages/*"],
2+
projects: ["<rootDir>/packages/openblocks", "<rootDir>/packages/openblocks-core"],
33
};

client/packages/create-openblocks-comps/README.md

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# create-openblocks-plugin
2+
3+
## Usage
4+
5+
```bash
6+
yarn create openblocks-plugin my-openblocks-plugin
7+
8+
# or
9+
10+
npm create openblocks-plugin my-openblocks-plugin
11+
```

client/packages/create-openblocks-comps/index.js renamed to client/packages/create-openblocks-plugin/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,11 @@ async function createProject(projectName, options) {
129129
await install([
130130
cliPackageName,
131131
sdkPackageName,
132-
"openblocks-design",
133-
"openblocks-core",
134132
"react@17",
135133
"react-dom@17",
136134
"@types/react@17",
137135
"@types/react-dom@17",
136+
"vite",
138137
]);
139138

140139
await executeNodeScript(
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
{
2-
"name": "create-openblocks-comps",
3-
"version": "0.0.7",
2+
"name": "create-openblocks-plugin",
3+
"version": "0.0.2",
44
"bin": "./index.js",
55
"type": "module",
66
"dependencies": {
77
"chalk": "4",
88
"commander": "^9.4.1",
99
"fs-extra": "^10.1.0",
1010
"openblocks-dev-utils": "workspace:^"
11-
}
11+
},
12+
"license": "MIT",
13+
"keywords": [
14+
"openblocks"
15+
]
1216
}
Lines changed: 10 additions & 0 deletions
Loading
Binary file not shown.

client/packages/openblocks-cli-template-typescript/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openblocks-cli-template-typescript",
3-
"version": "0.0.9",
3+
"version": "0.0.11",
44
"type": "module",
55
"scripts": {
66
"start": "vite",
@@ -11,7 +11,7 @@
1111
"comps": {
1212
"hello_world": {
1313
"name": "__i18n_helloWorldCompName__",
14-
"icon": "./icons/hello_world.png"
14+
"icon": "./icons/demo-icon.png"
1515
}
1616
}
1717
},
@@ -21,5 +21,8 @@
2121
"typescript": "^4.8.4",
2222
"vite": "^3.2.4"
2323
},
24+
"keywords": [
25+
"openblocks"
26+
],
2427
"license": "MIT"
2528
}

client/packages/openblocks-cli-template-typescript/src/HelloWorldComp.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
withMethodExposing,
1212
} from "openblocks-sdk";
1313

14+
import styles from "./styles.module.css";
15+
1416
const { Button } = antd;
1517

1618
const childrenMap = {
@@ -25,10 +27,10 @@ const childrenMap = {
2527
]),
2628
};
2729

28-
const HelloWorldCompBase = new UICompBuilder(childrenMap, (props) => {
30+
const HelloWorldCompBase = new UICompBuilder(childrenMap, (props: any) => {
2931
const currentValue = props.value.value;
3032
return (
31-
<div>
33+
<div className={styles.wrapper}>
3234
<Button
3335
onClick={() => {
3436
props.value.onChange(currentValue - props.step);
@@ -49,7 +51,7 @@ const HelloWorldCompBase = new UICompBuilder(childrenMap, (props) => {
4951
</div>
5052
);
5153
})
52-
.setPropertyViewFn((children) => {
54+
.setPropertyViewFn((children: any) => {
5355
return (
5456
<>
5557
<Section name="Basic">
@@ -68,7 +70,7 @@ const HelloWorldCompTemp = withMethodExposing(HelloWorldCompBase, [
6870
name: "random",
6971
params: [],
7072
},
71-
execute(comp) {
73+
execute(comp: any) {
7274
comp.children.value.getView().onChange(Math.floor(Math.random() * 100));
7375
},
7476
},
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/// <reference types="openblocks-cli/client" />
2+
3+
declare module "openblocks-sdk";
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.wrapper {
2+
padding: 5px;
3+
display: flex;
4+
justify-content: center;
5+
align-items: center;
6+
height: 100%;
7+
border: 1px solid #dddddd;
8+
background-color: white;
9+
}

client/packages/openblocks-cli-template-typescript/tsconfig.json

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,7 @@
1616
"isolatedModules": true,
1717
"noEmit": true,
1818
"jsx": "react-jsx",
19-
"baseUrl": "src",
20-
"paths": {
21-
"openblocks-sdk": [
22-
"../../openblocks/src/index.sdk.ts",
23-
"../node_modules/openblocks-sdk/src/openblocks/index.sdk.ts"
24-
],
25-
"*": [
26-
"*",
27-
"../../openblocks/src/*",
28-
"../../openblocks-sdk/src/*",
29-
"../node_modules/openblocks-sdk/src/openblocks/*"
30-
]
31-
}
19+
"baseUrl": "src"
3220
},
3321
"include": ["src", "index.tsx"]
3422
}

client/packages/openblocks-cli/actions/build.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,21 @@ export default async function buildAction(options) {
9191
copySync(paths.resolveApp(compManifest.icon), resolve(paths.appOutPath, compManifest.icon));
9292
});
9393

94-
// pack
95-
const tarOutPath = paths.resolveApp(outDir);
96-
execSync(`npm pack --pack-destination ${tarOutPath}`, {
97-
stdio: "ignore",
98-
cwd: paths.appOutPath,
99-
});
94+
if (options.publish) {
95+
// publish
96+
execSync("npm publish", {
97+
stdio: "inherit",
98+
cwd: paths.appOutPath,
99+
});
100+
} else {
101+
// pack
102+
const tarOutPath = paths.resolveApp(outDir);
103+
execSync(`npm pack --pack-destination ${tarOutPath}`, {
104+
stdio: "ignore",
105+
cwd: paths.appOutPath,
106+
});
100107

101-
console.green(`Package generated in: ${tarOutPath}`);
108+
console.green(`Package generated in: ${tarOutPath}`);
109+
}
102110
console.green(`Done in ${Math.round(performance.now() - beginTime)}ms!`);
103111
}

client/packages/openblocks-cli/config/vite.config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import react from "@vitejs/plugin-react";
22
import svgrPlugin from "vite-plugin-svgr";
3+
import global from "rollup-plugin-external-globals";
34
import { buildVars } from "openblocks-dev-utils/buildVars.js";
4-
import { getLibNames } from "openblocks-dev-utils/external.js";
5+
import injectCss from "vite-plugin-css-injected-by-js";
6+
import { getLibNames, getAllLibGlobalVarNames } from "openblocks-dev-utils/external.js";
57
import paths from "./paths.js";
68
import { defineConfig } from "vite";
9+
import { readJson } from "openblocks-dev-utils/util.js";
10+
11+
const isProduction = process.env.NODE_ENV === "production";
12+
const packageJson = readJson(paths.appPackageJson);
713

814
const define = {};
915
buildVars.forEach(({ name, defaultValue }) => {
@@ -13,6 +19,7 @@ buildVars.forEach(({ name, defaultValue }) => {
1319
export default defineConfig({
1420
define: {
1521
...define,
22+
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || "development"),
1623
__OPENBLOCKS_DEV__: JSON.stringify({}),
1724
},
1825
assetsInclude: ["**/*.md"],
@@ -53,5 +60,7 @@ export default defineConfig({
5360
ref: true,
5461
},
5562
}),
63+
isProduction && global(getAllLibGlobalVarNames(), { exclude: [/\.css$/] }),
64+
isProduction && injectCss({ styleId: `${packageJson.name}-${packageJson.version}` }),
5665
].filter(Boolean),
5766
});

client/packages/openblocks-cli/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ program
2222
.command("build")
2323
.description("build component lib")
2424
.option("--outDir", "where to place tar ball", "./")
25+
.option("--publish", "publish to npm", false)
2526
.action(buildAction);
2627

2728
program.parse();

client/packages/openblocks-cli/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "openblocks-cli",
33
"description": "CLI tool used to start build publish openblocks components",
4-
"version": "0.0.15",
4+
"version": "0.0.20",
55
"bin": "./index.js",
66
"type": "module",
77
"exports": {
@@ -31,7 +31,9 @@
3131
"react": "^17",
3232
"react-dom": "^17",
3333
"react-json-view": "^1.21.3",
34+
"rollup-plugin-external-globals": "^0.7.1",
3435
"vite": "^3.2.4",
36+
"vite-plugin-css-injected-by-js": "^2.1.1",
3537
"vite-plugin-svgr": "^2.2.2"
3638
},
3739
"devDependencies": {
@@ -40,5 +42,8 @@
4042
},
4143
"peerDependencies": {
4244
"openblocks-sdk": "*"
43-
}
45+
},
46+
"keywords": [
47+
"openblocks"
48+
]
4449
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/lib
2-
/node_modules
2+
/node_modules
3+
*.tgz
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# openblocks comp lib
2+
3+
## Start
4+
5+
Start dev server to develop your comp lib.
6+
7+
```bash
8+
yarn start
9+
10+
# or
11+
12+
npm start
13+
```
14+
15+
## Build
16+
17+
Build current comp lib into a .tgz file that you can upload it to the Openblocks Comp Market.
18+
19+
Before build you should change the version in package.json file.
20+
21+
```bash
22+
yarn build
23+
24+
# or
25+
26+
npm run build
27+
```

0 commit comments

Comments
 (0)