@spicemod/creator 0.0.29 → 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.29";
148
+ var version = "0.0.31";
148
149
 
149
150
  //#endregion
150
151
  //#region src/utils/common.ts
@@ -358,6 +359,7 @@ const LocaleNameSchema = v.intersect([v.object({ en: v.string() }), v.record(v.p
358
359
  const ExtensionTemplateSchema = v.object({
359
360
  name: v.string(),
360
361
  template: v.literal("extension"),
362
+ cssId: v.optional(v.string()),
361
363
  entry: EntryFileSchema
362
364
  });
363
365
  const ThemeTemplateSchema = v.object({
@@ -624,6 +626,7 @@ async function resolveContext(config) {
624
626
  config.outDir = resolve(cwd, config.outDir || "./dist");
625
627
  config.esbuildOptions ??= {};
626
628
  config.serverConfig ??= {};
629
+ if (config.template === "extension") config.cssId ??= `${varSlugify(getEnName(config.name))}_styles`;
627
630
  if (config.template === "custom-app") config.icon ??= {
628
631
  default: resolveDefaultIcon(cwd),
629
632
  active: resolveActiveIcon(cwd)
@@ -830,17 +833,51 @@ const clean = (cache, logger = createLogger("plugin:clean")) => ({
830
833
  }
831
834
  });
832
835
 
836
+ //#endregion
837
+ //#region src/esbuild/plugins/inlineBundledCss.ts
838
+ function inlineBundledCss(styleId) {
839
+ return {
840
+ name: "inline-bundled-css",
841
+ setup(build) {
842
+ build.onEnd(async (result) => {
843
+ if (result.errors.length > 0 || !result.outputFiles) return;
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) => {
848
+ const cssContent = cssFile.text;
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
+ });
856
+ const jsPath = cssFile.path.replace(/\.css$/, ".js");
857
+ const jsFile = jsFiles.find((file) => file.path === jsPath);
858
+ if (jsFile) {
859
+ const updatedJsText = jsFile.text + injectScript;
860
+ jsFile.contents = new TextEncoder().encode(updatedJsText);
861
+ const cssIndex = outputFiles.indexOf(cssFile);
862
+ if (cssIndex > -1) outputFiles.splice(cssIndex, 1);
863
+ }
864
+ }));
865
+ });
866
+ }
867
+ };
868
+ }
869
+
833
870
  //#endregion
834
871
  //#region src/esbuild/plugins/css.ts
835
- function css({ minify = false, inline = false, logger = createLogger("plugin:css") } = {}) {
872
+ function css({ minify = false, inline = false, logger = createLogger("plugin:css"), styleId = null } = {}) {
836
873
  const postCssPlugins = [
837
874
  postcssImport({ path: [resolve(process.cwd(), "src")] }),
838
875
  autoprefixer,
839
876
  postcssPresetEnv({ stage: 0 }),
840
877
  ...minify ? [postcssMinify()] : []
841
878
  ];
842
- const type = inline ? "style" : "css";
843
- return [sassPlugin({
879
+ const type = inline ? styleId ? "css" : "style" : "css";
880
+ const plugins = [sassPlugin({
844
881
  filter: /\.module\.(s[ac]ss|css)$/,
845
882
  type,
846
883
  transform: postcssModules({
@@ -861,6 +898,8 @@ function css({ minify = false, inline = false, logger = createLogger("plugin:css
861
898
  return result.css;
862
899
  }
863
900
  })];
901
+ if (inline && styleId) plugins.push(inlineBundledCss(styleId));
902
+ return plugins;
864
903
  }
865
904
 
866
905
  //#endregion
@@ -1105,7 +1144,7 @@ function wrapWithLoader({ config, cache, outFiles, server, dev = false, logger =
1105
1144
  target: build$3.initialOptions.target || "es2020",
1106
1145
  loader: "jsx",
1107
1146
  define: {
1108
- __ESBUILD__HAS_CSS: JSON.stringify(type !== "theme"),
1147
+ __ESBUILD__HAS_CSS: JSON.stringify(type !== "theme" && bundledCss.length !== 0),
1109
1148
  __ESBUILD__INJECTED_CSS: JSON.stringify(bundledCss),
1110
1149
  __ESBUILD__APP_SLUG: JSON.stringify(slug),
1111
1150
  __ESBUILD__APP_TYPE: JSON.stringify(type),
@@ -1213,7 +1252,8 @@ const getCommonPlugins = (opts) => {
1213
1252
  const p = [
1214
1253
  ...plugins.css({
1215
1254
  minify,
1216
- inline
1255
+ inline,
1256
+ styleId: template === "extension" && opts.cssId ? opts.cssId : null
1217
1257
  }),
1218
1258
  plugins.clean(cache),
1219
1259
  plugins.externalGlobal({
@@ -2085,7 +2125,7 @@ async function createHmrServer(config, logger = createLogger("hmrServer")) {
2085
2125
 
2086
2126
  //#endregion
2087
2127
  //#region src/utils/hmr.ts
2088
- const injectHMRExtension = async (rootLink, wsLink, outFiles) => {
2128
+ const injectHMRExtension = async (rootLink, wsLink, outFiles, config) => {
2089
2129
  const extName = `sc-live-reload-helper.js`;
2090
2130
  const spiceConfig = await getSpicetifyConfig();
2091
2131
  const cleanup = () => {
@@ -2117,7 +2157,8 @@ const injectHMRExtension = async (rootLink, wsLink, outFiles) => {
2117
2157
  _HOT_RELOAD_LINK: JSON.stringify(wsLink),
2118
2158
  _JS_PATH: JSON.stringify(`/files/${outFiles.js}`),
2119
2159
  _CSS_PATH: JSON.stringify(outFiles.css ? `/files/${outFiles.css}` : `/files/app.css`),
2120
- _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")
2121
2162
  }
2122
2163
  });
2123
2164
  writeFileSync(outDir, code);
@@ -2232,7 +2273,7 @@ async function dev$1(options) {
2232
2273
  await server.start();
2233
2274
  const outFiles = getOutFiles(config, true);
2234
2275
  if (config.template === "custom-app") await injectHMRCustomApp(server.link, server.wsLink, outFiles, config);
2235
- else await injectHMRExtension(server.link, server.wsLink, outFiles);
2276
+ else await injectHMRExtension(server.link, server.wsLink, outFiles, config);
2236
2277
  ctx = await context(getJSDevOptions(config, {
2237
2278
  ...options,
2238
2279
  outFiles,
package/dist/index.d.mts CHANGED
@@ -171,36 +171,43 @@ declare const FileOptionsSchema: v.IntersectSchema<[Omit<v.ObjectSchema<{
171
171
  }, undefined>, v.VariantSchema<"template", [Omit<v.ObjectSchema<{
172
172
  readonly name: v.StringSchema<undefined>;
173
173
  readonly template: v.LiteralSchema<"extension", undefined>;
174
+ readonly cssId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
174
175
  readonly entry: v.StringSchema<undefined>;
175
176
  }, undefined>, "~types" | "~run" | "~standard" | "entries"> & {
176
177
  readonly entries: {
177
178
  readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
178
179
  readonly template: v.OptionalSchema<v.LiteralSchema<"extension", undefined>, undefined>;
180
+ readonly cssId: v.OptionalSchema<v.OptionalSchema<v.StringSchema<undefined>, undefined>, undefined>;
179
181
  readonly entry: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
180
182
  };
181
183
  readonly "~standard": v.StandardProps<{
182
184
  name?: string | undefined;
183
185
  template?: "extension" | undefined;
186
+ cssId?: string | undefined;
184
187
  entry?: string | undefined;
185
188
  }, {
186
189
  name?: string | undefined;
187
190
  template?: "extension" | undefined;
191
+ cssId?: string | undefined;
188
192
  entry?: string | undefined;
189
193
  }>;
190
194
  readonly "~run": (dataset: v.UnknownDataset, config: v.Config<v.BaseIssue<unknown>>) => v.OutputDataset<{
191
195
  name?: string | undefined;
192
196
  template?: "extension" | undefined;
197
+ cssId?: string | undefined;
193
198
  entry?: string | undefined;
194
199
  }, v.StringIssue | v.ObjectIssue | v.LiteralIssue>;
195
200
  readonly "~types"?: {
196
201
  readonly input: {
197
202
  name?: string | undefined;
198
203
  template?: "extension" | undefined;
204
+ cssId?: string | undefined;
199
205
  entry?: string | undefined;
200
206
  };
201
207
  readonly output: {
202
208
  name?: string | undefined;
203
209
  template?: "extension" | undefined;
210
+ cssId?: string | undefined;
204
211
  entry?: string | undefined;
205
212
  };
206
213
  readonly issue: v.StringIssue | v.ObjectIssue | v.LiteralIssue;
@@ -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.29",
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