@spicemod/creator 0.0.29 → 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.29";
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({
@@ -830,17 +831,44 @@ const clean = (cache, logger = createLogger("plugin:clean")) => ({
830
831
  }
831
832
  });
832
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
+
833
861
  //#endregion
834
862
  //#region src/esbuild/plugins/css.ts
835
- function css({ minify = false, inline = false, logger = createLogger("plugin:css") } = {}) {
863
+ function css({ minify = false, inline = false, logger = createLogger("plugin:css"), styleId = null } = {}) {
836
864
  const postCssPlugins = [
837
865
  postcssImport({ path: [resolve(process.cwd(), "src")] }),
838
866
  autoprefixer,
839
867
  postcssPresetEnv({ stage: 0 }),
840
868
  ...minify ? [postcssMinify()] : []
841
869
  ];
842
- const type = inline ? "style" : "css";
843
- return [sassPlugin({
870
+ const type = inline ? styleId ? "css" : "style" : "css";
871
+ const plugins = [sassPlugin({
844
872
  filter: /\.module\.(s[ac]ss|css)$/,
845
873
  type,
846
874
  transform: postcssModules({
@@ -861,6 +889,8 @@ function css({ minify = false, inline = false, logger = createLogger("plugin:css
861
889
  return result.css;
862
890
  }
863
891
  })];
892
+ if (inline && styleId) plugins.push(inlineBundledCss(styleId));
893
+ return plugins;
864
894
  }
865
895
 
866
896
  //#endregion
@@ -1105,7 +1135,7 @@ function wrapWithLoader({ config, cache, outFiles, server, dev = false, logger =
1105
1135
  target: build$3.initialOptions.target || "es2020",
1106
1136
  loader: "jsx",
1107
1137
  define: {
1108
- __ESBUILD__HAS_CSS: JSON.stringify(type !== "theme"),
1138
+ __ESBUILD__HAS_CSS: JSON.stringify(type !== "theme" && bundledCss.length !== 0),
1109
1139
  __ESBUILD__INJECTED_CSS: JSON.stringify(bundledCss),
1110
1140
  __ESBUILD__APP_SLUG: JSON.stringify(slug),
1111
1141
  __ESBUILD__APP_TYPE: JSON.stringify(type),
@@ -1213,7 +1243,8 @@ const getCommonPlugins = (opts) => {
1213
1243
  const p = [
1214
1244
  ...plugins.css({
1215
1245
  minify,
1216
- inline
1246
+ inline,
1247
+ styleId: template === "extension" && opts.cssId ? opts.cssId : null
1217
1248
  }),
1218
1249
  plugins.clean(cache),
1219
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.29",
3
+ "version": "0.0.30",
4
4
  "description": "Easily make Spicetify extensions and themes",
5
5
  "keywords": [
6
6
  "cli",