浏览代码

feat: Auto release @excalidraw/excalidraw-next on every change (#3614)

* feat: Auto release @excalidraw/excalidraw-next on every change

* fix

* fix name

* fix

* add logs

* use commithash

* yarn installå

* fix

* catch

* log

* fix

* uncomment

* remove console

* add logs

* list files changed between prev and current commit

* fetch last two commits

* remove logs

* fix

* update readme_next

* update readme before release

* temp commit to trigger release

* update package name to excalidraw-next

* bold

* remove temp branch

* add note about next

* fix

* fix

* fix
vanilla_orig
Aakansha Doshi 4 年前
父节点
当前提交
5662c5141d
没有帐户链接到提交者的电子邮件

+ 26
- 0
.github/workflows/autorelease-excalidraw.yml 查看文件

@@ -0,0 +1,26 @@
1
+name: Auto release @excalidraw/excalidraw-next
2
+on:
3
+  push:
4
+    branches:
5
+      - master
6
+
7
+jobs:
8
+  Auto-release-excalidraw-next:
9
+    runs-on: ubuntu-latest
10
+
11
+    steps:
12
+      - uses: actions/checkout@v2
13
+        with:
14
+          fetch-depth: 2
15
+      - name: Setup Node.js 14.x
16
+        uses: actions/setup-node@v2
17
+        with:
18
+          node-version: 14.x
19
+      - name: Set up publish access
20
+        run: |
21
+          npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
22
+        env:
23
+          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
24
+      - name: Auto release
25
+        run: |
26
+          yarn autorelease

+ 2
- 1
package.json 查看文件

@@ -104,6 +104,7 @@
104 104
     "test:other": "yarn prettier --list-different",
105 105
     "test:typecheck": "tsc",
106 106
     "test:update": "yarn test:app --updateSnapshot --watchAll=false",
107
-    "test": "yarn test:app"
107
+    "test": "yarn test:app",
108
+    "autorelease": "node scripts/autorelease.js"
108 109
   }
109 110
 }

+ 51
- 0
scripts/autorelease.js 查看文件

@@ -0,0 +1,51 @@
1
+const fs = require("fs");
2
+const { exec, execSync } = require("child_process");
3
+
4
+const excalidrawDir = `${__dirname}/../src/packages/excalidraw`;
5
+const excalidrawPackage = `${excalidrawDir}/package.json`;
6
+const pkg = require(excalidrawPackage);
7
+
8
+const getShortCommitHash = () => {
9
+  return execSync("git rev-parse --short HEAD").toString().trim();
10
+};
11
+
12
+const publish = () => {
13
+  try {
14
+    execSync(`yarn  --frozen-lockfile`);
15
+    execSync(`yarn --frozen-lockfile`, { cwd: excalidrawDir });
16
+    execSync(`yarn run build:umd`, { cwd: excalidrawDir });
17
+    execSync(`yarn --cwd ${excalidrawDir} publish`);
18
+  } catch (e) {
19
+    console.error(e);
20
+  }
21
+};
22
+
23
+// get files changed between prev and head commit
24
+exec(`git diff --name-only HEAD^ HEAD`, async (error, stdout, stderr) => {
25
+  if (error || stderr) {
26
+    console.error(error);
27
+    process.exit(1);
28
+  }
29
+
30
+  const changedFiles = stdout.trim().split("\n");
31
+  const filesToIgnoreRegex = /src\/excalidraw-app|packages\/utils/;
32
+
33
+  const excalidrawPackageFiles = changedFiles.filter((file) => {
34
+    return file.indexOf("src") >= 0 && !filesToIgnoreRegex.test(file);
35
+  });
36
+
37
+  if (!excalidrawPackageFiles.length) {
38
+    process.exit(0);
39
+  }
40
+
41
+  // update package.json
42
+  pkg.version = `${pkg.version}-${getShortCommitHash()}`;
43
+  pkg.name = "@excalidraw/excalidraw-next";
44
+  fs.writeFileSync(excalidrawPackage, JSON.stringify(pkg, null, 2), "utf8");
45
+
46
+  // update readme
47
+  const data = fs.readFileSync(`${excalidrawDir}/README_NEXT.md`, "utf8");
48
+  fs.writeFileSync(`${excalidrawDir}/README.md`, data, "utf8");
49
+
50
+  publish();
51
+});

+ 4
- 0
src/packages/excalidraw/README.md 查看文件

@@ -24,6 +24,10 @@ By default it will try to load the files from `https://unpkg.com/@excalidraw/exc
24 24
 
25 25
 If you want to load assets from a different path you can set a variable `window.EXCALIDRAW_ASSET_PATH` depending on environment (for example if you have different URL's for dev and prod) to the url from where you want to load the assets.
26 26
 
27
+#### Note
28
+
29
+**If you don't want to wait for the next stable release and try out the unreleased changes you can use [@excalidraw/excalidraw-next](https://www.npmjs.com/package/@excalidraw/excalidraw-next).**
30
+
27 31
 ### Demo
28 32
 
29 33
 [Try here](https://codesandbox.io/s/excalidraw-ehlz3).

+ 28
- 18
src/packages/excalidraw/README_NEXT.md 查看文件

@@ -1,3 +1,13 @@
1
+<!-- stable-readme-start-->
2
+
3
+## Note
4
+
5
+**This is an unstable release and not recommended for production. If you don't want to wait for the stable release and try out the unreleased changes you can use this.**
6
+
7
+For stable release please use [@excalidraw/excalidraw](https://www.npmjs.com/package/@excalidraw/excalidraw).
8
+
9
+<!-- stable-readme-end-->
10
+
1 11
 ### Excalidraw
2 12
 
3 13
 Excalidraw exported as a component to directly embed in your projects.
@@ -7,20 +17,20 @@ Excalidraw exported as a component to directly embed in your projects.
7 17
 You can use npm
8 18
 
9 19
 ```
10
-npm install react react-dom @excalidraw/excalidraw
20
+npm install react react-dom @excalidraw/excalidraw-next
11 21
 ```
12 22
 
13 23
 or via yarn
14 24
 
15 25
 ```
16
-yarn add react react-dom @excalidraw/excalidraw
26
+yarn add react react-dom @excalidraw/excalidraw-next
17 27
 ```
18 28
 
19 29
 After installation you will see a folder `excalidraw-assets` and `excalidraw-assets-dev` in `dist` directory which contains the assets needed for this app in prod and dev mode respectively.
20 30
 
21 31
 Move the folder `excalidraw-assets` and `excalidraw-assets-dev` to the path where your assets are served.
22 32
 
23
-By default it will try to load the files from `https://unpkg.com/@excalidraw/excalidraw/{currentVersion}/dist/`
33
+By default it will try to load the files from `https://unpkg.com/@excalidraw/excalidraw-next/dist/`
24 34
 
25 35
 If you want to load assets from a different path you can set a variable `window.EXCALIDRAW_ASSET_PATH` depending on environment (for example if you have different URL's for dev and prod) to the url from where you want to load the assets.
26 36
 
@@ -38,7 +48,7 @@ If you are using a Web bundler (for instance, Webpack), you can import it as an
38 48
 
39 49
 ```js
40 50
 import React, { useEffect, useState, useRef } from "react";
41
-import Excalidraw from "@excalidraw/excalidraw";
51
+import Excalidraw from "@excalidraw/excalidraw-next";
42 52
 import InitialData from "./initialData";
43 53
 
44 54
 import "./styles.scss";
@@ -156,13 +166,13 @@ import { useState, useEffect } from "react";
156 166
 export default function IndexPage() {
157 167
   const [Comp, setComp] = useState(null);
158 168
   useEffect(() => {
159
-    import("@excalidraw/excalidraw").then((comp) => setComp(comp.default));
169
+    import("@excalidraw/excalidraw-next").then((comp) => setComp(comp.default));
160 170
   });
161 171
   return <>{Comp && <Comp />}</>;
162 172
 }
163 173
 ```
164 174
 
165
-The `types` are available at `@excalidraw/excalidraw/types`, you can view [example for typescript](https://codesandbox.io/s/excalidraw-types-9h2dm)
175
+The `types` are available at `@excalidraw/excalidraw-next/types`, you can view [example for typescript](https://codesandbox.io/s/excalidraw-types-9h2dm)
166 176
 
167 177
 #### In Browser
168 178
 
@@ -173,7 +183,7 @@ For development use :point_down:
173 183
 ```js
174 184
 <script
175 185
   type="text/javascript"
176
-  src="https://unpkg.com/@excalidraw/excalidraw@0.8.0/dist/excalidraw.development.js"
186
+  src="https://unpkg.com/@excalidraw/excalidraw-next/dist/excalidraw.development.js"
177 187
 ></script>
178 188
 ```
179 189
 
@@ -182,7 +192,7 @@ For production use :point_down:
182 192
 ```js
183 193
 <script
184 194
   type="text/javascript"
185
-  src="https://unpkg.com/@excalidraw/excalidraw@0.8.0/dist/excalidraw.production.min.js"
195
+  src="https://unpkg.com/@excalidraw/excalidraw-next/dist/excalidraw.production.min.js"
186 196
 ></script>
187 197
 ```
188 198
 
@@ -201,7 +211,7 @@ You will need to make sure `react`, `react-dom` is available as shown in the bel
201 211
 
202 212
     <script
203 213
       type="text/javascript"
204
-      src="https://unpkg.com/@excalidraw/excalidraw@0.8.0/dist/excalidraw.development.js"
214
+      src="https://unpkg.com/@excalidraw/excalidraw-next/dist/excalidraw.development.js"
205 215
     ></script>
206 216
   </head>
207 217
 
@@ -495,7 +505,7 @@ This callback is triggered when the shareable-link button is clicked in the expo
495 505
 Determines the language of the UI. It should be one of the [available language codes](https://github.com/excalidraw/excalidraw/blob/master/src/i18n.ts#L14). Defaults to `en` (English). We also export default language and supported languages which you can import as shown below.
496 506
 
497 507
 ```js
498
-import { defaultLang, languages } from "@excalidraw/excalidraw";
508
+import { defaultLang, languages } from "@excalidraw/excalidraw-next";
499 509
 ```
500 510
 
501 511
 | name | type |
@@ -636,7 +646,7 @@ The unique id of the excalidraw component. This can be used to identify the exca
636 646
 **How to use**
637 647
 
638 648
 <pre>
639
-import { getSceneVersion } from "@excalidraw/excalidraw";
649
+import { getSceneVersion } from "@excalidraw/excalidraw-next";
640 650
 getSceneVersion(elements:  <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement[]</a>)
641 651
 </pre>
642 652
 
@@ -653,7 +663,7 @@ isInvisiblySmallElement(element:  <a href="https://github.com/excalidraw/excalid
653 663
 **How to use**
654 664
 
655 665
 ```js
656
-import { isInvisiblySmallElement } from "@excalidraw/excalidraw";
666
+import { isInvisiblySmallElement } from "@excalidraw/excalidraw-next";
657 667
 ```
658 668
 
659 669
 Returns `true` if element is invisibly small (e.g. width & height are zero).
@@ -669,7 +679,7 @@ getElementsMap(elements:  <a href="https://github.com/excalidraw/excalidraw/blob
669 679
 **How to use**
670 680
 
671 681
 ```js
672
-import { getElementsMap } from "@excalidraw/excalidraw";
682
+import { getElementsMap } from "@excalidraw/excalidraw-next";
673 683
 ```
674 684
 
675 685
 This function returns an object where each element is mapped to its id.
@@ -687,7 +697,7 @@ restoreAppState(appState:  <a href="https://github.com/excalidraw/excalidraw/blo
687 697
 **_How to use_**
688 698
 
689 699
 ```js
690
-import { restoreAppState } from "@excalidraw/excalidraw";
700
+import { restoreAppState } from "@excalidraw/excalidraw-next";
691 701
 ```
692 702
 
693 703
 This function will make sure all the keys have appropriate values in [appState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L42) and if any key is missing, it will be set to default value. If you pass `localAppState`, `localAppState` value will be preferred over the `appState` passed in params.
@@ -703,7 +713,7 @@ restoreElements(elements:  <a href="https://github.com/excalidraw/excalidraw/blo
703 713
 **_How to use_**
704 714
 
705 715
 ```js
706
-import { restoreElements } from "@excalidraw/excalidraw";
716
+import { restoreElements } from "@excalidraw/excalidraw-next";
707 717
 ```
708 718
 
709 719
 This function will make sure all properties of element is correctly set and if any attribute is missing, it will be set to default value.
@@ -719,7 +729,7 @@ restoreElements(data:  <a href="https://github.com/excalidraw/excalidraw/blob/ma
719 729
 **_How to use_**
720 730
 
721 731
 ```js
722
-import { restore } from "@excalidraw/excalidraw";
732
+import { restore } from "@excalidraw/excalidraw-next";
723 733
 ```
724 734
 
725 735
 This function makes sure elements and state is set to appropriate values and set to default value if not present. It is combination of [restoreElements](#restoreElements) and [restoreAppState](#restoreAppState)
@@ -760,7 +770,7 @@ Takes the scene elements and state and returns a JSON string. Deleted `elements`
760 770
 **How to use**
761 771
 
762 772
 ```js
763
-import { exportToCanvas } from "@excalidraw/excalidraw";
773
+import { exportToCanvas } from "@excalidraw/excalidraw-next";
764 774
 ```
765 775
 
766 776
 This function returns the canvas with the exported elements, appState and dimensions.
@@ -786,7 +796,7 @@ exportToBlob(
786 796
 **How to use**
787 797
 
788 798
 ```js
789
-import { exportToBlob } from "@excalidraw/excalidraw";
799
+import { exportToBlob } from "@excalidraw/excalidraw-next";
790 800
 ```
791 801
 
792 802
 Returns a promise which resolves with a [blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob). It internally uses [canvas.ToBlob](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob).

正在加载...
取消
保存