@shopify/cli-hydrogen 3.34.0 → 3.36.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/cli/commands/hydrogen/add/eslint.js +2 -2
- package/dist/cli/commands/hydrogen/add/eslint.js.map +1 -1
- package/dist/cli/commands/hydrogen/add/tailwind.js +2 -2
- package/dist/cli/commands/hydrogen/add/tailwind.js.map +1 -1
- package/dist/cli/commands/hydrogen/build.js +2 -2
- package/dist/cli/commands/hydrogen/build.js.map +1 -1
- package/dist/cli/commands/hydrogen/deploy.js +3 -2
- package/dist/cli/commands/hydrogen/deploy.js.map +1 -1
- package/dist/cli/commands/hydrogen/dev.js +2 -2
- package/dist/cli/commands/hydrogen/dev.js.map +1 -1
- package/dist/cli/commands/hydrogen/info.js +3 -2
- package/dist/cli/commands/hydrogen/info.js.map +1 -1
- package/dist/cli/commands/hydrogen/preview.js +3 -3
- package/dist/cli/commands/hydrogen/preview.js.map +1 -1
- package/dist/cli/models/hydrogen.js +11 -9
- package/dist/cli/models/hydrogen.js.map +1 -1
- package/dist/cli/services/build/check-lockfile.js +6 -4
- package/dist/cli/services/build/check-lockfile.js.map +1 -1
- package/dist/cli/services/deploy/config.js +18 -13
- package/dist/cli/services/deploy/config.js.map +1 -1
- package/dist/cli/services/deploy/upload.js +9 -8
- package/dist/cli/services/deploy/upload.js.map +1 -1
- package/dist/cli/services/eslint.js +12 -9
- package/dist/cli/services/eslint.js.map +1 -1
- package/dist/cli/services/preview.js +13 -7
- package/dist/cli/services/preview.js.map +1 -1
- package/dist/cli/services/tailwind.js +16 -14
- package/dist/cli/services/tailwind.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +2 -2
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { genericConfigurationFileNames } from '../constants.js';
|
|
2
|
-
import { ui,
|
|
3
|
-
import { addNPMDependenciesWithoutVersionIfNeeded } from '@shopify/cli-kit/node/node-package-manager';
|
|
2
|
+
import { ui, error } from '@shopify/cli-kit';
|
|
3
|
+
import { addNPMDependenciesWithoutVersionIfNeeded, findUpAndReadPackageJson, writePackageJSON, } from '@shopify/cli-kit/node/node-package-manager';
|
|
4
4
|
import { addRecommendedExtensions, isVSCode } from '@shopify/cli-kit/node/vscode';
|
|
5
5
|
import { isUnitTest } from '@shopify/cli-kit/node/environment/local';
|
|
6
|
+
import { writeFile, fileExists, removeFile, fileContentPrettyFormat } from '@shopify/cli-kit/node/fs';
|
|
7
|
+
import { joinPath } from '@shopify/cli-kit/node/path';
|
|
6
8
|
import stream from 'stream';
|
|
7
9
|
export async function addESLint({ app, force, install }) {
|
|
8
10
|
const list = ui.newListr([
|
|
@@ -34,10 +36,10 @@ export async function addESLint({ app, force, install }) {
|
|
|
34
36
|
{
|
|
35
37
|
title: 'Adding ESLint configuration',
|
|
36
38
|
task: async (_, task) => {
|
|
37
|
-
const eslintConfigPath =
|
|
38
|
-
if (await
|
|
39
|
+
const eslintConfigPath = joinPath(app.directory, genericConfigurationFileNames.eslint);
|
|
40
|
+
if (await fileExists(eslintConfigPath)) {
|
|
39
41
|
if (force) {
|
|
40
|
-
await
|
|
42
|
+
await removeFile(eslintConfigPath);
|
|
41
43
|
}
|
|
42
44
|
else {
|
|
43
45
|
throw new error.Abort('ESLint config already exists.', 'Use --force to override existing config.');
|
|
@@ -47,18 +49,19 @@ export async function addESLint({ app, force, install }) {
|
|
|
47
49
|
if (app.language === 'TypeScript') {
|
|
48
50
|
extended.push(`'plugin:hydrogen/typescript'`);
|
|
49
51
|
}
|
|
50
|
-
const eslintConfig = await
|
|
51
|
-
await
|
|
52
|
+
const eslintConfig = await fileContentPrettyFormat(['module.exports = {', 'extends: [', `${extended.join(',')}`, ' ],', ' };'].join('\n'), { path: genericConfigurationFileNames.eslint });
|
|
53
|
+
await writeFile(eslintConfigPath, eslintConfig);
|
|
52
54
|
task.title = 'ESLint configuration added';
|
|
53
55
|
},
|
|
54
56
|
},
|
|
55
57
|
{
|
|
56
58
|
title: 'Updating package.json',
|
|
57
59
|
task: async (_, task) => {
|
|
58
|
-
const packageJSON = await
|
|
60
|
+
const packageJSON = (await findUpAndReadPackageJson(app.directory)).content;
|
|
61
|
+
packageJSON.scripts = packageJSON.scripts || {};
|
|
59
62
|
packageJSON.scripts.lint = `eslint --ext .js,.ts,.jsx,.tsx src/`;
|
|
60
63
|
packageJSON.prettier = '@shopify/prettier-config';
|
|
61
|
-
await
|
|
64
|
+
await writePackageJSON(app.directory, packageJSON);
|
|
62
65
|
task.title = 'Package.json updated';
|
|
63
66
|
},
|
|
64
67
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eslint.js","sourceRoot":"","sources":["../../../src/cli/services/eslint.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,6BAA6B,EAAC,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAC,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"eslint.js","sourceRoot":"","sources":["../../../src/cli/services/eslint.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,6BAA6B,EAAC,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAC,EAAE,EAAE,KAAK,EAAC,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EACL,wCAAwC,EACxC,wBAAwB,EACxB,gBAAgB,GACjB,MAAM,4CAA4C,CAAA;AACnD,OAAO,EAAC,wBAAwB,EAAE,QAAQ,EAAC,MAAM,8BAA8B,CAAA;AAC/E,OAAO,EAAC,UAAU,EAAC,MAAM,yCAAyC,CAAA;AAClE,OAAO,EAAC,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,uBAAuB,EAAC,MAAM,0BAA0B,CAAA;AACnG,OAAO,EAAC,QAAQ,EAAC,MAAM,4BAA4B,CAAA;AACnD,OAAO,MAAM,MAAM,QAAQ,CAAA;AAQ3B,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,EAAC,GAAG,EAAE,KAA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AI,EAAE,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YAClD,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;gBACtB,MAAM,wBAAwB,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,wBAAwB,CAAC,CAAC,CAAA;gBACzE,IAAI,CAAC,KAAK,GAAG,qCAAqC,CAAA;YACpD,CAAC;SACF;KACF,EACD,EAAC,cAAc,EAAE,UAAU,EAAE,EAAC,CAC/B,CAAA;IACD,MAAM,IAAI,CAAC,GAAG,EAAE,CAAA;AAClB,CAAC","sourcesContent":["import {HydrogenApp} from '../models/hydrogen.js'\nimport {genericConfigurationFileNames} from '../constants.js'\nimport {ui, error} from '@shopify/cli-kit'\nimport {\n addNPMDependenciesWithoutVersionIfNeeded,\n findUpAndReadPackageJson,\n writePackageJSON,\n} from '@shopify/cli-kit/node/node-package-manager'\nimport {addRecommendedExtensions, isVSCode} from '@shopify/cli-kit/node/vscode'\nimport {isUnitTest} from '@shopify/cli-kit/node/environment/local'\nimport {writeFile, fileExists, removeFile, fileContentPrettyFormat} from '@shopify/cli-kit/node/fs'\nimport {joinPath} from '@shopify/cli-kit/node/path'\nimport stream from '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 addNPMDependenciesWithoutVersionIfNeeded(requiredDependencies, {\n packageManager: app.packageManager,\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 = joinPath(app.directory, genericConfigurationFileNames.eslint)\n\n if (await fileExists(eslintConfigPath)) {\n if (force) {\n await removeFile(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 fileContentPrettyFormat(\n ['module.exports = {', 'extends: [', `${extended.join(',')}`, ' ],', ' };'].join('\\n'),\n {path: genericConfigurationFileNames.eslint},\n )\n\n await writeFile(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 findUpAndReadPackageJson(app.directory)).content\n packageJSON.scripts = packageJSON.scripts || {}\n packageJSON.scripts.lint = `eslint --ext .js,.ts,.jsx,.tsx src/`\n\n packageJSON.prettier = '@shopify/prettier-config'\n\n await writePackageJSON(app.directory, packageJSON)\n\n task.title = 'Package.json updated'\n },\n },\n {\n title: 'Adding editor plugin recommendations',\n skip: async () => !(await isVSCode(app.directory)),\n task: async (_, task) => {\n await addRecommendedExtensions(app.directory, ['dbaeumer.vscode-eslint'])\n task.title = 'Editor plugin recommendations added'\n },\n },\n ],\n {rendererSilent: isUnitTest()},\n )\n await list.run()\n}\n"]}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { error, output } from '@shopify/cli-kit';
|
|
2
2
|
import { readAndParseDotEnv } from '@shopify/cli-kit/node/dot-env';
|
|
3
|
+
import { fileExists, removeFileSync, writeFile, findPathUp } from '@shopify/cli-kit/node/fs';
|
|
3
4
|
import { exec } from '@shopify/cli-kit/node/system';
|
|
5
|
+
import { resolvePath, dirname } from '@shopify/cli-kit/node/path';
|
|
4
6
|
import { fileURLToPath } from 'url';
|
|
5
7
|
export async function previewInNode({ directory, port }) {
|
|
6
|
-
const buildOutputPath = await
|
|
7
|
-
if (!(await
|
|
8
|
+
const buildOutputPath = await resolvePath(directory, 'dist/node');
|
|
9
|
+
if (!(await fileExists(buildOutputPath))) {
|
|
8
10
|
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.`);
|
|
9
11
|
await exec('yarn', ['shopify', 'hydrogen', 'build', '--target=node'], {
|
|
10
12
|
cwd: directory,
|
|
@@ -31,10 +33,10 @@ export async function previewInWorker({ directory, port, envPath }) {
|
|
|
31
33
|
autoReload: true,
|
|
32
34
|
...(envPath && (await parseEnvPath(envPath))),
|
|
33
35
|
};
|
|
34
|
-
await
|
|
36
|
+
await writeFile(resolvePath(directory, 'mini-oxygen.config.json'), JSON.stringify(config, null, 2));
|
|
35
37
|
function cleanUp(options) {
|
|
36
38
|
if (options.exit) {
|
|
37
|
-
|
|
39
|
+
removeFileSync(resolvePath(directory, 'mini-oxygen.config.json'));
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
async function parseEnvPath(envPath) {
|
|
@@ -54,8 +56,12 @@ export async function previewInWorker({ directory, port, envPath }) {
|
|
|
54
56
|
}
|
|
55
57
|
export const OxygenPreviewExecutableNotFound = new error.Bug('Could not locate the executable file to run Oxygen locally.');
|
|
56
58
|
async function oxygenPreviewExecutable() {
|
|
57
|
-
const cwd =
|
|
58
|
-
const executablePath = await
|
|
59
|
+
const cwd = dirname(fileURLToPath(import.meta.url));
|
|
60
|
+
const executablePath = await findPathUp('node_modules/.bin/oxygen-preview', {
|
|
61
|
+
type: 'file',
|
|
62
|
+
cwd,
|
|
63
|
+
allowSymlinks: true,
|
|
64
|
+
});
|
|
59
65
|
if (!executablePath) {
|
|
60
66
|
throw OxygenPreviewExecutableNotFound;
|
|
61
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview.js","sourceRoot":"","sources":["../../../src/cli/services/preview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"preview.js","sourceRoot":"","sources":["../../../src/cli/services/preview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,MAAM,EAAC,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAC,kBAAkB,EAAa,MAAM,+BAA+B,CAAA;AAC5E,OAAO,EAAC,UAAU,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAC,MAAM,0BAA0B,CAAA;AAC1F,OAAO,EAAC,IAAI,EAAC,MAAM,8BAA8B,CAAA;AACjD,OAAO,EAAC,WAAW,EAAE,OAAO,EAAC,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAC,aAAa,EAAC,MAAM,KAAK,CAAA;AAejC,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,EAAC,SAAS,EAAE,IAAI,EAAiB;IACnE,MAAM,eAAe,GAAG,MAAM,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;IAEjE,IAAI,CAAC,CAAC,MAAM,UAAU,CAAC,eAAe,CAAC,CAAC,EAAE;QACxC,MAAM,CAAC,IAAI,CACT,MAAM,CAAC,OAAO,CAAA,kEAAkE,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAC5G,MAAM,EACN,wBAAwB,EACxB,eAAe,CAChB,iBAAiB,CACnB,CAAA;QAED,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,eAAe,CAAC,EAAE;YACpE,GAAG,EAAE,SAAS;YACd,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC,CAAA;KACH;IAED,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC,sBAAsB,EAAE,eAAe,CAAC,EAAE;QAC5D,GAAG,EAAE,EAAC,IAAI,EAAE,GAAG,IAAI,EAAE,EAAC;QACtB,GAAG,EAAE,SA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C;QAChD,GAAG,EAAE,SAAS;QACd,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,+BAA+B,GAAG,IAAI,KAAK,CAAC,GAAG,CAC1D,6DAA6D,CAC9D,CAAA;AAED,KAAK,UAAU,uBAAuB;IACpC,MAAM,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;IACnD,MAAM,cAAc,GAAG,MAAM,UAAU,CAAC,kCAAkC,EAAE;QAC1E,IAAI,EAAE,MAAM;QACZ,GAAG;QACH,aAAa,EAAE,IAAI;KACpB,CAAC,CAAA;IACF,IAAI,CAAC,cAAc,EAAE;QACnB,MAAM,+BAA+B,CAAA;KACtC;IACD,OAAO,cAAc,CAAA;AACvB,CAAC","sourcesContent":["import {error, output} from '@shopify/cli-kit'\nimport {readAndParseDotEnv, DotEnvFile} from '@shopify/cli-kit/node/dot-env'\nimport {fileExists, removeFileSync, writeFile, findPathUp} from '@shopify/cli-kit/node/fs'\nimport {exec} from '@shopify/cli-kit/node/system'\nimport {resolvePath, dirname} from '@shopify/cli-kit/node/path'\nimport {fileURLToPath} from 'url'\n\ninterface PreviewOptions {\n directory: string\n port: number\n}\n\ninterface PreviewOptionsWorker extends PreviewOptions {\n envPath: string | undefined\n}\n\ninterface EnvConfig {\n env: DotEnvFile['variables']\n}\n\nexport async function previewInNode({directory, port}: PreviewOptions) {\n const buildOutputPath = await resolvePath(directory, 'dist/node')\n\n if (!(await fileExists(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 exec('yarn', ['shopify', 'hydrogen', 'build', '--target=node'], {\n cwd: directory,\n stdout: process.stdout,\n stderr: process.stderr,\n })\n }\n\n await 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, envPath}: PreviewOptionsWorker) {\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 ...(envPath && (await parseEnvPath(envPath))),\n }\n\n await writeFile(resolvePath(directory, 'mini-oxygen.config.json'), JSON.stringify(config, null, 2))\n\n function cleanUp(options: {exit: boolean}) {\n if (options.exit) {\n removeFileSync(resolvePath(directory, 'mini-oxygen.config.json'))\n }\n }\n\n async function parseEnvPath(envPath: string): Promise<EnvConfig> {\n const {variables} = await readAndParseDotEnv(envPath)\n return {\n env: variables,\n }\n }\n\n process.on('SIGINT', cleanUp.bind(null, {exit: true}))\n\n const executable = await oxygenPreviewExecutable()\n\n await 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 = dirname(fileURLToPath(import.meta.url))\n const executablePath = await findPathUp('node_modules/.bin/oxygen-preview', {\n type: 'file',\n cwd,\n allowSymlinks: true,\n })\n if (!executablePath) {\n throw OxygenPreviewExecutableNotFound\n }\n return executablePath\n}\n"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { ui,
|
|
1
|
+
import { ui, error } from '@shopify/cli-kit';
|
|
2
2
|
import { addNPMDependenciesWithoutVersionIfNeeded } from '@shopify/cli-kit/node/node-package-manager';
|
|
3
3
|
import { addRecommendedExtensions } from '@shopify/cli-kit/node/vscode';
|
|
4
4
|
import { exec } from '@shopify/cli-kit/node/system';
|
|
5
|
+
import { writeFile, fileExists, removeFile, fileContentPrettyFormat, readFile } from '@shopify/cli-kit/node/fs';
|
|
6
|
+
import { joinPath } from '@shopify/cli-kit/node/path';
|
|
5
7
|
import stream from 'stream';
|
|
6
8
|
const tailwindImports = [
|
|
7
9
|
"@import 'tailwindcss/base';",
|
|
@@ -39,27 +41,27 @@ export async function addTailwind({ app, force, install, directory }) {
|
|
|
39
41
|
{
|
|
40
42
|
title: 'Adding PostCSS configuration',
|
|
41
43
|
task: async (_, task) => {
|
|
42
|
-
const postCSSConfiguration =
|
|
43
|
-
if (await
|
|
44
|
+
const postCSSConfiguration = joinPath(directory, 'postcss.config.js');
|
|
45
|
+
if (await fileExists(postCSSConfiguration)) {
|
|
44
46
|
if (force) {
|
|
45
|
-
await
|
|
47
|
+
await removeFile(postCSSConfiguration);
|
|
46
48
|
}
|
|
47
49
|
else {
|
|
48
50
|
throw new error.Abort('PostCSS config already exists.\nUse --force to override existing config.');
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
|
-
const postCSSConfig = await
|
|
52
|
-
await
|
|
53
|
+
const postCSSConfig = await fileContentPrettyFormat(['module.exports = {', 'plugins: {', 'tailwindcss: {},', 'autoprefixer: {},', '},', ' };'].join('\n'), { path: 'postcss.config.js' });
|
|
54
|
+
await writeFile(postCSSConfiguration, postCSSConfig);
|
|
53
55
|
task.title = 'PostCSS configuration added';
|
|
54
56
|
},
|
|
55
57
|
},
|
|
56
58
|
{
|
|
57
59
|
title: 'Initializing Tailwind CSS...',
|
|
58
60
|
task: async (_, task) => {
|
|
59
|
-
const tailwindConfigurationPath =
|
|
60
|
-
if (await
|
|
61
|
+
const tailwindConfigurationPath = joinPath(directory, 'tailwind.config.js');
|
|
62
|
+
if (await fileExists(tailwindConfigurationPath)) {
|
|
61
63
|
if (force) {
|
|
62
|
-
await
|
|
64
|
+
await removeFile(tailwindConfigurationPath);
|
|
63
65
|
}
|
|
64
66
|
else {
|
|
65
67
|
throw new error.Abort('Tailwind config already exists.\nUse --force to override existing config.');
|
|
@@ -75,14 +77,14 @@ export async function addTailwind({ app, force, install, directory }) {
|
|
|
75
77
|
{
|
|
76
78
|
title: 'Importing Tailwind CSS in index.css',
|
|
77
79
|
task: async (_ctx, task) => {
|
|
78
|
-
const indexCSSPath =
|
|
79
|
-
const indexCSS = await
|
|
80
|
+
const indexCSSPath = joinPath(directory, 'src', 'index.css');
|
|
81
|
+
const indexCSS = await readFile(indexCSSPath);
|
|
80
82
|
if (tailwindImportsExist(indexCSS)) {
|
|
81
83
|
task.skip('Imports already exist in index.css');
|
|
82
84
|
}
|
|
83
85
|
else {
|
|
84
86
|
const newIndexCSS = tailwindImports.join('\n') + indexCSS;
|
|
85
|
-
await
|
|
87
|
+
await writeFile(indexCSSPath, newIndexCSS);
|
|
86
88
|
}
|
|
87
89
|
task.title = 'Tailwind imports added';
|
|
88
90
|
},
|
|
@@ -98,8 +100,8 @@ export async function addTailwind({ app, force, install, directory }) {
|
|
|
98
100
|
await list.run();
|
|
99
101
|
}
|
|
100
102
|
async function replace(find, replace, filepath) {
|
|
101
|
-
const original = await
|
|
103
|
+
const original = await readFile(filepath);
|
|
102
104
|
const modified = original.replace(find, replace);
|
|
103
|
-
await
|
|
105
|
+
await writeFile(filepath, modified);
|
|
104
106
|
}
|
|
105
107
|
//# sourceMappingURL=tailwind.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tailwind.js","sourceRoot":"","sources":["../../../src/cli/services/tailwind.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"tailwind.js","sourceRoot":"","sources":["../../../src/cli/services/tailwind.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,EAAE,EAAE,KAAK,EAAC,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAC,wCAAwC,EAAC,MAAM,4CAA4C,CAAA;AACnG,OAAO,EAAC,wBAAwB,EAAC,MAAM,8BAA8B,CAAA;AACrE,OAAO,EAAC,IAAI,EAAC,MAAM,8BAA8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AAqC,CAAA;YACpD,CAAC;SACF;KACF,CAAC,CAAA;IACF,MAAM,IAAI,CAAC,GAAG,EAAE,CAAA;AAClB,CAAC;AAED,KAAK,UAAU,OAAO,CAAC,IAAqB,EAAE,OAAe,EAAE,QAAgB;IAC7E,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAA;IACzC,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAChD,MAAM,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;AACrC,CAAC","sourcesContent":["import {HydrogenApp} from '../models/hydrogen.js'\nimport {ui, error} from '@shopify/cli-kit'\nimport {addNPMDependenciesWithoutVersionIfNeeded} from '@shopify/cli-kit/node/node-package-manager'\nimport {addRecommendedExtensions} from '@shopify/cli-kit/node/vscode'\nimport {exec} from '@shopify/cli-kit/node/system'\nimport {writeFile, fileExists, removeFile, fileContentPrettyFormat, readFile} from '@shopify/cli-kit/node/fs'\nimport {joinPath} from '@shopify/cli-kit/node/path'\nimport stream from '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 addNPMDependenciesWithoutVersionIfNeeded(requiredDependencies, {\n packageManager: app.packageManager,\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 = joinPath(directory, 'postcss.config.js')\n\n if (await fileExists(postCSSConfiguration)) {\n if (force) {\n await removeFile(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 fileContentPrettyFormat(\n ['module.exports = {', 'plugins: {', 'tailwindcss: {},', 'autoprefixer: {},', '},', ' };'].join('\\n'),\n {path: 'postcss.config.js'},\n )\n\n await writeFile(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 = joinPath(directory, 'tailwind.config.js')\n\n if (await fileExists(tailwindConfigurationPath)) {\n if (force) {\n await removeFile(tailwindConfigurationPath)\n } else {\n throw new error.Abort('Tailwind config already exists.\\nUse --force to override existing config.')\n }\n }\n\n await exec(app.packageManager, ['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 = joinPath(directory, 'src', 'index.css')\n const indexCSS = await readFile(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 writeFile(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 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 readFile(filepath)\n const modified = original.replace(find, replace)\n await writeFile(filepath, modified)\n}\n"]}
|