@spicemod/creator 0.0.30 → 0.0.31

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/dist/bin.mjs CHANGED
@@ -140,11 +140,12 @@ const liveReloadFilePath = dist(`templates/liveReload.js`, import.meta.url);
140
140
  const hmrCustomAppFilePath = dist(`templates/hmrCustomApp.js`, import.meta.url);
141
141
  const templateWrapperFilePath = dist("templates/wrapper.js", import.meta.url);
142
142
  const customAppEntryFilePath = dist("templates/customAppEntry.js", import.meta.url);
143
+ const injectCSSFilePath = dist("templates/injectCSS.js", import.meta.url);
143
144
 
144
145
  //#endregion
145
146
  //#region package.json
146
147
  var name = "@spicemod/creator";
147
- var version = "0.0.30";
148
+ var version = "0.0.31";
148
149
 
149
150
  //#endregion
150
151
  //#region src/utils/common.ts
@@ -625,6 +626,7 @@ async function resolveContext(config) {
625
626
  config.outDir = resolve(cwd, config.outDir || "./dist");
626
627
  config.esbuildOptions ??= {};
627
628
  config.serverConfig ??= {};
629
+ if (config.template === "extension") config.cssId ??= `${varSlugify(getEnName(config.name))}_styles`;
628
630
  if (config.template === "custom-app") config.icon ??= {
629
631
  default: resolveDefaultIcon(cwd),
630
632
  active: resolveActiveIcon(cwd)
@@ -837,22 +839,29 @@ function inlineBundledCss(styleId) {
837
839
  return {
838
840
  name: "inline-bundled-css",
839
841
  setup(build) {
840
- build.onEnd((result) => {
842
+ build.onEnd(async (result) => {
841
843
  if (result.errors.length > 0 || !result.outputFiles) return;
842
- const cssFiles = result.outputFiles.filter((file) => file.path.endsWith(".css"));
843
- const jsFiles = result.outputFiles.filter((file) => file.path.endsWith(".js"));
844
- for (const cssFile of cssFiles) {
844
+ const outputFiles = result.outputFiles;
845
+ const cssFiles = outputFiles.filter((file) => file.path.endsWith(".css"));
846
+ const jsFiles = outputFiles.filter((file) => file.path.endsWith(".js"));
847
+ await Promise.all(cssFiles.map(async (cssFile) => {
845
848
  const cssContent = cssFile.text;
846
- const injectScript = `(function() {if (typeof document === 'undefined') return;var style = document.getElementById('${styleId}');if (!style) {style = document.createElement('style');style.id = '${styleId}';document.head.appendChild(style);}style.textContent = ${JSON.stringify(cssContent)};})();`;
849
+ const { code: injectScript } = await transform(readFileSync(injectCSSFilePath, "utf-8"), {
850
+ loader: "js",
851
+ define: {
852
+ __ESBUILD__STYLE_ID__: JSON.stringify(styleId),
853
+ __ESBUILD__CSS_CONTENT__: JSON.stringify(cssContent)
854
+ }
855
+ });
847
856
  const jsPath = cssFile.path.replace(/\.css$/, ".js");
848
857
  const jsFile = jsFiles.find((file) => file.path === jsPath);
849
858
  if (jsFile) {
850
859
  const updatedJsText = jsFile.text + injectScript;
851
860
  jsFile.contents = new TextEncoder().encode(updatedJsText);
852
- const cssIndex = result.outputFiles.indexOf(cssFile);
853
- if (cssIndex > -1) result.outputFiles.splice(cssIndex, 1);
861
+ const cssIndex = outputFiles.indexOf(cssFile);
862
+ if (cssIndex > -1) outputFiles.splice(cssIndex, 1);
854
863
  }
855
- }
864
+ }));
856
865
  });
857
866
  }
858
867
  };
@@ -2116,7 +2125,7 @@ async function createHmrServer(config, logger = createLogger("hmrServer")) {
2116
2125
 
2117
2126
  //#endregion
2118
2127
  //#region src/utils/hmr.ts
2119
- const injectHMRExtension = async (rootLink, wsLink, outFiles) => {
2128
+ const injectHMRExtension = async (rootLink, wsLink, outFiles, config) => {
2120
2129
  const extName = `sc-live-reload-helper.js`;
2121
2130
  const spiceConfig = await getSpicetifyConfig();
2122
2131
  const cleanup = () => {
@@ -2148,7 +2157,8 @@ const injectHMRExtension = async (rootLink, wsLink, outFiles) => {
2148
2157
  _HOT_RELOAD_LINK: JSON.stringify(wsLink),
2149
2158
  _JS_PATH: JSON.stringify(`/files/${outFiles.js}`),
2150
2159
  _CSS_PATH: JSON.stringify(outFiles.css ? `/files/${outFiles.css}` : `/files/app.css`),
2151
- _REMOVE_CMD: JSON.stringify(`spicetify config extensions sc-live-reload-helper.js- && spicetify apply`)
2160
+ _REMOVE_CMD: JSON.stringify(`spicetify config extensions sc-live-reload-helper.js- && spicetify apply`),
2161
+ _CSS_ID: JSON.stringify(config.template === "extension" && config.cssId ? config.cssId : "sc-injected-css")
2152
2162
  }
2153
2163
  });
2154
2164
  writeFileSync(outDir, code);
@@ -2263,7 +2273,7 @@ async function dev$1(options) {
2263
2273
  await server.start();
2264
2274
  const outFiles = getOutFiles(config, true);
2265
2275
  if (config.template === "custom-app") await injectHMRCustomApp(server.link, server.wsLink, outFiles, config);
2266
- else await injectHMRExtension(server.link, server.wsLink, outFiles);
2276
+ else await injectHMRExtension(server.link, server.wsLink, outFiles, config);
2267
2277
  ctx = await context(getJSDevOptions(config, {
2268
2278
  ...options,
2269
2279
  outFiles,
@@ -0,0 +1,9 @@
1
+ (function () {
2
+ var style = document.getElementById(__ESBUILD__STYLE_ID__ || undefined);
3
+ if (!style) {
4
+ style = document.createElement("style");
5
+ style.id = __ESBUILD__STYLE_ID__ || undefined;
6
+ document.head.appendChild(style);
7
+ }
8
+ style.textContent = __ESBUILD__CSS_CONTENT__;
9
+ })();
@@ -5,7 +5,7 @@
5
5
  cssPath: _CSS_PATH,
6
6
  jsPath: _JS_PATH,
7
7
  removeCmd: _REMOVE_CMD,
8
- cssId: "sc-css-injected",
8
+ cssId: _CSS_ID || "sc-css-injected",
9
9
  jsId: "sc-js-injected",
10
10
  };
11
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spicemod/creator",
3
- "version": "0.0.30",
3
+ "version": "0.0.31",
4
4
  "description": "Easily make Spicetify extensions and themes",
5
5
  "keywords": [
6
6
  "cli",
@@ -0,0 +1,9 @@
1
+ (function () {
2
+ var style = document.getElementById(__ESBUILD__STYLE_ID__ || undefined);
3
+ if (!style) {
4
+ style = document.createElement("style");
5
+ style.id = __ESBUILD__STYLE_ID__ || undefined;
6
+ document.head.appendChild(style);
7
+ }
8
+ style.textContent = __ESBUILD__CSS_CONTENT__;
9
+ })();
@@ -5,7 +5,7 @@
5
5
  cssPath: _CSS_PATH,
6
6
  jsPath: _JS_PATH,
7
7
  removeCmd: _REMOVE_CMD,
8
- cssId: "sc-css-injected",
8
+ cssId: _CSS_ID || "sc-css-injected",
9
9
  jsId: "sc-js-injected",
10
10
  };
11
11