@shopify/cli-hydrogen 3.0.25 → 3.0.26
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/CHANGELOG.md +20 -0
- package/README.md +2 -2
- package/dist/cli/commands/hydrogen/add/eslint.d.ts +10 -0
- package/dist/cli/commands/hydrogen/add/eslint.js +25 -0
- package/dist/cli/commands/hydrogen/add/eslint.js.map +1 -0
- package/dist/cli/commands/hydrogen/add/tailwind.d.ts +10 -0
- package/dist/cli/commands/hydrogen/add/tailwind.js +25 -0
- package/dist/cli/commands/hydrogen/add/tailwind.js.map +1 -0
- package/dist/cli/commands/hydrogen/build.d.ts +13 -0
- package/dist/cli/commands/hydrogen/build.js +48 -0
- package/dist/cli/commands/hydrogen/build.js.map +1 -0
- package/dist/cli/commands/hydrogen/dev.d.ts +11 -0
- package/dist/cli/commands/hydrogen/dev.js +25 -0
- package/dist/cli/commands/hydrogen/dev.js.map +1 -0
- package/dist/cli/commands/hydrogen/info.d.ts +11 -0
- package/dist/cli/commands/hydrogen/info.js +27 -0
- package/dist/cli/commands/hydrogen/info.js.map +1 -0
- package/dist/cli/commands/hydrogen/preview.d.ts +11 -0
- package/dist/cli/commands/hydrogen/preview.js +37 -0
- package/dist/cli/commands/hydrogen/preview.js.map +1 -0
- package/dist/cli/constants.d.ts +21 -0
- package/dist/cli/constants.js +18 -0
- package/dist/cli/constants.js.map +1 -0
- package/dist/cli/flags.d.ts +4 -0
- package/dist/cli/flags.js +16 -0
- package/dist/cli/flags.js.map +1 -0
- package/dist/cli/models/hydrogen.d.ts +22 -0
- package/dist/cli/models/hydrogen.js +82 -0
- package/dist/cli/models/hydrogen.js.map +1 -0
- package/dist/cli/services/build.d.ts +10 -0
- package/dist/cli/services/build.js +38 -0
- package/dist/cli/services/build.js.map +1 -0
- package/dist/cli/services/dev.d.ts +7 -0
- package/dist/cli/services/dev.js +25 -0
- package/dist/cli/services/dev.js.map +1 -0
- package/dist/cli/services/eslint.d.ts +8 -0
- package/dist/cli/services/eslint.js +73 -0
- package/dist/cli/services/eslint.js.map +1 -0
- package/dist/cli/services/info.d.ts +7 -0
- package/dist/cli/services/info.js +131 -0
- package/dist/cli/services/info.js.map +1 -0
- package/dist/cli/services/preview.d.ts +9 -0
- package/dist/cli/services/preview.js +55 -0
- package/dist/cli/services/preview.js.map +1 -0
- package/dist/cli/services/tailwind.d.ts +9 -0
- package/dist/cli/services/tailwind.js +102 -0
- package/dist/cli/services/tailwind.js.map +1 -0
- package/dist/cli/utilities/load-config.d.ts +5 -0
- package/dist/cli/utilities/load-config.js +6 -0
- package/dist/cli/utilities/load-config.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +9 -11
- package/dist/commands/hydrogen/add/eslint.js +0 -103
- package/dist/commands/hydrogen/add/eslint.js.map +0 -1
- package/dist/commands/hydrogen/add/tailwind.js +0 -131
- package/dist/commands/hydrogen/add/tailwind.js.map +0 -1
- package/dist/commands/hydrogen/build.js +0 -77
- package/dist/commands/hydrogen/build.js.map +0 -1
- package/dist/commands/hydrogen/dev.js +0 -49
- package/dist/commands/hydrogen/dev.js.map +0 -1
- package/dist/commands/hydrogen/info.js +0 -158
- package/dist/commands/hydrogen/info.js.map +0 -1
- package/dist/commands/hydrogen/preview.js +0 -93
- package/dist/commands/hydrogen/preview.js.map +0 -1
- package/dist/flags-39d1e3c2.js +0 -19
- package/dist/flags-39d1e3c2.js.map +0 -1
- package/dist/hydrogen-21276a42.js +0 -124
- package/dist/hydrogen-21276a42.js.map +0 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createServer } from 'vite';
|
|
2
|
+
import { error as kitError } from '@shopify/cli-kit';
|
|
3
|
+
async function dev({ directory, force, host }) {
|
|
4
|
+
try {
|
|
5
|
+
const server = await createServer({
|
|
6
|
+
root: directory,
|
|
7
|
+
server: {
|
|
8
|
+
open: true,
|
|
9
|
+
force,
|
|
10
|
+
host,
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
await server.listen();
|
|
14
|
+
server.printUrls();
|
|
15
|
+
server.config.logger.info('');
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
const abortError = new kitError.Abort(error.message);
|
|
20
|
+
abortError.stack = error.stack;
|
|
21
|
+
throw abortError;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export default dev;
|
|
25
|
+
//# sourceMappingURL=dev.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../../src/cli/services/dev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,MAAM,CAAA;AACjC,OAAO,EAAC,KAAK,IAAI,QAAQ,EAAC,MAAM,kBAAkB,CAAA;AAQlD,KAAK,UAAU,GAAG,CAAC,EAAC,SAAS,EAAE,KAAK,EAAE,IAAI,EAAa;IACrD,IAAI;QACF,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC;YAChC,IAAI,EAAE,SAAS;YACf,MAAM,EAAE;gBACN,IAAI,EAAE,IAAI;gBACV,KAAK;gBACL,IAAI;aACL;SACF,CAAC,CAAA;QACF,MAAM,MAAM,CAAC,MAAM,EAAE,CAAA;QACrB,MAAM,CAAC,SAAS,EAAE,CAAA;QAClB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAC7B,8DAA8D;KAC/D;IAAC,OAAO,KAAU,EAAE;QACnB,MAAM,UAAU,GAAG,IAAI,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QACpD,UAAU,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAA;QAC9B,MAAM,UAAU,CAAA;KACjB;AACH,CAAC;AAED,eAAe,GAAG,CAAA","sourcesContent":["import {createServer} from 'vite'\nimport {error as kitError} from '@shopify/cli-kit'\n\ninterface DevOptions {\n directory: string\n force: boolean\n host: boolean\n}\n\nasync function dev({directory, force, host}: DevOptions) {\n try {\n const server = await createServer({\n root: directory,\n server: {\n open: true,\n force,\n host,\n },\n })\n await server.listen()\n server.printUrls()\n server.config.logger.info('')\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n const abortError = new kitError.Abort(error.message)\n abortError.stack = error.stack\n throw abortError\n }\n}\n\nexport default dev\n"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { genericConfigurationFileNames } from '../constants';
|
|
2
|
+
import { ui, vscode, npm, file, dependency, path, error, environment } from '@shopify/cli-kit';
|
|
3
|
+
import stream from 'node:stream';
|
|
4
|
+
export async function addESLint({ app, force, install }) {
|
|
5
|
+
const list = ui.newListr([
|
|
6
|
+
{
|
|
7
|
+
title: 'Installing additional dependencies',
|
|
8
|
+
skip: () => !install,
|
|
9
|
+
task: async (_, task) => {
|
|
10
|
+
const requiredDependencies = ['eslint', 'eslint-plugin-hydrogen', 'prettier', '@shopify/prettier-config'];
|
|
11
|
+
await dependency.addNPMDependenciesWithoutVersionIfNeeded(requiredDependencies, {
|
|
12
|
+
dependencyManager: app.dependencyManager,
|
|
13
|
+
type: 'prod',
|
|
14
|
+
directory: app.directory,
|
|
15
|
+
stderr: new stream.Writable({
|
|
16
|
+
write(chunk, encoding, next) {
|
|
17
|
+
task.output = chunk.toString();
|
|
18
|
+
next();
|
|
19
|
+
},
|
|
20
|
+
}),
|
|
21
|
+
stdout: new stream.Writable({
|
|
22
|
+
write(chunk, encoding, next) {
|
|
23
|
+
task.output = chunk.toString();
|
|
24
|
+
next();
|
|
25
|
+
},
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
28
|
+
task.title = 'Dependencies installed';
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
title: 'Adding ESLint configuration',
|
|
33
|
+
task: async (_, task) => {
|
|
34
|
+
const eslintConfigPath = path.join(app.directory, genericConfigurationFileNames.eslint);
|
|
35
|
+
if (await file.exists(eslintConfigPath)) {
|
|
36
|
+
if (force) {
|
|
37
|
+
await file.remove(eslintConfigPath);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
throw new error.Abort('ESLint config already exists.', 'Use --force to override existing config.');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const extended = [`'plugin:hydrogen/recommended'`];
|
|
44
|
+
if (app.language === 'TypeScript') {
|
|
45
|
+
extended.push(`'plugin:hydrogen/typescript'`);
|
|
46
|
+
}
|
|
47
|
+
const eslintConfig = await file.format(['module.exports = {', 'extends: [', `${extended.join(',')}`, ' ],', ' };'].join('\n'), { path: genericConfigurationFileNames.eslint });
|
|
48
|
+
await file.write(eslintConfigPath, eslintConfig);
|
|
49
|
+
task.title = 'ESLint configuration added';
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
title: 'Updating package.json',
|
|
54
|
+
task: async (_, task) => {
|
|
55
|
+
const packageJSON = await npm.readPackageJSON(app.directory);
|
|
56
|
+
packageJSON.scripts.lint = `eslint --ext .js,.ts,.jsx,.tsx src/`;
|
|
57
|
+
packageJSON.prettier = '@shopify/prettier-config';
|
|
58
|
+
await npm.writePackageJSON(app.directory, packageJSON);
|
|
59
|
+
task.title = 'Package.json updated';
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
title: 'Adding editor plugin recommendations',
|
|
64
|
+
skip: async () => !(await vscode.isVSCode(app.directory)),
|
|
65
|
+
task: async (_, task) => {
|
|
66
|
+
await vscode.addRecommendedExtensions(app.directory, ['dbaeumer.vscode-eslint']);
|
|
67
|
+
task.title = 'Editor plugin recommendations added';
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
], { rendererSilent: environment.local.isUnitTest() });
|
|
71
|
+
await list.run();
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=eslint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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G,CAAC,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;gBAE5D,WAAW,CAAC,OAAO,CAAC,IAAI,GAAG,qCAAqC,CAAA;gBAEhE,WAAW,CAAC,QAAQ,GAAG,0BAA0B,CAAA;gBAEjD,MAAM,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;gBAEtD,IAAI,CAAC,KAAK,GAAG,sBAAsB,CAAA;YACrC,CAAC;SACF;QACD;YACE,KAAK,EAAE,sCAAsC;YAC7C,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YACzD,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;gBACtB,MAAM,MAAM,CAAC,wBAAwB,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,wBAAwB,CAAC,CAAC,CAAA;gBAChF,IAAI,CAAC,KAAK,GAAG,qCAAqC,CAAA;YACpD,CAAC;SACF;KACF,EACD,EAAC,cAAc,EAAE,WAAW,CAAC,KAAK,CAAC,UAAU,EAAE,EAAC,CACjD,CAAA;IACD,MAAM,IAAI,CAAC,GAAG,EAAE,CAAA;AAClB,CAAC","sourcesContent":["import {HydrogenApp} from '../models/hydrogen'\nimport {genericConfigurationFileNames} from '../constants'\nimport {ui, vscode, npm, file, dependency, path, error, environment} from '@shopify/cli-kit'\nimport stream from 'node:stream'\n\ninterface AddESlintOptions {\n app: HydrogenApp\n force: boolean\n install: boolean\n}\n\nexport async function addESLint({app, force, install}: AddESlintOptions) {\n const list = ui.newListr(\n [\n {\n title: 'Installing additional dependencies',\n skip: () => !install,\n task: async (_, task) => {\n const requiredDependencies = ['eslint', 'eslint-plugin-hydrogen', 'prettier', '@shopify/prettier-config']\n await dependency.addNPMDependenciesWithoutVersionIfNeeded(requiredDependencies, {\n dependencyManager: app.dependencyManager,\n type: 'prod',\n directory: app.directory,\n stderr: new stream.Writable({\n write(chunk, encoding, next) {\n task.output = chunk.toString()\n next()\n },\n }),\n stdout: new stream.Writable({\n write(chunk, encoding, next) {\n task.output = chunk.toString()\n next()\n },\n }),\n })\n task.title = 'Dependencies installed'\n },\n },\n\n {\n title: 'Adding ESLint configuration',\n task: async (_, task) => {\n const eslintConfigPath = path.join(app.directory, genericConfigurationFileNames.eslint)\n\n if (await file.exists(eslintConfigPath)) {\n if (force) {\n await file.remove(eslintConfigPath)\n } else {\n throw new error.Abort('ESLint config already exists.', 'Use --force to override existing config.')\n }\n }\n\n const extended = [`'plugin:hydrogen/recommended'`]\n\n if (app.language === 'TypeScript') {\n extended.push(`'plugin:hydrogen/typescript'`)\n }\n\n const eslintConfig = await file.format(\n ['module.exports = {', 'extends: [', `${extended.join(',')}`, ' ],', ' };'].join('\\n'),\n {path: genericConfigurationFileNames.eslint},\n )\n\n await file.write(eslintConfigPath, eslintConfig)\n\n task.title = 'ESLint configuration added'\n },\n },\n {\n title: 'Updating package.json',\n task: async (_, task) => {\n const packageJSON = await npm.readPackageJSON(app.directory)\n\n packageJSON.scripts.lint = `eslint --ext .js,.ts,.jsx,.tsx src/`\n\n packageJSON.prettier = '@shopify/prettier-config'\n\n await npm.writePackageJSON(app.directory, packageJSON)\n\n task.title = 'Package.json updated'\n },\n },\n {\n title: 'Adding editor plugin recommendations',\n skip: async () => !(await vscode.isVSCode(app.directory)),\n task: async (_, task) => {\n await vscode.addRecommendedExtensions(app.directory, ['dbaeumer.vscode-eslint'])\n task.title = 'Editor plugin recommendations added'\n },\n },\n ],\n {rendererSilent: environment.local.isUnitTest()},\n )\n await list.run()\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HydrogenApp } from '../models/hydrogen.js';
|
|
2
|
+
import { output } from '@shopify/cli-kit';
|
|
3
|
+
interface InfoOptions {
|
|
4
|
+
showPrivateData: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function info(app: HydrogenApp, { showPrivateData }: InfoOptions): output.Message;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { output, string, os } from '@shopify/cli-kit';
|
|
2
|
+
export function info(app, { showPrivateData }) {
|
|
3
|
+
const appInfo = new HydrogenAppInfo(app);
|
|
4
|
+
return appInfo.output({ showPrivateData });
|
|
5
|
+
}
|
|
6
|
+
const NOT_FOUND_TEXT = output.content `${output.token.italic('Not found')}`.value;
|
|
7
|
+
const NOT_CONFIGURED_TEXT = output.content `${output.token.italic('Not yet configured')}`.value;
|
|
8
|
+
class AppInfo {
|
|
9
|
+
constructor(app) {
|
|
10
|
+
this.app = app;
|
|
11
|
+
}
|
|
12
|
+
output({ showPrivateData }) {
|
|
13
|
+
const sections = [
|
|
14
|
+
this.projectSettingsSection(),
|
|
15
|
+
this.storefrontSettingsSection({ showPrivateData }),
|
|
16
|
+
this.eslintSection(),
|
|
17
|
+
this.systemInfoSection(),
|
|
18
|
+
];
|
|
19
|
+
return sections.map((sectionContents) => this.section(...sectionContents)).join('\n\n');
|
|
20
|
+
}
|
|
21
|
+
projectSettingsSection() {
|
|
22
|
+
const title = 'Your Project';
|
|
23
|
+
const lines = [
|
|
24
|
+
['Name', this.app.name],
|
|
25
|
+
['Project location', this.app.directory],
|
|
26
|
+
['Language', this.app.language],
|
|
27
|
+
];
|
|
28
|
+
const projectInfo = this.linesToColumns(lines);
|
|
29
|
+
return [title, projectInfo];
|
|
30
|
+
}
|
|
31
|
+
storefrontSettingsSection({ showPrivateData }) {
|
|
32
|
+
const errors = [];
|
|
33
|
+
const title = 'Storefront';
|
|
34
|
+
if (this.app.configuration.shopify && typeof this.app.configuration.shopify === 'function') {
|
|
35
|
+
return [title, 'Storefront settings defined as a function are not supported in this command.'];
|
|
36
|
+
}
|
|
37
|
+
const privateFields = showPrivateData ? ['storefrontToken'] : [];
|
|
38
|
+
const fields = [
|
|
39
|
+
'storeDomain',
|
|
40
|
+
'storefrontApiVersion',
|
|
41
|
+
...privateFields,
|
|
42
|
+
];
|
|
43
|
+
const storefrontInfo = this.configurationCheck(fields, this.app.configuration.shopify);
|
|
44
|
+
let errorContent = `\n${errors.map(this.formattedError).join('\n')}`;
|
|
45
|
+
if (errorContent.trim() === '')
|
|
46
|
+
errorContent = '';
|
|
47
|
+
return [title, `${this.linesToColumns(storefrontInfo)}${errorContent}`];
|
|
48
|
+
}
|
|
49
|
+
eslintSection() {
|
|
50
|
+
const errors = [];
|
|
51
|
+
const title = 'ESLint';
|
|
52
|
+
const dependencyResults = this.dependencyCheck(['eslint', 'eslint-plugin-hydrogen']);
|
|
53
|
+
if (this.app.nodeDependencies.eslint && !this.app.nodeDependencies['eslint-plugin-hydrogen']) {
|
|
54
|
+
errors.push('Run `yarn shopify add eslint` to install and configure eslint for hydrogen');
|
|
55
|
+
}
|
|
56
|
+
let errorContent = `\n${errors.map(this.formattedError).join('\n')}`;
|
|
57
|
+
if (errorContent.trim() === '')
|
|
58
|
+
errorContent = '';
|
|
59
|
+
return [title, `${this.linesToColumns(dependencyResults)}${errorContent}`];
|
|
60
|
+
}
|
|
61
|
+
configurationCheck(key, configObject = this.app.configuration) {
|
|
62
|
+
const keys = Array.isArray(key) ? key : [key];
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
const result = keys.reduce((acc, key) => {
|
|
66
|
+
const found = configObject[key];
|
|
67
|
+
if (typeof found === 'string') {
|
|
68
|
+
const result = [string.capitalize(key.toString()), found];
|
|
69
|
+
return [...acc, result];
|
|
70
|
+
}
|
|
71
|
+
const result = [key, NOT_CONFIGURED_TEXT];
|
|
72
|
+
return [...acc, result];
|
|
73
|
+
}, []);
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
dependencyCheck(dependency) {
|
|
77
|
+
const dependencies = Array.isArray(dependency) ? dependency : [dependency];
|
|
78
|
+
const result = dependencies.reduce((acc, dependency) => {
|
|
79
|
+
const found = this.app.nodeDependencies[dependency];
|
|
80
|
+
if (found) {
|
|
81
|
+
const result = [dependency, found];
|
|
82
|
+
return [...acc, result];
|
|
83
|
+
}
|
|
84
|
+
const result = [dependency, NOT_FOUND_TEXT];
|
|
85
|
+
return [...acc, result];
|
|
86
|
+
}, []);
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
formattedError(str) {
|
|
90
|
+
const [errorFirstLine, ...errorRemainingLines] = str.split('\n');
|
|
91
|
+
const errorLines = [`! ${errorFirstLine}`, ...errorRemainingLines.map((line) => ` ${line}`)];
|
|
92
|
+
return output.content `${output.token.errorText(errorLines.join('\n'))}`.value;
|
|
93
|
+
}
|
|
94
|
+
systemInfoSection() {
|
|
95
|
+
const title = 'Tooling and System';
|
|
96
|
+
const { platform, arch } = os.platformAndArch();
|
|
97
|
+
const lines = [
|
|
98
|
+
...this.dependencyCheck(['@shopify/hydrogen', '@shopify/cli-hydrogen', '@shopify/cli']),
|
|
99
|
+
['Package manager', this.app.dependencyManager],
|
|
100
|
+
['OS', `${platform}-${arch}`],
|
|
101
|
+
['Shell', process.env.SHELL || 'unknown'],
|
|
102
|
+
['Node.js version', process.version],
|
|
103
|
+
];
|
|
104
|
+
return [title, this.linesToColumns(lines)];
|
|
105
|
+
}
|
|
106
|
+
linesToColumns(lines) {
|
|
107
|
+
const widths = [];
|
|
108
|
+
for (let i = 0; lines[0] && i < lines[0].length; i++) {
|
|
109
|
+
const columnRows = lines.map((line) => line[i]);
|
|
110
|
+
widths.push(Math.max(...columnRows.map((row) => output.unstyled(row).length)));
|
|
111
|
+
}
|
|
112
|
+
const paddedLines = lines
|
|
113
|
+
.map((line) => {
|
|
114
|
+
return line
|
|
115
|
+
.map((col, index) => {
|
|
116
|
+
return `${col}${' '.repeat(widths[index] - output.unstyled(col).length)}`;
|
|
117
|
+
})
|
|
118
|
+
.join(' ')
|
|
119
|
+
.trimEnd();
|
|
120
|
+
})
|
|
121
|
+
.join('\n');
|
|
122
|
+
return paddedLines;
|
|
123
|
+
}
|
|
124
|
+
section(title, body) {
|
|
125
|
+
const formattedTitle = `${title.toUpperCase()}${' '.repeat(35 - title.length)}`;
|
|
126
|
+
return output.content `${output.token.heading(formattedTitle)}\n${body}`.value;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
class HydrogenAppInfo extends AppInfo {
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"info.js","sourceRoot":"","sources":["../../../src/cli/services/info.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAC,MAAM,kBAAkB,CAAA;AAMnD,MAAM,UAAU,IAAI,CAAC,GAAgB,EAAE,EAAC,eAAe,EAAc;IACnE,MAAM,OAAO,GAAG,IAAI,eAAe,CAAC,GAAG,CAAC,CAAA;IAExC,OAAO,OAAO,CAAC,MAAM,CAAC,EAAC,eAAe,EAAC,CAAC,CAAA;AAC1C,CAAC;AAED,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAA,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,KAAK,CAAA;AAChF,MAAM,mBAAmB,GAAG,MAAM,CAAC,OAAO,CAAA,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,oBAAoB,CAAC,EAAE,CAAC,KAAK,CAAA;AAE9F,MAAM,OAAO;IAEX,YAAY,GAAgB;QAC1B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED,MAAM,CAAC,EAAC,eAAe,EAAc;QACnC,MAAM,QAAQ,GAAuB;YACnC,IAAI,CAAC,sBAAsB,EAAE;YAC7B,IAAI,CAAC,yBAAyB,CAAC,EAAC,eAAe,EAAC,CAAC;YACjD,IAAI,CAAC,aAAa,EAAE;YACpB,IAAI,CAAC,iBAAiB,EAAE;SACzB,CAAA;QACD,OAAO,QAAQ,CAAC,GA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AAC,IAAI,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;SAC/E;QACD,MAAM,WAAW,GAAG,KAAK;aACtB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;YACZ,OAAO,IAAI;iBACR,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;gBAClB,OAAO,GAAG,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAA;YAC3E,CAAC,CAAC;iBACD,IAAI,CAAC,KAAK,CAAC;iBACX,OAAO,EAAE,CAAA;QACd,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAA;QACb,OAAO,WAAW,CAAA;IACpB,CAAC;IAED,OAAO,CAAC,KAAa,EAAE,IAAY;QACjC,MAAM,cAAc,GAAG,GAAG,KAAK,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,CAAA;QAC/E,OAAO,MAAM,CAAC,OAAO,CAAA,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,IAAI,EAAE,CAAC,KAAK,CAAA;IAC/E,CAAC;CACF;AAED,MAAM,eAAgB,SAAQ,OAAO;CAAG","sourcesContent":["import {HydrogenApp} from '../models/hydrogen.js'\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport {HydrogenConfig} from '@shopify/hydrogen/config'\nimport {output, string, os} from '@shopify/cli-kit'\n\ninterface InfoOptions {\n showPrivateData: boolean\n}\n\nexport function info(app: HydrogenApp, {showPrivateData}: InfoOptions): output.Message {\n const appInfo = new HydrogenAppInfo(app)\n\n return appInfo.output({showPrivateData})\n}\n\nconst NOT_FOUND_TEXT = output.content`${output.token.italic('Not found')}`.value\nconst NOT_CONFIGURED_TEXT = output.content`${output.token.italic('Not yet configured')}`.value\n\nclass AppInfo {\n private app: HydrogenApp\n constructor(app: HydrogenApp) {\n this.app = app\n }\n\n output({showPrivateData}: InfoOptions): string {\n const sections: [string, string][] = [\n this.projectSettingsSection(),\n this.storefrontSettingsSection({showPrivateData}),\n this.eslintSection(),\n this.systemInfoSection(),\n ]\n return sections.map((sectionContents: [string, string]) => this.section(...sectionContents)).join('\\n\\n')\n }\n\n projectSettingsSection(): [string, string] {\n const title = 'Your Project'\n\n const lines = [\n ['Name', this.app.name],\n ['Project location', this.app.directory],\n ['Language', this.app.language],\n ]\n\n const projectInfo = this.linesToColumns(lines)\n return [title, projectInfo]\n }\n\n storefrontSettingsSection({showPrivateData}: InfoOptions): [string, string] {\n const errors: string[] = []\n const title = 'Storefront'\n\n if (this.app.configuration.shopify && typeof this.app.configuration.shopify === 'function') {\n return [title, 'Storefront settings defined as a function are not supported in this command.']\n }\n\n const privateFields = showPrivateData ? ['storefrontToken'] : []\n\n const fields = [\n 'storeDomain',\n 'storefrontApiVersion',\n ...privateFields,\n ] as unknown as keyof HydrogenConfig['shopify'][]\n\n const storefrontInfo = this.configurationCheck(fields, this.app.configuration.shopify)\n\n let errorContent = `\\n${errors.map(this.formattedError).join('\\n')}`\n\n if (errorContent.trim() === '') errorContent = ''\n\n return [title, `${this.linesToColumns(storefrontInfo)}${errorContent}`]\n }\n\n eslintSection(): [string, string] {\n const errors: string[] = []\n const title = 'ESLint'\n const dependencyResults = this.dependencyCheck(['eslint', 'eslint-plugin-hydrogen'])\n\n if (this.app.nodeDependencies.eslint && !this.app.nodeDependencies['eslint-plugin-hydrogen']) {\n errors.push('Run `yarn shopify add eslint` to install and configure eslint for hydrogen')\n }\n\n let errorContent = `\\n${errors.map(this.formattedError).join('\\n')}`\n\n if (errorContent.trim() === '') errorContent = ''\n\n return [title, `${this.linesToColumns(dependencyResults)}${errorContent}`]\n }\n\n configurationCheck(\n key: keyof HydrogenConfig | keyof HydrogenConfig[],\n configObject: HydrogenConfig | HydrogenConfig['shopify'] = this.app.configuration,\n ): string[][] {\n const keys = Array.isArray(key) ? key : [key]\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const result = keys.reduce((acc, key) => {\n const found = configObject[key as keyof HydrogenConfig & keyof HydrogenConfig['shopify']]\n\n if (typeof found === 'string') {\n const result = [string.capitalize(key.toString()), found]\n return [...acc, result]\n }\n\n const result = [key, NOT_CONFIGURED_TEXT]\n return [...acc, result]\n }, [])\n\n return result\n }\n\n dependencyCheck(dependency: string | string[]): string[][] {\n const dependencies = Array.isArray(dependency) ? dependency : [dependency]\n\n const result = dependencies.reduce<string[][]>((acc, dependency) => {\n const found = this.app.nodeDependencies[dependency]\n if (found) {\n const result = [dependency, found]\n return [...acc, result]\n }\n\n const result = [dependency, NOT_FOUND_TEXT]\n return [...acc, result]\n }, [])\n\n return result\n }\n\n formattedError(str: string): string {\n const [errorFirstLine, ...errorRemainingLines] = str.split('\\n')\n const errorLines = [`! ${errorFirstLine}`, ...errorRemainingLines.map((line) => ` ${line}`)]\n return output.content`${output.token.errorText(errorLines.join('\\n'))}`.value\n }\n\n systemInfoSection(): [string, string] {\n const title = 'Tooling and System'\n const {platform, arch} = os.platformAndArch()\n const lines: string[][] = [\n ...this.dependencyCheck(['@shopify/hydrogen', '@shopify/cli-hydrogen', '@shopify/cli']),\n ['Package manager', this.app.dependencyManager],\n ['OS', `${platform}-${arch}`],\n ['Shell', process.env.SHELL || 'unknown'],\n ['Node.js version', process.version],\n ]\n\n return [title, this.linesToColumns(lines)]\n }\n\n linesToColumns(lines: string[][]): string {\n const widths: number[] = []\n for (let i = 0; lines[0] && i < lines[0].length; i++) {\n const columnRows = lines.map((line) => line[i])\n widths.push(Math.max(...columnRows.map((row) => output.unstyled(row).length)))\n }\n const paddedLines = lines\n .map((line) => {\n return line\n .map((col, index) => {\n return `${col}${' '.repeat(widths[index] - output.unstyled(col).length)}`\n })\n .join(' ')\n .trimEnd()\n })\n .join('\\n')\n return paddedLines\n }\n\n section(title: string, body: string): string {\n const formattedTitle = `${title.toUpperCase()}${' '.repeat(35 - title.length)}`\n return output.content`${output.token.heading(formattedTitle)}\\n${body}`.value\n }\n}\n\nclass HydrogenAppInfo extends AppInfo {}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { error } from '@shopify/cli-kit';
|
|
2
|
+
interface PreviewOptions {
|
|
3
|
+
directory: string;
|
|
4
|
+
port: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function previewInNode({ directory, port }: PreviewOptions): Promise<void>;
|
|
7
|
+
export declare function previewInWorker({ directory, port }: PreviewOptions): Promise<void>;
|
|
8
|
+
export declare const OxygenPreviewExecutableNotFound: error.Bug;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { path, error, system, file, output } from '@shopify/cli-kit';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
export async function previewInNode({ directory, port }) {
|
|
4
|
+
const buildOutputPath = await path.resolve(directory, 'dist/node');
|
|
5
|
+
if (!(await file.exists(buildOutputPath))) {
|
|
6
|
+
output.info(output.content `Couldn’t find a Node.js server build for this project. Running ${output.token.packagejsonScript('yarn', 'shopify hydrogen build', '--target=node')} to create one.`);
|
|
7
|
+
await system.exec('yarn', ['shopify', 'hydrogen', 'build', '--target=node'], {
|
|
8
|
+
cwd: directory,
|
|
9
|
+
stdout: process.stdout,
|
|
10
|
+
stderr: process.stderr,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
await system.exec('node', ['--enable-source-maps', buildOutputPath], {
|
|
14
|
+
env: { PORT: `${port}` },
|
|
15
|
+
cwd: directory,
|
|
16
|
+
stdout: process.stdout,
|
|
17
|
+
stderr: process.stderr,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export async function previewInWorker({ directory, port }) {
|
|
21
|
+
const config = {
|
|
22
|
+
port,
|
|
23
|
+
workerFile: 'dist/worker/index.js',
|
|
24
|
+
assetsDir: 'dist/client',
|
|
25
|
+
buildCommand: 'yarn build',
|
|
26
|
+
modules: true,
|
|
27
|
+
watch: true,
|
|
28
|
+
buildWatchPaths: ['./src'],
|
|
29
|
+
autoReload: true,
|
|
30
|
+
};
|
|
31
|
+
await file.write(path.resolve(directory, 'mini-oxygen.config.json'), JSON.stringify(config, null, 2));
|
|
32
|
+
function cleanUp(options) {
|
|
33
|
+
if (options.exit) {
|
|
34
|
+
file.remove(path.resolve(directory, 'mini-oxygen.config.json'));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
process.on('SIGINT', cleanUp.bind(null, { exit: true }));
|
|
38
|
+
const executable = await oxygenPreviewExecutable();
|
|
39
|
+
await system.exec(executable, [], {
|
|
40
|
+
env: { NODE_OPTIONS: '--experimental-vm-modules' },
|
|
41
|
+
cwd: directory,
|
|
42
|
+
stdout: process.stdout,
|
|
43
|
+
stderr: process.stderr,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export const OxygenPreviewExecutableNotFound = new error.Bug('Could not locate the executable file to run Oxygen locally.');
|
|
47
|
+
async function oxygenPreviewExecutable() {
|
|
48
|
+
const cwd = path.dirname(fileURLToPath(import.meta.url));
|
|
49
|
+
const executablePath = await path.findUp('node_modules/.bin/oxygen-preview', { type: 'file', cwd });
|
|
50
|
+
if (!executablePath) {
|
|
51
|
+
throw OxygenPreviewExecutableNotFound;
|
|
52
|
+
}
|
|
53
|
+
return executablePath;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=preview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview.js","sourceRoot":"","sources":["../../../src/cli/services/preview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,E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C","sourcesContent":["import {path, error, system, file, output} from '@shopify/cli-kit'\nimport {fileURLToPath} from 'url'\n\ninterface PreviewOptions {\n directory: string\n port: number\n}\n\nexport async function previewInNode({directory, port}: PreviewOptions) {\n const buildOutputPath = await path.resolve(directory, 'dist/node')\n\n if (!(await file.exists(buildOutputPath))) {\n output.info(\n output.content`Couldn’t find a Node.js server build for this project. Running ${output.token.packagejsonScript(\n 'yarn',\n 'shopify hydrogen build',\n '--target=node',\n )} to create one.`,\n )\n\n await system.exec('yarn', ['shopify', 'hydrogen', 'build', '--target=node'], {\n cwd: directory,\n stdout: process.stdout,\n stderr: process.stderr,\n })\n }\n\n await system.exec('node', ['--enable-source-maps', buildOutputPath], {\n env: {PORT: `${port}`},\n cwd: directory,\n stdout: process.stdout,\n stderr: process.stderr,\n })\n}\n\nexport async function previewInWorker({directory, port}: PreviewOptions) {\n const config = {\n port,\n workerFile: 'dist/worker/index.js',\n assetsDir: 'dist/client',\n buildCommand: 'yarn build',\n modules: true,\n watch: true,\n buildWatchPaths: ['./src'],\n autoReload: true,\n }\n\n await file.write(path.resolve(directory, 'mini-oxygen.config.json'), JSON.stringify(config, null, 2))\n\n function cleanUp(options: {exit: boolean}) {\n if (options.exit) {\n file.remove(path.resolve(directory, 'mini-oxygen.config.json'))\n }\n }\n\n process.on('SIGINT', cleanUp.bind(null, {exit: true}))\n\n const executable = await oxygenPreviewExecutable()\n\n await system.exec(executable, [], {\n env: {NODE_OPTIONS: '--experimental-vm-modules'},\n cwd: directory,\n stdout: process.stdout,\n stderr: process.stderr,\n })\n}\n\nexport const OxygenPreviewExecutableNotFound = new error.Bug(\n 'Could not locate the executable file to run Oxygen locally.',\n)\n\nasync function oxygenPreviewExecutable(): Promise<string> {\n const cwd = path.dirname(fileURLToPath(import.meta.url))\n const executablePath = await path.findUp('node_modules/.bin/oxygen-preview', {type: 'file', cwd})\n if (!executablePath) {\n throw OxygenPreviewExecutableNotFound\n }\n return executablePath\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { HydrogenApp } from '../models/hydrogen.js';
|
|
2
|
+
interface AddTailwindOptions {
|
|
3
|
+
app: HydrogenApp;
|
|
4
|
+
force: boolean;
|
|
5
|
+
directory: string;
|
|
6
|
+
install: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function addTailwind({ app, force, install, directory }: AddTailwindOptions): Promise<void>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ui, vscode, system, path, file, error, dependency } from '@shopify/cli-kit';
|
|
2
|
+
import stream from 'node:stream';
|
|
3
|
+
const tailwindImports = [
|
|
4
|
+
"@import 'tailwindcss/base';",
|
|
5
|
+
"@import 'tailwindcss/components';",
|
|
6
|
+
"@import 'tailwindcss/utilities';",
|
|
7
|
+
];
|
|
8
|
+
const tailwindImportsExist = (indexCSS) => tailwindImports.map((el) => new RegExp(el)).every((tailwindDirective) => tailwindDirective.test(indexCSS));
|
|
9
|
+
export async function addTailwind({ app, force, install, directory }) {
|
|
10
|
+
const list = ui.newListr([
|
|
11
|
+
{
|
|
12
|
+
title: 'Installing additional dependencies',
|
|
13
|
+
skip: () => !install,
|
|
14
|
+
task: async (_, task) => {
|
|
15
|
+
const requiredDependencies = ['postcss', 'postcss-loader', 'tailwindcss', 'autoprefixer'];
|
|
16
|
+
await dependency.addNPMDependenciesWithoutVersionIfNeeded(requiredDependencies, {
|
|
17
|
+
dependencyManager: app.dependencyManager,
|
|
18
|
+
type: 'prod',
|
|
19
|
+
directory: app.directory,
|
|
20
|
+
stderr: new stream.Writable({
|
|
21
|
+
write(chunk, encoding, next) {
|
|
22
|
+
task.output = chunk.toString();
|
|
23
|
+
next();
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
stdout: new stream.Writable({
|
|
27
|
+
write(chunk, encoding, next) {
|
|
28
|
+
task.output = chunk.toString();
|
|
29
|
+
next();
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
33
|
+
task.title = 'Dependencies installed';
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
title: 'Adding PostCSS configuration',
|
|
38
|
+
task: async (_, task) => {
|
|
39
|
+
const postCSSConfiguration = path.join(directory, 'postcss.config.js');
|
|
40
|
+
if (await file.exists(postCSSConfiguration)) {
|
|
41
|
+
if (force) {
|
|
42
|
+
await file.remove(postCSSConfiguration);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
throw new error.Abort('PostCSS config already exists.\nUse --force to override existing config.');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const postCSSConfig = await file.format(['module.exports = {', 'plugins: {', 'tailwindcss: {},', 'autoprefixer: {},', '},', ' };'].join('\n'), { path: 'postcss.config.js' });
|
|
49
|
+
await file.write(postCSSConfiguration, postCSSConfig);
|
|
50
|
+
task.title = 'PostCSS configuration added';
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
title: 'Initializing Tailwind CSS...',
|
|
55
|
+
task: async (_, task) => {
|
|
56
|
+
const tailwindConfigurationPath = path.join(directory, 'tailwind.config.js');
|
|
57
|
+
if (await file.exists(tailwindConfigurationPath)) {
|
|
58
|
+
if (force) {
|
|
59
|
+
await file.remove(tailwindConfigurationPath);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
throw new error.Abort('Tailwind config already exists.\nUse --force to override existing config.');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
await system.exec(app.dependencyManager, ['tailwindcss', 'init', tailwindConfigurationPath], {
|
|
66
|
+
cwd: directory,
|
|
67
|
+
});
|
|
68
|
+
await replace('content: []', "content: ['./index.html', './src/**/*.{js,jsx,ts,tsx}']", tailwindConfigurationPath);
|
|
69
|
+
task.title = 'Tailwind configuration added';
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
title: 'Importing Tailwind CSS in index.css',
|
|
74
|
+
task: async (_ctx, task) => {
|
|
75
|
+
const indexCSSPath = path.join(directory, 'src', 'index.css');
|
|
76
|
+
const indexCSS = await file.read(indexCSSPath);
|
|
77
|
+
if (tailwindImportsExist(indexCSS)) {
|
|
78
|
+
task.skip('Imports already exist in index.css');
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const newIndexCSS = tailwindImports.join('\n') + indexCSS;
|
|
82
|
+
await file.write(indexCSSPath, newIndexCSS);
|
|
83
|
+
}
|
|
84
|
+
task.title = 'Tailwind imports added';
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
title: 'Adding editor plugin recommendations',
|
|
89
|
+
task: async (_, task) => {
|
|
90
|
+
await vscode.addRecommendedExtensions(directory, ['csstools.postcss', 'bradlc.vscode-tailwindcss']);
|
|
91
|
+
task.title = 'Editor plugin recommendations added';
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
]);
|
|
95
|
+
await list.run();
|
|
96
|
+
}
|
|
97
|
+
async function replace(find, replace, filepath) {
|
|
98
|
+
const original = await file.read(filepath);
|
|
99
|
+
const modified = original.replace(find, replace);
|
|
100
|
+
await file.write(filepath, modified);
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=tailwind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tailwind.js","sourceRoot":"","sources":["../../../src/cli/services/tailwind.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAC,MAAM,kBAAkB,CAAA;AAClF,OAAO,MAAM,MAAM,aAAa,CAAA;AAShC,MAAM,eAAe,GAAG;IACtB,6BAA6B;IAC7B,mCAAmC;IACnC,kCAAkC;CACnC,CAAA;AAED,MAAM,oBAAoB,GAAG,CAAC,QAAgB,EAAE,EAAE,CAChD,eAAe,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,MAAM,C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C1C,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAChD,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;AACtC,CAAC","sourcesContent":["import {HydrogenApp} from '../models/hydrogen.js'\nimport {ui, vscode, system, path, file, error, dependency} from '@shopify/cli-kit'\nimport stream from 'node:stream'\n\ninterface AddTailwindOptions {\n app: HydrogenApp\n force: boolean\n directory: string\n install: boolean\n}\n\nconst tailwindImports = [\n \"@import 'tailwindcss/base';\",\n \"@import 'tailwindcss/components';\",\n \"@import 'tailwindcss/utilities';\",\n]\n\nconst tailwindImportsExist = (indexCSS: string) =>\n tailwindImports.map((el) => new RegExp(el)).every((tailwindDirective) => tailwindDirective.test(indexCSS))\n\nexport async function addTailwind({app, force, install, directory}: AddTailwindOptions) {\n const list = ui.newListr([\n {\n title: 'Installing additional dependencies',\n skip: () => !install,\n task: async (_, task) => {\n const requiredDependencies = ['postcss', 'postcss-loader', 'tailwindcss', 'autoprefixer']\n await dependency.addNPMDependenciesWithoutVersionIfNeeded(requiredDependencies, {\n dependencyManager: app.dependencyManager,\n type: 'prod',\n directory: app.directory,\n stderr: new stream.Writable({\n write(chunk, encoding, next) {\n task.output = chunk.toString()\n next()\n },\n }),\n stdout: new stream.Writable({\n write(chunk, encoding, next) {\n task.output = chunk.toString()\n next()\n },\n }),\n })\n task.title = 'Dependencies installed'\n },\n },\n\n {\n title: 'Adding PostCSS configuration',\n task: async (_, task) => {\n const postCSSConfiguration = path.join(directory, 'postcss.config.js')\n\n if (await file.exists(postCSSConfiguration)) {\n if (force) {\n await file.remove(postCSSConfiguration)\n } else {\n throw new error.Abort('PostCSS config already exists.\\nUse --force to override existing config.')\n }\n }\n\n const postCSSConfig = await file.format(\n ['module.exports = {', 'plugins: {', 'tailwindcss: {},', 'autoprefixer: {},', '},', ' };'].join('\\n'),\n {path: 'postcss.config.js'},\n )\n\n await file.write(postCSSConfiguration, postCSSConfig)\n\n task.title = 'PostCSS configuration added'\n },\n },\n\n {\n title: 'Initializing Tailwind CSS...',\n task: async (_, task) => {\n const tailwindConfigurationPath = path.join(directory, 'tailwind.config.js')\n\n if (await file.exists(tailwindConfigurationPath)) {\n if (force) {\n await file.remove(tailwindConfigurationPath)\n } else {\n throw new error.Abort('Tailwind config already exists.\\nUse --force to override existing config.')\n }\n }\n\n await system.exec(app.dependencyManager, ['tailwindcss', 'init', tailwindConfigurationPath], {\n cwd: directory,\n })\n\n await replace(\n 'content: []',\n \"content: ['./index.html', './src/**/*.{js,jsx,ts,tsx}']\",\n tailwindConfigurationPath,\n )\n\n task.title = 'Tailwind configuration added'\n },\n },\n {\n title: 'Importing Tailwind CSS in index.css',\n task: async (_ctx, task) => {\n const indexCSSPath = path.join(directory, 'src', 'index.css')\n const indexCSS = await file.read(indexCSSPath)\n\n if (tailwindImportsExist(indexCSS)) {\n task.skip('Imports already exist in index.css')\n } else {\n const newIndexCSS = tailwindImports.join('\\n') + indexCSS\n\n await file.write(indexCSSPath, newIndexCSS)\n }\n\n task.title = 'Tailwind imports added'\n },\n },\n {\n title: 'Adding editor plugin recommendations',\n task: async (_, task) => {\n await vscode.addRecommendedExtensions(directory, ['csstools.postcss', 'bradlc.vscode-tailwindcss'])\n task.title = 'Editor plugin recommendations added'\n },\n },\n ])\n await list.run()\n}\n\nasync function replace(find: string | RegExp, replace: string, filepath: string) {\n const original = await file.read(filepath)\n const modified = original.replace(find, replace)\n await file.write(filepath, modified)\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
/* eslint-enable @typescript-eslint/ban-ts-comment */
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
const { loadConfig } = require('@shopify/hydrogen/load-config');
|
|
5
|
+
export { loadConfig };
|
|
6
|
+
//# sourceMappingURL=load-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-config.js","sourceRoot":"","sources":["../../../src/cli/utilities/load-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,QAAQ,CAAA;AAIpC,qDAAqD;AAErD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC9C,MAAM,EAAC,UAAU,EAAC,GAAG,OAAO,CAAC,+BAA+B,CAE3D,CAAA;AAED,OAAO,EAAC,UAAU,EAAC,CAAA","sourcesContent":["import {createRequire} from 'module'\n/* eslint-disable @typescript-eslint/ban-ts-comment */\n// @ts-ignore\nimport type {HydrogenConfig} from '@shopify/hydrogen/config'\n/* eslint-enable @typescript-eslint/ban-ts-comment */\n\nconst require = createRequire(import.meta.url)\nconst {loadConfig} = require('@shopify/hydrogen/load-config') as {\n loadConfig: (options: {root: string}) => Promise<HydrogenConfig>\n}\n\nexport {loadConfig}\n"]}
|