@spicemod/creator 0.0.28 → 0.0.30

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
@@ -144,7 +144,7 @@ const customAppEntryFilePath = dist("templates/customAppEntry.js", import.meta.u
144
144
  //#endregion
145
145
  //#region package.json
146
146
  var name = "@spicemod/creator";
147
- var version = "0.0.28";
147
+ var version = "0.0.30";
148
148
 
149
149
  //#endregion
150
150
  //#region src/utils/common.ts
@@ -358,6 +358,7 @@ const LocaleNameSchema = v.intersect([v.object({ en: v.string() }), v.record(v.p
358
358
  const ExtensionTemplateSchema = v.object({
359
359
  name: v.string(),
360
360
  template: v.literal("extension"),
361
+ cssId: v.optional(v.string()),
361
362
  entry: EntryFileSchema
362
363
  });
363
364
  const ThemeTemplateSchema = v.object({
@@ -409,7 +410,7 @@ const OptionsSchema$1 = v.intersect([
409
410
  //#region src/env.ts
410
411
  const isDev = process.env.IS_DEV === "true";
411
412
  const spicetifyBin = process.env.SPICETIFY_BIN || process.env.SPICE_BIN || "spicetify";
412
- const skipSpicetify = process.env.SPICETIFY_SKIP === "true" || process.env.CI === "true";
413
+ const skipSpicetify = process.env.SPICETIFY_SKIP === "true" || !!process.env.CI;
413
414
  const env = {
414
415
  isDev,
415
416
  spicetifyBin,
@@ -509,6 +510,7 @@ const SpicetifyConfigSchema = v.object({
509
510
  //#endregion
510
511
  //#region src/utils/spicetify/index.ts
511
512
  function runSpice(args) {
513
+ if (env.skipSpicetify) throw new Error("Spicetify operations are disabled in CI");
512
514
  validateSpicetify(env.spicetifyBin);
513
515
  return spawnSync(env.spicetifyBin, args, { encoding: "utf-8" });
514
516
  }
@@ -516,6 +518,7 @@ const getCustomAppsDir = () => join(getSpiceDataPath(), "CustomApps");
516
518
  const getExtensionDir = () => join(getSpiceDataPath(), "Extensions");
517
519
  const getThemesDir = () => join(getSpiceDataPath(), "Themes");
518
520
  async function getSpicetifyConfig() {
521
+ if (env.skipSpicetify) throw new Error("Spicetify operations are disabled in CI");
519
522
  const { stdout, stderr, error } = runSpice(["path", "-c"]);
520
523
  if (error || stderr) throw new Error(`Failed to locate Spicetify config: ${stderr || error?.message}`);
521
524
  const rawConfig = parse(await readFile(stdout.trim(), "utf-8"));
@@ -524,11 +527,13 @@ async function getSpicetifyConfig() {
524
527
  else throw new Error("Spicetify Config Validation Failed:", v.flatten(result.issues).nested);
525
528
  }
526
529
  function getSpiceDataPath() {
530
+ if (env.skipSpicetify) throw new Error("Spicetify operations are disabled in CI");
527
531
  const { stdout, stderr, error } = runSpice(["path", "userdata"]);
528
532
  if (error || stderr) throw new Error(`Failed to locate Spicetify config: ${stderr || error?.message}`);
529
533
  return stdout.trim();
530
534
  }
531
535
  function validateSpicetify(bin) {
536
+ if (env.skipSpicetify) return;
532
537
  const result = spawnSync(bin, ["--version"], { encoding: "utf-8" });
533
538
  if (result.error) throw result.error;
534
539
  if (result.status !== 0) throw new Error(`Invalid spicetify binary "${bin}": ${result.stderr || "unknown error"}`);
@@ -826,17 +831,44 @@ const clean = (cache, logger = createLogger("plugin:clean")) => ({
826
831
  }
827
832
  });
828
833
 
834
+ //#endregion
835
+ //#region src/esbuild/plugins/inlineBundledCss.ts
836
+ function inlineBundledCss(styleId) {
837
+ return {
838
+ name: "inline-bundled-css",
839
+ setup(build) {
840
+ build.onEnd((result) => {
841
+ 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) {
845
+ 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)};})();`;
847
+ const jsPath = cssFile.path.replace(/\.css$/, ".js");
848
+ const jsFile = jsFiles.find((file) => file.path === jsPath);
849
+ if (jsFile) {
850
+ const updatedJsText = jsFile.text + injectScript;
851
+ jsFile.contents = new TextEncoder().encode(updatedJsText);
852
+ const cssIndex = result.outputFiles.indexOf(cssFile);
853
+ if (cssIndex > -1) result.outputFiles.splice(cssIndex, 1);
854
+ }
855
+ }
856
+ });
857
+ }
858
+ };
859
+ }
860
+
829
861
  //#endregion
830
862
  //#region src/esbuild/plugins/css.ts
831
- function css({ minify = false, inline = false, logger = createLogger("plugin:css") } = {}) {
863
+ function css({ minify = false, inline = false, logger = createLogger("plugin:css"), styleId = null } = {}) {
832
864
  const postCssPlugins = [
833
865
  postcssImport({ path: [resolve(process.cwd(), "src")] }),
834
866
  autoprefixer,
835
867
  postcssPresetEnv({ stage: 0 }),
836
868
  ...minify ? [postcssMinify()] : []
837
869
  ];
838
- const type = inline ? "style" : "css";
839
- return [sassPlugin({
870
+ const type = inline ? styleId ? "css" : "style" : "css";
871
+ const plugins = [sassPlugin({
840
872
  filter: /\.module\.(s[ac]ss|css)$/,
841
873
  type,
842
874
  transform: postcssModules({
@@ -857,6 +889,8 @@ function css({ minify = false, inline = false, logger = createLogger("plugin:css
857
889
  return result.css;
858
890
  }
859
891
  })];
892
+ if (inline && styleId) plugins.push(inlineBundledCss(styleId));
893
+ return plugins;
860
894
  }
861
895
 
862
896
  //#endregion
@@ -922,7 +956,7 @@ const spicetifyHandler = ({ config, options, cache, logger = createLogger("plugi
922
956
  const identifier = isExtension ? `${urlSlugify(config.name)}.js` : urlSlugify(getEnName(config.name));
923
957
  const getDestDirs = () => {
924
958
  const dirs = [resolve(outDir)];
925
- if (copy) dirs.push(isExtension ? getExtensionDir() : isCustomApp ? resolve(getCustomAppsDir(), identifier) : resolve(getThemesDir(), identifier));
959
+ if (copy && !env.skipSpicetify) dirs.push(isExtension ? getExtensionDir() : isCustomApp ? resolve(getCustomAppsDir(), identifier) : resolve(getThemesDir(), identifier));
926
960
  return dirs;
927
961
  };
928
962
  if (env.skipSpicetify) logger.info(pc.yellow("Skipping Spicetify operations..."));
@@ -1101,7 +1135,7 @@ function wrapWithLoader({ config, cache, outFiles, server, dev = false, logger =
1101
1135
  target: build$3.initialOptions.target || "es2020",
1102
1136
  loader: "jsx",
1103
1137
  define: {
1104
- __ESBUILD__HAS_CSS: JSON.stringify(type !== "theme"),
1138
+ __ESBUILD__HAS_CSS: JSON.stringify(type !== "theme" && bundledCss.length !== 0),
1105
1139
  __ESBUILD__INJECTED_CSS: JSON.stringify(bundledCss),
1106
1140
  __ESBUILD__APP_SLUG: JSON.stringify(slug),
1107
1141
  __ESBUILD__APP_TYPE: JSON.stringify(type),
@@ -1209,7 +1243,8 @@ const getCommonPlugins = (opts) => {
1209
1243
  const p = [
1210
1244
  ...plugins.css({
1211
1245
  minify,
1212
- inline
1246
+ inline,
1247
+ styleId: template === "extension" && opts.cssId ? opts.cssId : null
1213
1248
  }),
1214
1249
  plugins.clean(cache),
1215
1250
  plugins.externalGlobal({
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spicemod/creator",
3
- "version": "0.0.28",
3
+ "version": "0.0.30",
4
4
  "description": "Easily make Spicetify extensions and themes",
5
5
  "keywords": [
6
6
  "cli",