@sanity/cli-build 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @sanity/cli-build
2
+
3
+ Build utilities for Studio and App SDK.
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Copies a directory from one location to another
3
+ *
4
+ * @internal
5
+ *
6
+ * @param srcDir - Source directory
7
+ * @param destDir - Destination directory
8
+ * @param skipExisting - Skip existing files
9
+ */
10
+ export declare function copyDir(
11
+ srcDir: string,
12
+ destDir: string,
13
+ skipExisting?: boolean,
14
+ ): Promise<void>;
15
+
16
+ /**
17
+ * @internal
18
+ */
19
+ export declare function generateWebManifest(basePath: string): WebManifest;
20
+
21
+ /**
22
+ * @internal
23
+ */
24
+ export declare function getDefaultFaviconsPath(): Promise<string>;
25
+
26
+ /**
27
+ * @internal
28
+ */
29
+ declare interface WebManifest {
30
+ icons: {
31
+ sizes: string;
32
+ src: string;
33
+ type: string;
34
+ }[];
35
+ }
36
+
37
+ /**
38
+ * @internal
39
+ */
40
+ export declare function writeFavicons(
41
+ basePath: string,
42
+ destDir: string,
43
+ ): Promise<void>;
44
+
45
+ export {};
@@ -0,0 +1,5 @@
1
+ export * from '../actions/build/generateWebManifest.js';
2
+ export * from '../actions/build/writeFavicons.js';
3
+ export { copyDir } from '../util/copyDir.js';
4
+
5
+ //# sourceMappingURL=_internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/_exports/_internal.ts"],"sourcesContent":["export * from '../actions/build/generateWebManifest.js'\nexport * from '../actions/build/writeFavicons.js'\nexport {copyDir} from '../util/copyDir.js'\n"],"names":["copyDir"],"mappings":"AAAA,cAAc,0CAAyC;AACvD,cAAc,oCAAmC;AACjD,SAAQA,OAAO,QAAO,qBAAoB"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @internal
3
+ */ /**
4
+ * @internal
5
+ */ export function generateWebManifest(basePath) {
6
+ return {
7
+ icons: [
8
+ {
9
+ sizes: '96x96',
10
+ src: `${basePath}/favicon-96.png`,
11
+ type: 'image/png'
12
+ },
13
+ {
14
+ sizes: '192x192',
15
+ src: `${basePath}/favicon-192.png`,
16
+ type: 'image/png'
17
+ },
18
+ {
19
+ sizes: '512x512',
20
+ src: `${basePath}/favicon-512.png`,
21
+ type: 'image/png'
22
+ }
23
+ ]
24
+ };
25
+ }
26
+
27
+ //# sourceMappingURL=generateWebManifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/actions/build/generateWebManifest.ts"],"sourcesContent":["/**\n * @internal\n */\ninterface WebManifest {\n icons: {\n sizes: string\n src: string\n type: string\n }[]\n}\n\n/**\n * @internal\n */\nexport function generateWebManifest(basePath: string): WebManifest {\n return {\n icons: [\n {sizes: '96x96', src: `${basePath}/favicon-96.png`, type: 'image/png'},\n {sizes: '192x192', src: `${basePath}/favicon-192.png`, type: 'image/png'},\n {sizes: '512x512', src: `${basePath}/favicon-512.png`, type: 'image/png'},\n ],\n }\n}\n"],"names":["generateWebManifest","basePath","icons","sizes","src","type"],"mappings":"AAAA;;CAEC,GASD;;CAEC,GACD,OAAO,SAASA,oBAAoBC,QAAgB;IAClD,OAAO;QACLC,OAAO;YACL;gBAACC,OAAO;gBAASC,KAAK,GAAGH,SAAS,eAAe,CAAC;gBAAEI,MAAM;YAAW;YACrE;gBAACF,OAAO;gBAAWC,KAAK,GAAGH,SAAS,gBAAgB,CAAC;gBAAEI,MAAM;YAAW;YACxE;gBAACF,OAAO;gBAAWC,KAAK,GAAGH,SAAS,gBAAgB,CAAC;gBAAEI,MAAM;YAAW;SACzE;IACH;AACF"}
@@ -0,0 +1,31 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { readPackageUp } from 'read-package-up';
4
+ import { copyDir } from '../../util/copyDir.js';
5
+ import { writeWebManifest } from './writeWebManifest.js';
6
+ /**
7
+ * @internal
8
+ */ export async function getDefaultFaviconsPath() {
9
+ const sanityCliPkgPath = (await readPackageUp({
10
+ cwd: import.meta.dirname
11
+ }))?.path;
12
+ if (!sanityCliPkgPath) {
13
+ throw new Error('Unable to resolve `@sanity/cli-build` module root');
14
+ }
15
+ return path.join(path.dirname(sanityCliPkgPath), 'static', 'favicons');
16
+ }
17
+ /**
18
+ * @internal
19
+ */ export async function writeFavicons(basePath, destDir) {
20
+ const faviconsPath = await getDefaultFaviconsPath();
21
+ await fs.mkdir(destDir, {
22
+ recursive: true
23
+ });
24
+ await copyDir(faviconsPath, destDir, true);
25
+ await writeWebManifest(basePath, destDir);
26
+ // Copy the /static/favicon.ico to /favicon.ico as well, because some tools/browsers
27
+ // blindly expects it to be there before requesting the HTML containing the actual path
28
+ await fs.copyFile(path.join(destDir, 'favicon.ico'), path.join(destDir, '..', 'favicon.ico'));
29
+ }
30
+
31
+ //# sourceMappingURL=writeFavicons.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/actions/build/writeFavicons.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport {readPackageUp} from 'read-package-up'\n\nimport {copyDir} from '../../util/copyDir.js'\nimport {writeWebManifest} from './writeWebManifest.js'\n\n/**\n * @internal\n */\nexport async function getDefaultFaviconsPath(): Promise<string> {\n const sanityCliPkgPath = (await readPackageUp({cwd: import.meta.dirname}))?.path\n if (!sanityCliPkgPath) {\n throw new Error('Unable to resolve `@sanity/cli-build` module root')\n }\n\n return path.join(path.dirname(sanityCliPkgPath), 'static', 'favicons')\n}\n\n/**\n * @internal\n */\nexport async function writeFavicons(basePath: string, destDir: string): Promise<void> {\n const faviconsPath = await getDefaultFaviconsPath()\n\n await fs.mkdir(destDir, {recursive: true})\n await copyDir(faviconsPath, destDir, true)\n await writeWebManifest(basePath, destDir)\n\n // Copy the /static/favicon.ico to /favicon.ico as well, because some tools/browsers\n // blindly expects it to be there before requesting the HTML containing the actual path\n await fs.copyFile(path.join(destDir, 'favicon.ico'), path.join(destDir, '..', 'favicon.ico'))\n}\n"],"names":["fs","path","readPackageUp","copyDir","writeWebManifest","getDefaultFaviconsPath","sanityCliPkgPath","cwd","dirname","Error","join","writeFavicons","basePath","destDir","faviconsPath","mkdir","recursive","copyFile"],"mappings":"AAAA,OAAOA,QAAQ,mBAAkB;AACjC,OAAOC,UAAU,YAAW;AAE5B,SAAQC,aAAa,QAAO,kBAAiB;AAE7C,SAAQC,OAAO,QAAO,wBAAuB;AAC7C,SAAQC,gBAAgB,QAAO,wBAAuB;AAEtD;;CAEC,GACD,OAAO,eAAeC;IACpB,MAAMC,mBAAoB,CAAA,MAAMJ,cAAc;QAACK,KAAK,YAAYC,OAAO;IAAA,EAAC,GAAIP;IAC5E,IAAI,CAACK,kBAAkB;QACrB,MAAM,IAAIG,MAAM;IAClB;IAEA,OAAOR,KAAKS,IAAI,CAACT,KAAKO,OAAO,CAACF,mBAAmB,UAAU;AAC7D;AAEA;;CAEC,GACD,OAAO,eAAeK,cAAcC,QAAgB,EAAEC,OAAe;IACnE,MAAMC,eAAe,MAAMT;IAE3B,MAAML,GAAGe,KAAK,CAACF,SAAS;QAACG,WAAW;IAAI;IACxC,MAAMb,QAAQW,cAAcD,SAAS;IACrC,MAAMT,iBAAiBQ,UAAUC;IAEjC,oFAAoF;IACpF,uFAAuF;IACvF,MAAMb,GAAGiB,QAAQ,CAAChB,KAAKS,IAAI,CAACG,SAAS,gBAAgBZ,KAAKS,IAAI,CAACG,SAAS,MAAM;AAChF"}
@@ -0,0 +1,12 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { skipIfExistsError } from '../../util/copyDir.js';
4
+ import { generateWebManifest } from './generateWebManifest.js';
5
+ /**
6
+ * @internal
7
+ */ export async function writeWebManifest(basePath, destDir) {
8
+ const content = JSON.stringify(generateWebManifest(basePath), null, 2);
9
+ await fs.writeFile(path.join(destDir, 'manifest.webmanifest'), content, 'utf8').catch(skipIfExistsError);
10
+ }
11
+
12
+ //# sourceMappingURL=writeWebManifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/actions/build/writeWebManifest.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport {skipIfExistsError} from '../../util/copyDir.js'\nimport {generateWebManifest} from './generateWebManifest.js'\n\n/**\n * @internal\n */\nexport async function writeWebManifest(basePath: string, destDir: string): Promise<void> {\n const content = JSON.stringify(generateWebManifest(basePath), null, 2)\n await fs\n .writeFile(path.join(destDir, 'manifest.webmanifest'), content, 'utf8')\n .catch(skipIfExistsError)\n}\n"],"names":["fs","path","skipIfExistsError","generateWebManifest","writeWebManifest","basePath","destDir","content","JSON","stringify","writeFile","join","catch"],"mappings":"AAAA,OAAOA,QAAQ,mBAAkB;AACjC,OAAOC,UAAU,YAAW;AAE5B,SAAQC,iBAAiB,QAAO,wBAAuB;AACvD,SAAQC,mBAAmB,QAAO,2BAA0B;AAE5D;;CAEC,GACD,OAAO,eAAeC,iBAAiBC,QAAgB,EAAEC,OAAe;IACtE,MAAMC,UAAUC,KAAKC,SAAS,CAACN,oBAAoBE,WAAW,MAAM;IACpE,MAAML,GACHU,SAAS,CAACT,KAAKU,IAAI,CAACL,SAAS,yBAAyBC,SAAS,QAC/DK,KAAK,CAACV;AACX"}
@@ -0,0 +1,63 @@
1
+ import { constants as fsConstants } from 'node:fs';
2
+ import fs from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ /**
5
+ * Tries to read a directory, and returns an empty array if the directory does not exist
6
+ *
7
+ * @internal
8
+ *
9
+ * @param dir - Directory to read
10
+ * @returns List of files in the directory
11
+ */ async function tryReadDir(dir) {
12
+ try {
13
+ const content = await fs.readdir(dir);
14
+ return content;
15
+ } catch (err) {
16
+ if (err.code === 'ENOENT') {
17
+ return [];
18
+ }
19
+ throw err;
20
+ }
21
+ }
22
+ /**
23
+ * Skips an error if the file already exists
24
+ *
25
+ * @internal
26
+ *
27
+ * @param err - Error to check
28
+ */ export function skipIfExistsError(err) {
29
+ if (err.code === 'EEXIST') {
30
+ return;
31
+ }
32
+ throw err;
33
+ }
34
+ /**
35
+ * Copies a directory from one location to another
36
+ *
37
+ * @internal
38
+ *
39
+ * @param srcDir - Source directory
40
+ * @param destDir - Destination directory
41
+ * @param skipExisting - Skip existing files
42
+ */ export async function copyDir(srcDir, destDir, skipExisting) {
43
+ await fs.mkdir(destDir, {
44
+ recursive: true
45
+ });
46
+ for (const file of (await tryReadDir(srcDir))){
47
+ const srcFile = path.resolve(srcDir, file);
48
+ if (srcFile === destDir) {
49
+ continue;
50
+ }
51
+ const destFile = path.resolve(destDir, file);
52
+ const stat = await fs.stat(srcFile);
53
+ if (stat.isDirectory()) {
54
+ await copyDir(srcFile, destFile, skipExisting);
55
+ } else if (skipExisting) {
56
+ await fs.copyFile(srcFile, destFile, fsConstants.COPYFILE_EXCL).catch(skipIfExistsError);
57
+ } else {
58
+ await fs.copyFile(srcFile, destFile);
59
+ }
60
+ }
61
+ }
62
+
63
+ //# sourceMappingURL=copyDir.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/copyDir.ts"],"sourcesContent":["import {constants as fsConstants} from 'node:fs'\nimport fs from 'node:fs/promises'\nimport path from 'node:path'\n\n/**\n * Tries to read a directory, and returns an empty array if the directory does not exist\n *\n * @internal\n *\n * @param dir - Directory to read\n * @returns List of files in the directory\n */\nasync function tryReadDir(dir: string): Promise<string[]> {\n try {\n const content = await fs.readdir(dir)\n return content\n } catch (err) {\n if (err.code === 'ENOENT') {\n return []\n }\n\n throw err\n }\n}\n\n/**\n * Skips an error if the file already exists\n *\n * @internal\n *\n * @param err - Error to check\n */\nexport function skipIfExistsError(err: Error & {code: string}) {\n if (err.code === 'EEXIST') {\n return\n }\n\n throw err\n}\n\n/**\n * Copies a directory from one location to another\n *\n * @internal\n *\n * @param srcDir - Source directory\n * @param destDir - Destination directory\n * @param skipExisting - Skip existing files\n */\nexport async function copyDir(\n srcDir: string,\n destDir: string,\n skipExisting?: boolean,\n): Promise<void> {\n await fs.mkdir(destDir, {recursive: true})\n\n for (const file of await tryReadDir(srcDir)) {\n const srcFile = path.resolve(srcDir, file)\n if (srcFile === destDir) {\n continue\n }\n\n const destFile = path.resolve(destDir, file)\n const stat = await fs.stat(srcFile)\n\n if (stat.isDirectory()) {\n await copyDir(srcFile, destFile, skipExisting)\n } else if (skipExisting) {\n await fs.copyFile(srcFile, destFile, fsConstants.COPYFILE_EXCL).catch(skipIfExistsError)\n } else {\n await fs.copyFile(srcFile, destFile)\n }\n }\n}\n"],"names":["constants","fsConstants","fs","path","tryReadDir","dir","content","readdir","err","code","skipIfExistsError","copyDir","srcDir","destDir","skipExisting","mkdir","recursive","file","srcFile","resolve","destFile","stat","isDirectory","copyFile","COPYFILE_EXCL","catch"],"mappings":"AAAA,SAAQA,aAAaC,WAAW,QAAO,UAAS;AAChD,OAAOC,QAAQ,mBAAkB;AACjC,OAAOC,UAAU,YAAW;AAE5B;;;;;;;CAOC,GACD,eAAeC,WAAWC,GAAW;IACnC,IAAI;QACF,MAAMC,UAAU,MAAMJ,GAAGK,OAAO,CAACF;QACjC,OAAOC;IACT,EAAE,OAAOE,KAAK;QACZ,IAAIA,IAAIC,IAAI,KAAK,UAAU;YACzB,OAAO,EAAE;QACX;QAEA,MAAMD;IACR;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASE,kBAAkBF,GAA2B;IAC3D,IAAIA,IAAIC,IAAI,KAAK,UAAU;QACzB;IACF;IAEA,MAAMD;AACR;AAEA;;;;;;;;CAQC,GACD,OAAO,eAAeG,QACpBC,MAAc,EACdC,OAAe,EACfC,YAAsB;IAEtB,MAAMZ,GAAGa,KAAK,CAACF,SAAS;QAACG,WAAW;IAAI;IAExC,KAAK,MAAMC,QAAQ,CAAA,MAAMb,WAAWQ,OAAM,EAAG;QAC3C,MAAMM,UAAUf,KAAKgB,OAAO,CAACP,QAAQK;QACrC,IAAIC,YAAYL,SAAS;YACvB;QACF;QAEA,MAAMO,WAAWjB,KAAKgB,OAAO,CAACN,SAASI;QACvC,MAAMI,OAAO,MAAMnB,GAAGmB,IAAI,CAACH;QAE3B,IAAIG,KAAKC,WAAW,IAAI;YACtB,MAAMX,QAAQO,SAASE,UAAUN;QACnC,OAAO,IAAIA,cAAc;YACvB,MAAMZ,GAAGqB,QAAQ,CAACL,SAASE,UAAUnB,YAAYuB,aAAa,EAAEC,KAAK,CAACf;QACxE,OAAO;YACL,MAAMR,GAAGqB,QAAQ,CAACL,SAASE;QAC7B;IACF;AACF"}
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@sanity/cli-build",
3
+ "version": "0.1.0",
4
+ "description": "Internal Sanity package for building studios and apps",
5
+ "keywords": [
6
+ "cli",
7
+ "cms",
8
+ "content",
9
+ "headless",
10
+ "realtime",
11
+ "sanity",
12
+ "tool"
13
+ ],
14
+ "homepage": "https://github.com/sanity-io/cli",
15
+ "bugs": "https://github.com/sanity-io/cli/issues",
16
+ "license": "MIT",
17
+ "author": "Sanity.io <hello@sanity.io>",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/sanity-io/cli.git",
21
+ "directory": "packages/@sanity/cli-build"
22
+ },
23
+ "files": [
24
+ "./dist",
25
+ "!./dist/**/__tests__",
26
+ "./static"
27
+ ],
28
+ "type": "module",
29
+ "sideEffects": false,
30
+ "main": "./dist/_exports/_internal.js",
31
+ "types": "./dist/_exports/_internal.d.ts",
32
+ "exports": {
33
+ "./_internal": {
34
+ "source": "./src/_exports/_internal.ts",
35
+ "default": "./dist/_exports/_internal.js"
36
+ },
37
+ "./package.json": "./package.json"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "scripts": {
43
+ "build": "swc --delete-dir-on-start --strip-leading-paths --out-dir dist/ src --ignore '**/*.test.ts' --ignore '**/__tests__/**'",
44
+ "build:types": "pkg-utils build --emitDeclarationOnly",
45
+ "check:types": "tsc --noEmit",
46
+ "lint": "eslint .",
47
+ "publint": "publint",
48
+ "test": "vitest run",
49
+ "posttest": "pnpm run lint",
50
+ "test:coverage": "vitest run --coverage",
51
+ "test:watch": "vitest",
52
+ "watch": "swc --delete-dir-on-start --strip-leading-paths --out-dir dist/ --watch src"
53
+ },
54
+ "dependencies": {
55
+ "read-package-up": "catalog:"
56
+ },
57
+ "devDependencies": {
58
+ "@eslint/compat": "catalog:",
59
+ "@repo/package.config": "workspace:*",
60
+ "@repo/tsconfig": "workspace:*",
61
+ "@sanity/cli-test": "workspace:*",
62
+ "@sanity/eslint-config-cli": "workspace:^",
63
+ "@sanity/pkg-utils": "catalog:",
64
+ "@swc/cli": "catalog:",
65
+ "@swc/core": "catalog:",
66
+ "@types/node": "catalog:",
67
+ "@vitest/coverage-istanbul": "catalog:",
68
+ "eslint": "catalog:",
69
+ "publint": "catalog:",
70
+ "typescript": "catalog:",
71
+ "vitest": "catalog:"
72
+ },
73
+ "engines": {
74
+ "node": ">=20.19.1 <22 || >=22.12"
75
+ }
76
+ }
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,12 @@
1
+ <svg width="512" height="512" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <rect width="512" height="512" fill="#0B0B0B"/>
3
+ <rect width="256" height="256" fill="#0B0B0B"/>
4
+ <g clip-path="url(#clip0_261_6485)">
5
+ <path d="M431.519 304.966L417.597 280.733L350.26 321.759L425.051 226.504L436.358 219.867L433.56 215.662L438.697 209.096L415.097 189.445L404.295 203.215L186.253 330.829L266.869 233.849L417.024 151.513L402.758 123.926L320.972 168.755L361.246 120.336L338.174 100L247.535 209.026L157.515 258.413L226.435 167.267L269.621 144.782L255.906 116.888L130.085 182.407L164.396 136.987L140.429 117.785L68 213.678L69.1238 214.576L82.6554 242.139L162.951 200.31L89.7653 297.077L101.76 306.69L108.893 320.484L193.431 274.12L100.338 386.121L123.411 406.457L128.044 400.883L352.623 269.018L278.061 364.014L279.277 365.029L279.162 365.1L294.62 392.002L393.791 331.561L355.604 393.207L381.199 410L442 311.863L431.519 304.966Z" fill="white"/>
6
+ </g>
7
+ <defs>
8
+ <clipPath id="clip0_261_6485">
9
+ <rect width="374" height="310" fill="white" transform="translate(68 100)"/>
10
+ </clipPath>
11
+ </defs>
12
+ </svg>