@atomicsmash/smash-config 1.0.2 → 2.0.0-beta.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/dist/index.d.ts CHANGED
@@ -1,16 +1,3 @@
1
- import type { Options } from "sass";
2
- export type SCSSAliases = {
3
- loadPaths?: Options<"async">["loadPaths"];
4
- importers?: Options<"async">["importers"];
5
- };
6
- export type SmashConfig = {
7
- projectName: string;
8
- themePath: string;
9
- themeFolderName?: string;
10
- assetsOutputFolder?: string;
11
- npmInstallPaths?: string[];
12
- composerInstallPaths?: string[];
13
- scssAliases?: SCSSAliases;
14
- };
15
- export { getSmashConfig } from "./utils.js";
1
+ export * from "./types.js";
2
+ export { getSmashConfig } from "./utils/getSmashConfig.js";
16
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,MAAM,MAAM,WAAW,GAAG;IACzB,SAAS,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC;IAC1C,SAAS,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,WAAW,CAAC,EAAE,WAAW,CAAC;CAC1B,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
- export { getSmashConfig } from "./utils.js";
1
+ export * from "./types.js";
2
+ export { getSmashConfig } from "./utils/getSmashConfig.js";
@@ -0,0 +1,89 @@
1
+ import type { Options } from "sass";
2
+ export type SCSSAliases = {
3
+ loadPaths?: Options<"async">["loadPaths"];
4
+ importers?: Options<"async">["importers"];
5
+ };
6
+ export type SmashConfigV1 = {
7
+ version?: 1 | undefined;
8
+ projectName: string;
9
+ themePath: string;
10
+ themeFolderName?: string;
11
+ assetsOutputFolder?: string;
12
+ npmInstallPaths?: string[];
13
+ composerInstallPaths?: string[];
14
+ scssAliases?: SCSSAliases;
15
+ };
16
+ export type SmashConfigV2 = {
17
+ version: 2;
18
+ projectName: string;
19
+ themePath: string;
20
+ themeFolderName?: string;
21
+ assetsOutputFolder?: string;
22
+ npmInstallPaths?: string[];
23
+ composerInstallPaths?: string[];
24
+ scssAliases?: SCSSAliases;
25
+ uploadsPath?: string;
26
+ cli?: {
27
+ pullMedia?: {
28
+ monthsToPull?: number;
29
+ };
30
+ };
31
+ staging: {
32
+ url: string;
33
+ webRoot: string;
34
+ dbPrefix?: string;
35
+ uploadsPath?: string;
36
+ ssh: {
37
+ username: string;
38
+ host: string;
39
+ port?: number;
40
+ };
41
+ httpAuth?: {
42
+ username: string;
43
+ password: string;
44
+ };
45
+ };
46
+ };
47
+ export type SmashConfig = SmashConfigV1 | SmashConfigV2;
48
+ export type SmashConfigV1Resolved = {
49
+ version: 1;
50
+ projectName: string;
51
+ themePath: string;
52
+ themeFolderName: string;
53
+ assetsOutputFolder: string;
54
+ npmInstallPaths: string[];
55
+ composerInstallPaths: string[];
56
+ scssAliases: SCSSAliases;
57
+ };
58
+ export type SmashConfigV2Resolved = {
59
+ version: 2;
60
+ projectName: string;
61
+ themePath: string;
62
+ themeFolderName: string;
63
+ assetsOutputFolder: string;
64
+ npmInstallPaths: string[];
65
+ composerInstallPaths: string[];
66
+ scssAliases: SCSSAliases;
67
+ uploadsPath: string;
68
+ cli: {
69
+ pullMedia: {
70
+ monthsToPull: number;
71
+ };
72
+ };
73
+ staging: {
74
+ url: string;
75
+ webRoot: string;
76
+ dbPrefix: string;
77
+ uploadsPath: string;
78
+ ssh: {
79
+ username: string;
80
+ host: string;
81
+ port?: number;
82
+ };
83
+ httpAuth?: {
84
+ username: string;
85
+ password: string;
86
+ };
87
+ };
88
+ };
89
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,MAAM,MAAM,WAAW,GAAG;IACzB,SAAS,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC;IAC1C,SAAS,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC3B,OAAO,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,WAAW,CAAC,EAAE,WAAW,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC3B,OAAO,EAAE,CAAC,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,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e,EAAE,MAAM,EAAE,CAAC;IAC1B,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE;QACJ,SAAS,EAAE;YACV,YAAY,EAAE,MAAM,CAAC;SACrB,CAAC;KACF,CAAC;IACF,OAAO,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;QACZ,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC;QACpB,GAAG,EAAE;YACJ,QAAQ,EAAE,MAAM,CAAC;YACjB,IAAI,EAAE,MAAM,CAAC;YACb,IAAI,CAAC,EAAE,MAAM,CAAC;SACd,CAAC;QACF,QAAQ,CAAC,EAAE;YACV,QAAQ,EAAE,MAAM,CAAC;YACjB,QAAQ,EAAE,MAAM,CAAC;SACjB,CAAC;KACF,CAAC;CACF,CAAC"}
package/dist/types.js ADDED
File without changes
@@ -0,0 +1,3 @@
1
+ import type { SmashConfigV1Resolved, SmashConfigV2Resolved } from "../types.js";
2
+ export declare function getSmashConfig<MinVersion extends 1 | 2>(minVersion?: MinVersion): Promise<MinVersion extends 2 ? SmashConfigV2Resolved : SmashConfigV1Resolved | SmashConfigV2Resolved>;
3
+ //# sourceMappingURL=getSmashConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSmashConfig.d.ts","sourceRoot":"","sources":["../../src/utils/getSmashConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIX,qBAAqB,EACrB,qBAAqB,EACrB,MAAM,aAAa,CAAC;AA6BrB,wBAAsB,cAAc,CAAC,UAAU,SAAS,CAAC,GAAG,CAAC,EAC5D,UAAU,CAAC,EAAE,UAAU,yGA+EvB"}
@@ -0,0 +1,109 @@
1
+ import { normaliseStagingURL } from "./normaliseStagingURL.js";
2
+ import { normalize, resolve } from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ import { cosmiconfig } from "cosmiconfig";
5
+ const getDefaultSCSSAliases = (themePath) => ({
6
+ importers: [
7
+ {
8
+ findFileUrl(url) {
9
+ if (!url.startsWith("sitecss:"))
10
+ return null;
11
+ const pathname = url.substring(8);
12
+ return pathToFileURL(`${resolve(process.cwd(), themePath, "src/styles")}${pathname.startsWith("/") ? pathname : `/${pathname}`}`);
13
+ },
14
+ },
15
+ {
16
+ findFileUrl(url) {
17
+ if (!url.startsWith("launchpad:"))
18
+ return null;
19
+ const pathname = url.substring(10);
20
+ return pathToFileURL(`${resolve(process.cwd(), themePath, "../launchpad/src/styles")}${pathname.startsWith("/") ? pathname : `/${pathname}`}`);
21
+ },
22
+ },
23
+ ],
24
+ });
25
+ export async function getSmashConfig(minVersion) {
26
+ const explorer = cosmiconfig("smash");
27
+ const config = await explorer
28
+ .load(resolve(process.cwd(), "smash.config.ts"))
29
+ .then((result) => {
30
+ if (!result || result.isEmpty) {
31
+ throw new Error("Failed to get config. Please make sure smash.config.ts exists and exports a valid smash config configuration object.");
32
+ }
33
+ const config = result.config;
34
+ if (isValidSmashConfigV2(config)) {
35
+ const fullConfig = {
36
+ scssAliases: getDefaultSCSSAliases(config.themePath),
37
+ themeFolderName: config.projectName,
38
+ uploadsPath: `public/wp-content/uploads`,
39
+ ...config,
40
+ // Normalize and resolve paths to cwd.
41
+ npmInstallPaths: config.npmInstallPaths?.map((path) => {
42
+ return normalize(resolve(process.cwd(), path));
43
+ }) ?? [],
44
+ composerInstallPaths: config.composerInstallPaths?.map((path) => {
45
+ return normalize(resolve(process.cwd(), path));
46
+ }) ?? [],
47
+ assetsOutputFolder: config.assetsOutputFolder
48
+ ? normalize(config.assetsOutputFolder)
49
+ : "dist",
50
+ staging: {
51
+ uploadsPath: config.uploadsPath ?? `public/wp-content/uploads`,
52
+ dbPrefix: "wp_",
53
+ ...config.staging,
54
+ url: normaliseStagingURL(config.staging.url),
55
+ },
56
+ cli: {
57
+ ...config.cli,
58
+ pullMedia: {
59
+ monthsToPull: -1,
60
+ ...config.cli?.pullMedia,
61
+ },
62
+ },
63
+ };
64
+ return fullConfig;
65
+ }
66
+ if (isValidSmashConfigV1(config)) {
67
+ const fullConfig = {
68
+ version: 1,
69
+ scssAliases: getDefaultSCSSAliases(config.themePath),
70
+ themeFolderName: config.projectName,
71
+ ...config,
72
+ // Normalize and resolve paths to cwd.
73
+ npmInstallPaths: config.npmInstallPaths?.map((path) => {
74
+ return normalize(resolve(process.cwd(), path));
75
+ }) ?? [],
76
+ composerInstallPaths: config.composerInstallPaths?.map((path) => {
77
+ return normalize(resolve(process.cwd(), path));
78
+ }) ?? [],
79
+ assetsOutputFolder: config.assetsOutputFolder
80
+ ? normalize(config.assetsOutputFolder)
81
+ : "dist",
82
+ };
83
+ return fullConfig;
84
+ }
85
+ throw new Error("Failed to get valid config. Please check that your smash.config.ts exports a valid smash config configuration object.");
86
+ });
87
+ if (minVersion && config.version < minVersion) {
88
+ throw new Error(`A smash config was found but it is not up to date. Please update to at least version ${minVersion.toString()}.`);
89
+ }
90
+ return config;
91
+ }
92
+ function isValidSmashConfigV1(config) {
93
+ return (typeof config === "object" &&
94
+ config !== null &&
95
+ "projectName" in config &&
96
+ typeof config.projectName === "string" &&
97
+ "themePath" in config &&
98
+ typeof config.themePath === "string");
99
+ }
100
+ function isValidSmashConfigV2(config) {
101
+ return (typeof config === "object" &&
102
+ config !== null &&
103
+ "version" in config &&
104
+ config.version === 2 &&
105
+ "projectName" in config &&
106
+ typeof config.projectName === "string" &&
107
+ "themePath" in config &&
108
+ typeof config.themePath === "string");
109
+ }
@@ -0,0 +1,2 @@
1
+ export declare function normaliseStagingURL(stagingURL: string): string;
2
+ //# sourceMappingURL=normaliseStagingURL.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normaliseStagingURL.d.ts","sourceRoot":"","sources":["../../src/utils/normaliseStagingURL.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAK9D"}
@@ -0,0 +1,6 @@
1
+ export function normaliseStagingURL(stagingURL) {
2
+ return stagingURL
3
+ .replace(/^https?:\/\//, "")
4
+ .replace(/^\/\//, "")
5
+ .replace(/\/$/, "");
6
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atomicsmash/smash-config",
3
3
  "type": "module",
4
- "version": "1.0.2",
4
+ "version": "2.0.0-beta.0",
5
5
  "description": "",
6
6
  "keywords": [],
7
7
  "homepage": "https://www.atomicsmash.co.uk/",
@@ -37,10 +37,9 @@
37
37
  "lint:types": "tsc"
38
38
  },
39
39
  "peerDependencies": {
40
- "dotenv": "^17.3.1",
41
- "sass": "^1.98.0"
40
+ "sass": "^1.101.0"
42
41
  },
43
42
  "dependencies": {
44
- "cosmiconfig": "^9.0.1"
43
+ "cosmiconfig": "^9.0.2"
45
44
  }
46
45
  }
package/dist/utils.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { SmashConfig } from "./index.js";
2
- export declare function getSmashConfig(): Promise<Required<SmashConfig> | null>;
3
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,YAAY,CAAC;AA4B3D,wBAAsB,cAAc,IAAI,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,CAoE5E"}
package/dist/utils.js DELETED
@@ -1,94 +0,0 @@
1
- import { normalize, resolve } from "node:path";
2
- import { pathToFileURL } from "node:url";
3
- import { cosmiconfig } from "cosmiconfig";
4
- const getDefaultSCSSAliases = (themePath) => ({
5
- importers: [
6
- {
7
- findFileUrl(url) {
8
- if (!url.startsWith("sitecss:"))
9
- return null;
10
- const pathname = url.substring(8);
11
- return pathToFileURL(`${resolve(process.cwd(), themePath, "src/styles")}${pathname.startsWith("/") ? pathname : `/${pathname}`}`);
12
- },
13
- },
14
- {
15
- findFileUrl(url) {
16
- if (!url.startsWith("launchpad:"))
17
- return null;
18
- const pathname = url.substring(10);
19
- return pathToFileURL(`${resolve(process.cwd(), themePath, "../launchpad/src/styles")}${pathname.startsWith("/") ? pathname : `/${pathname}`}`);
20
- },
21
- },
22
- ],
23
- });
24
- export async function getSmashConfig() {
25
- const explorer = cosmiconfig("smash");
26
- const config = await explorer
27
- .load(resolve(process.cwd(), "smash.config.ts"))
28
- .then((result) => {
29
- if (!result || result.isEmpty) {
30
- throw new Error("Return default config.");
31
- }
32
- const config = result.config;
33
- if (isValidSmashConfig(config)) {
34
- const fullConfig = {
35
- scssAliases: getDefaultSCSSAliases(config.themePath),
36
- themeFolderName: config.projectName,
37
- ...config,
38
- // Normalize and resolve paths to cwd.
39
- npmInstallPaths: config.npmInstallPaths?.map((path) => {
40
- return normalize(resolve(process.cwd(), path));
41
- }) ?? [],
42
- composerInstallPaths: config.composerInstallPaths?.map((path) => {
43
- return normalize(resolve(process.cwd(), path));
44
- }) ?? [],
45
- assetsOutputFolder: config.assetsOutputFolder
46
- ? normalize(config.assetsOutputFolder)
47
- : "dist",
48
- };
49
- return fullConfig;
50
- }
51
- throw new Error("Return default config.");
52
- })
53
- .catch(async () => {
54
- const { themeName, themePath } = await import("dotenv")
55
- .then((dotenv) => {
56
- dotenv.config();
57
- const themeName = process.env.THEME_NAME ?? process.env.npm_package_config_theme_name;
58
- const themePath = process.env.THEME_PATH ?? process.env.npm_package_config_theme_path;
59
- return {
60
- themeName,
61
- themePath,
62
- };
63
- })
64
- .catch(() => {
65
- return {
66
- themeName: false,
67
- themePath: false,
68
- };
69
- });
70
- if (!themeName || !themePath) {
71
- return null;
72
- }
73
- console.warn("Using env vars for theme name and path is deprecated and will be removed in a future version. Create a smash.config.ts file with the relevant properties in it instead.");
74
- const defaultConfig = {
75
- projectName: themeName,
76
- themePath,
77
- themeFolderName: themeName,
78
- assetsOutputFolder: "dist",
79
- npmInstallPaths: [],
80
- composerInstallPaths: [],
81
- scssAliases: getDefaultSCSSAliases(themePath),
82
- };
83
- return defaultConfig;
84
- });
85
- return config;
86
- }
87
- function isValidSmashConfig(config) {
88
- return (typeof config === "object" &&
89
- config !== null &&
90
- "projectName" in config &&
91
- typeof config.projectName === "string" &&
92
- "themePath" in config &&
93
- typeof config.themePath === "string");
94
- }