@sitecore-content-sdk/cli 1.3.0-canary.7 → 1.3.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/LICENSE.txt +202 -202
- package/README.md +5 -5
- package/dist/cjs/bin/sitecore-tools.js +77 -77
- package/dist/cjs/cli.js +69 -69
- package/dist/cjs/scripts/index.js +40 -40
- package/dist/cjs/scripts/project/build.js +42 -42
- package/dist/cjs/scripts/project/component/add.js +241 -236
- package/dist/cjs/scripts/project/component/generate-map.js +70 -68
- package/dist/cjs/scripts/project/component/index.js +57 -57
- package/dist/cjs/scripts/project/component/scaffold.js +69 -66
- package/dist/cjs/scripts/project/index.js +56 -56
- package/dist/cjs/utils/load-config.js +42 -42
- package/dist/cjs/utils/process-env.js +70 -70
- package/dist/cjs/utils/watch-items.js +18 -18
- package/dist/esm/cli.js +63 -63
- package/dist/esm/scripts/index.js +4 -4
- package/dist/esm/scripts/project/build.js +35 -35
- package/dist/esm/scripts/project/component/add.js +198 -193
- package/dist/esm/scripts/project/component/generate-map.js +62 -60
- package/dist/esm/scripts/project/component/index.js +21 -21
- package/dist/esm/scripts/project/component/scaffold.js +61 -58
- package/dist/esm/scripts/project/index.js +20 -20
- package/dist/esm/utils/load-config.js +36 -36
- package/dist/esm/utils/process-env.js +31 -31
- package/dist/esm/utils/watch-items.js +12 -12
- package/package.json +79 -79
- package/types/bin/sitecore-tools.d.ts +3 -2
- package/types/bin/sitecore-tools.d.ts.map +1 -0
- package/types/cli.d.ts +14 -13
- package/types/cli.d.ts.map +1 -0
- package/types/scripts/index.d.ts +3 -2
- package/types/scripts/index.d.ts.map +1 -0
- package/types/scripts/project/build.d.ts +25 -24
- package/types/scripts/project/build.d.ts.map +1 -0
- package/types/scripts/project/component/add.d.ts +59 -58
- package/types/scripts/project/component/add.d.ts.map +1 -0
- package/types/scripts/project/component/generate-map.d.ts +33 -32
- package/types/scripts/project/component/generate-map.d.ts.map +1 -0
- package/types/scripts/project/component/index.d.ts +6 -5
- package/types/scripts/project/component/index.d.ts.map +1 -0
- package/types/scripts/project/component/scaffold.d.ts +45 -44
- package/types/scripts/project/component/scaffold.d.ts.map +1 -0
- package/types/scripts/project/index.d.ts +6 -5
- package/types/scripts/project/index.d.ts.map +1 -0
- package/types/utils/load-config.d.ts +9 -8
- package/types/utils/load-config.d.ts.map +1 -0
- package/types/utils/process-env.d.ts +9 -8
- package/types/utils/process-env.d.ts.map +1 -0
- package/types/utils/watch-items.d.ts +7 -6
- package/types/utils/watch-items.d.ts.map +1 -0
|
@@ -1,60 +1,62 @@
|
|
|
1
|
-
import { watchItems } from '../../../utils/watch-items';
|
|
2
|
-
import loadCliConfig from '../../../utils/load-config';
|
|
3
|
-
/**
|
|
4
|
-
* @param {Argv} yargs
|
|
5
|
-
*/
|
|
6
|
-
export function builder(yargs) {
|
|
7
|
-
return yargs.command('generate-map', 'Generates component map based on provided paths', args, handler);
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* @param {Argv} yargs
|
|
11
|
-
*/
|
|
12
|
-
export function args(yargs) {
|
|
13
|
-
return yargs
|
|
14
|
-
.option('watch', {
|
|
15
|
-
requiresArg: false,
|
|
16
|
-
type: 'boolean',
|
|
17
|
-
describe: 'If true, watches for changes in the specified paths and updates the component map accordingly.',
|
|
18
|
-
default: false,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
1
|
+
import { watchItems } from '../../../utils/watch-items';
|
|
2
|
+
import loadCliConfig from '../../../utils/load-config';
|
|
3
|
+
/**
|
|
4
|
+
* @param {Argv} yargs
|
|
5
|
+
*/
|
|
6
|
+
export function builder(yargs) {
|
|
7
|
+
return yargs.command(['generate-map', 'g'], 'Generates component map based on provided paths', args, handler);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* @param {Argv} yargs
|
|
11
|
+
*/
|
|
12
|
+
export function args(yargs) {
|
|
13
|
+
return yargs
|
|
14
|
+
.option('watch', {
|
|
15
|
+
requiresArg: false,
|
|
16
|
+
type: 'boolean',
|
|
17
|
+
describe: 'If true, watches for changes in the specified paths and updates the component map accordingly.',
|
|
18
|
+
default: false,
|
|
19
|
+
alias: 'w',
|
|
20
|
+
})
|
|
21
|
+
.option('config', {
|
|
22
|
+
requiresArg: false,
|
|
23
|
+
type: 'string',
|
|
24
|
+
describe: 'Path to the `sitecore.cli.config` file. Supports both JavaScript (`.js`) and TypeScript (`.ts`) formats',
|
|
25
|
+
alias: 'c',
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Handler for the `generate-map` command.
|
|
30
|
+
* @param {GenerateMapCliArgs} argv Cli arguments for the command
|
|
31
|
+
*/
|
|
32
|
+
export function handler(argv) {
|
|
33
|
+
const cliConfig = loadCliConfig(argv.config);
|
|
34
|
+
if (!cliConfig.componentMap) {
|
|
35
|
+
console.error('The `sitecore.cli.config` file is missing a `componentMap` configuration. Please add it to use this command.');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const componentMapGenerator = cliConfig.componentMap.generator;
|
|
39
|
+
const { paths, destination, componentImports, exclude, clientComponentMap, includeVariants } = cliConfig.componentMap;
|
|
40
|
+
if (argv.watch) {
|
|
41
|
+
console.log(`Watching for component changes to component builder sources in:\n ${paths.join('\n')}`);
|
|
42
|
+
watchItems(paths, componentMapGenerator.bind(null, {
|
|
43
|
+
paths,
|
|
44
|
+
destination,
|
|
45
|
+
componentImports,
|
|
46
|
+
exclude,
|
|
47
|
+
clientComponentMap,
|
|
48
|
+
includeVariants,
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
console.log(`Generating component map for:\n ${paths.join('\n')}`);
|
|
53
|
+
componentMapGenerator({
|
|
54
|
+
paths,
|
|
55
|
+
destination,
|
|
56
|
+
componentImports,
|
|
57
|
+
exclude,
|
|
58
|
+
clientComponentMap,
|
|
59
|
+
includeVariants,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import * as scaffold from './scaffold';
|
|
2
|
-
import * as generateMap from './generate-map';
|
|
3
|
-
/**
|
|
4
|
-
* @param {Argv} yargs
|
|
5
|
-
*/
|
|
6
|
-
export function builder(yargs) {
|
|
7
|
-
return yargs.command({
|
|
8
|
-
command: 'component',
|
|
9
|
-
describe: 'Performs component level operations',
|
|
10
|
-
builder: (_yargs) => {
|
|
11
|
-
_yargs = _yargs
|
|
12
|
-
.command([scaffold, generateMap])
|
|
13
|
-
.strict()
|
|
14
|
-
.demandCommand(1, 'You need to specify a command to run');
|
|
15
|
-
_yargs = scaffold.builder(_yargs);
|
|
16
|
-
_yargs = generateMap.builder(_yargs);
|
|
17
|
-
return _yargs;
|
|
18
|
-
},
|
|
19
|
-
handler: () => { },
|
|
20
|
-
});
|
|
21
|
-
}
|
|
1
|
+
import * as scaffold from './scaffold';
|
|
2
|
+
import * as generateMap from './generate-map';
|
|
3
|
+
/**
|
|
4
|
+
* @param {Argv} yargs
|
|
5
|
+
*/
|
|
6
|
+
export function builder(yargs) {
|
|
7
|
+
return yargs.command({
|
|
8
|
+
command: ['component', 'c'],
|
|
9
|
+
describe: 'Performs component level operations',
|
|
10
|
+
builder: (_yargs) => {
|
|
11
|
+
_yargs = _yargs
|
|
12
|
+
.command([scaffold, generateMap])
|
|
13
|
+
.strict()
|
|
14
|
+
.demandCommand(1, 'You need to specify a command to run');
|
|
15
|
+
_yargs = scaffold.builder(_yargs);
|
|
16
|
+
_yargs = generateMap.builder(_yargs);
|
|
17
|
+
return _yargs;
|
|
18
|
+
},
|
|
19
|
+
handler: () => { },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -1,60 +1,63 @@
|
|
|
1
|
-
import { scaffoldComponent } from '@sitecore-content-sdk/core/tools';
|
|
2
|
-
import loadCliConfig from '../../../utils/load-config';
|
|
3
|
-
import { ComponentTemplateType } from '@sitecore-content-sdk/core/config';
|
|
4
|
-
/**
|
|
5
|
-
* @param {Argv} yargs
|
|
6
|
-
*/
|
|
7
|
-
export function builder(yargs) {
|
|
8
|
-
return yargs.command('scaffold <componentName>', 'Scaffolds a new component', args, handler);
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* @param {Argv} yargs
|
|
12
|
-
*/
|
|
13
|
-
export function args(yargs) {
|
|
14
|
-
return yargs
|
|
15
|
-
.positional('componentName', {
|
|
16
|
-
requiresArg: true,
|
|
17
|
-
positional: true,
|
|
18
|
-
type: 'string',
|
|
1
|
+
import { scaffoldComponent } from '@sitecore-content-sdk/core/tools';
|
|
2
|
+
import loadCliConfig from '../../../utils/load-config';
|
|
3
|
+
import { ComponentTemplateType } from '@sitecore-content-sdk/core/config';
|
|
4
|
+
/**
|
|
5
|
+
* @param {Argv} yargs
|
|
6
|
+
*/
|
|
7
|
+
export function builder(yargs) {
|
|
8
|
+
return yargs.command(['scaffold <componentName>', 's <componentName>'], 'Scaffolds a new component', args, handler);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @param {Argv} yargs
|
|
12
|
+
*/
|
|
13
|
+
export function args(yargs) {
|
|
14
|
+
return yargs
|
|
15
|
+
.positional('componentName', {
|
|
16
|
+
requiresArg: true,
|
|
17
|
+
positional: true,
|
|
18
|
+
type: 'string',
|
|
19
19
|
describe: `Name of the component to scaffold. Component name should start with an uppercase letter and contain only letters, numbers,
|
|
20
|
-
dashes, or underscores. It can also contain slashes to indicate a subfolder. Example: MyComponent or MyFolder/MyComponent. If no subfolder is specified, the component will be created under 'src/components'.`,
|
|
21
|
-
})
|
|
22
|
-
.option('config', {
|
|
23
|
-
requiresArg: false,
|
|
24
|
-
type: 'string',
|
|
25
|
-
describe: 'Path to the `sitecore.cli.config` file. Supports both JavaScript (`.js`) and TypeScript (`.ts`) formats',
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
20
|
+
dashes, or underscores. It can also contain slashes to indicate a subfolder. Example: MyComponent or MyFolder/MyComponent. If no subfolder is specified, the component will be created under 'src/components'.`,
|
|
21
|
+
})
|
|
22
|
+
.option('config', {
|
|
23
|
+
requiresArg: false,
|
|
24
|
+
type: 'string',
|
|
25
|
+
describe: 'Path to the `sitecore.cli.config` file. Supports both JavaScript (`.js`) and TypeScript (`.ts`) formats',
|
|
26
|
+
alias: 'c',
|
|
27
|
+
})
|
|
28
|
+
.option('templateName', {
|
|
29
|
+
requiresArg: false,
|
|
30
|
+
type: 'string',
|
|
31
|
+
describe: 'Name of the template that will be used to scaffold the component. Can be configured in the cli.config.',
|
|
32
|
+
alias: 't',
|
|
33
|
+
})
|
|
34
|
+
.option('byoc', {
|
|
35
|
+
requiresArg: false,
|
|
36
|
+
type: 'boolean',
|
|
37
|
+
describe: 'If true, scaffolds a byoc component.',
|
|
38
|
+
default: false,
|
|
39
|
+
alias: 'b',
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Handler for the scaffold command.
|
|
44
|
+
* @param {ScaffoldArgs} argv - The arguments passed to the command.
|
|
45
|
+
*/
|
|
46
|
+
export function handler(argv) {
|
|
47
|
+
var _a;
|
|
48
|
+
if (!argv.componentName) {
|
|
49
|
+
throw new Error('Component name is required. Usage: sitecore-tools scaffold <ComponentName>');
|
|
50
|
+
}
|
|
51
|
+
const nameParamFormat = new RegExp(/^((?:[\w\-]+\/)*)([A-Z][\w-]+)$/);
|
|
52
|
+
const regExResult = nameParamFormat.exec(argv.componentName);
|
|
53
|
+
if (regExResult === null) {
|
|
51
54
|
throw new Error(`Component name should start with an uppercase letter and contain only letters, numbers,
|
|
52
|
-
dashes, or underscores. It can also contain slashes to indicate a subfolder`);
|
|
53
|
-
}
|
|
54
|
-
const cliConfig = loadCliConfig(argv.config);
|
|
55
|
-
const componentPath = regExResult[1];
|
|
56
|
-
const componentName = regExResult[2];
|
|
57
|
-
const outputFolder = componentPath || 'src/components';
|
|
58
|
-
const templateName = (_a = argv.templateName) !== null && _a !== void 0 ? _a : (argv.byoc ? ComponentTemplateType.BYOC : ComponentTemplateType.DEFAULT);
|
|
59
|
-
scaffoldComponent(outputFolder, componentName, templateName, cliConfig.scaffold.templates);
|
|
60
|
-
}
|
|
55
|
+
dashes, or underscores. It can also contain slashes to indicate a subfolder`);
|
|
56
|
+
}
|
|
57
|
+
const cliConfig = loadCliConfig(argv.config);
|
|
58
|
+
const componentPath = regExResult[1];
|
|
59
|
+
const componentName = regExResult[2];
|
|
60
|
+
const outputFolder = componentPath || 'src/components';
|
|
61
|
+
const templateName = (_a = argv.templateName) !== null && _a !== void 0 ? _a : (argv.byoc ? ComponentTemplateType.BYOC : ComponentTemplateType.DEFAULT);
|
|
62
|
+
scaffoldComponent(outputFolder, componentName, templateName, cliConfig.scaffold.templates);
|
|
63
|
+
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import * as build from './build';
|
|
2
|
-
import * as component from './component';
|
|
3
|
-
/**
|
|
4
|
-
* @param {Argv} yargs
|
|
5
|
-
*/
|
|
6
|
-
export function builder(yargs) {
|
|
7
|
-
return yargs.command({
|
|
8
|
-
command: 'project',
|
|
9
|
-
describe: 'Performs project level operations',
|
|
10
|
-
builder: (_yargs) => {
|
|
11
|
-
_yargs = _yargs
|
|
12
|
-
.command([build, component])
|
|
13
|
-
.strict()
|
|
14
|
-
.demandCommand(1, 'You need to specify a command to run');
|
|
15
|
-
_yargs = component.builder(_yargs);
|
|
16
|
-
return _yargs;
|
|
17
|
-
},
|
|
18
|
-
handler: () => { },
|
|
19
|
-
});
|
|
20
|
-
}
|
|
1
|
+
import * as build from './build';
|
|
2
|
+
import * as component from './component';
|
|
3
|
+
/**
|
|
4
|
+
* @param {Argv} yargs
|
|
5
|
+
*/
|
|
6
|
+
export function builder(yargs) {
|
|
7
|
+
return yargs.command({
|
|
8
|
+
command: ['project', 'p'],
|
|
9
|
+
describe: 'Performs project level operations',
|
|
10
|
+
builder: (_yargs) => {
|
|
11
|
+
_yargs = _yargs
|
|
12
|
+
.command([build, component])
|
|
13
|
+
.strict()
|
|
14
|
+
.demandCommand(1, 'You need to specify a command to run');
|
|
15
|
+
_yargs = component.builder(_yargs);
|
|
16
|
+
return _yargs;
|
|
17
|
+
},
|
|
18
|
+
handler: () => { },
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import processEnv from './process-env';
|
|
4
|
-
const tsx = require('tsx/cjs/api');
|
|
5
|
-
/**
|
|
6
|
-
* Loads Sitecore Content SDK CLI configuration from the specified file.
|
|
7
|
-
* @param {string} [configFile] - The path to the configuration file.
|
|
8
|
-
* @returns {SitecoreCliConfig} The default export from the configuration file.
|
|
9
|
-
* @throws Will throw an error if the configuration file does not exist or does not have a default export.
|
|
10
|
-
*/
|
|
11
|
-
export default function loadCliConfig(configFile) {
|
|
12
|
-
// If no config file is provided, try to load the default config file.
|
|
13
|
-
if (!configFile) {
|
|
14
|
-
configFile = './sitecore.cli.config.ts';
|
|
15
|
-
if (!fs.existsSync(path.resolve(process.cwd(), configFile))) {
|
|
16
|
-
configFile = './sitecore.cli.config.js';
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
// configuration file/filepath has been provided
|
|
21
|
-
// the env variables have been already loaded from the current working directory, however the current command may be running outside of a context of a project
|
|
22
|
-
// if so try loading the env vars from the directory of the provided config file
|
|
23
|
-
const configFileDirectory = path.dirname(path.resolve(process.cwd(), configFile));
|
|
24
|
-
if (process.cwd() !== configFileDirectory) {
|
|
25
|
-
processEnv(configFileDirectory);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
let cliConfig;
|
|
29
|
-
try {
|
|
30
|
-
cliConfig = tsx.require(path.resolve(process.cwd(), configFile), __filename);
|
|
31
|
-
}
|
|
32
|
-
catch (e) {
|
|
33
|
-
throw `Error while trying to load the cli configuration from ${configFile}. Error message: ${e.message}`;
|
|
34
|
-
}
|
|
35
|
-
return cliConfig.default;
|
|
36
|
-
}
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import processEnv from './process-env';
|
|
4
|
+
const tsx = require('tsx/cjs/api');
|
|
5
|
+
/**
|
|
6
|
+
* Loads Sitecore Content SDK CLI configuration from the specified file.
|
|
7
|
+
* @param {string} [configFile] - The path to the configuration file.
|
|
8
|
+
* @returns {SitecoreCliConfig} The default export from the configuration file.
|
|
9
|
+
* @throws Will throw an error if the configuration file does not exist or does not have a default export.
|
|
10
|
+
*/
|
|
11
|
+
export default function loadCliConfig(configFile) {
|
|
12
|
+
// If no config file is provided, try to load the default config file.
|
|
13
|
+
if (!configFile) {
|
|
14
|
+
configFile = './sitecore.cli.config.ts';
|
|
15
|
+
if (!fs.existsSync(path.resolve(process.cwd(), configFile))) {
|
|
16
|
+
configFile = './sitecore.cli.config.js';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
// configuration file/filepath has been provided
|
|
21
|
+
// the env variables have been already loaded from the current working directory, however the current command may be running outside of a context of a project
|
|
22
|
+
// if so try loading the env vars from the directory of the provided config file
|
|
23
|
+
const configFileDirectory = path.dirname(path.resolve(process.cwd(), configFile));
|
|
24
|
+
if (process.cwd() !== configFileDirectory) {
|
|
25
|
+
processEnv(configFileDirectory);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
let cliConfig;
|
|
29
|
+
try {
|
|
30
|
+
cliConfig = tsx.require(path.resolve(process.cwd(), configFile), __filename);
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
throw `Error while trying to load the cli configuration from ${configFile}. Error message: ${e.message}`;
|
|
34
|
+
}
|
|
35
|
+
return cliConfig.default;
|
|
36
|
+
}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import * as dotenv from 'dotenv';
|
|
3
|
-
import dotenvExpand from 'dotenv-expand';
|
|
4
|
-
import { SITECORE_CLI_MODE_ENV_VAR } from '@sitecore-content-sdk/core/config-cli';
|
|
5
|
-
/**
|
|
6
|
-
* Loads and processes environment variables from `.env` files in the specified directory.
|
|
7
|
-
* It supports multiple `.env` files, including
|
|
8
|
-
* environment-specific files (e.g., `.env.development`, `.env.production`) and local overrides
|
|
9
|
-
* (e.g., `.env.local`, `.env.development.local`).
|
|
10
|
-
* @param {string} dir - The directory to search for `.env` files.
|
|
11
|
-
*/
|
|
12
|
-
export default function processEnv(dir) {
|
|
13
|
-
// replicate Next.js handling/behavior, but without a default NODE_ENV
|
|
14
|
-
// https://github.com/vercel/next.js/blob/v10.0.5/packages/next-env/index.ts#L80-L90
|
|
15
|
-
const mode = process.env.NODE_ENV;
|
|
16
|
-
const dotenvFiles = [
|
|
17
|
-
mode && `.env.${mode}.local`,
|
|
18
|
-
// Don't include `.env.local` for `test` environment
|
|
19
|
-
// since normally you expect tests to produce the same
|
|
20
|
-
// results for everyone
|
|
21
|
-
mode !== 'test' && '.env.local',
|
|
22
|
-
mode && `.env.${mode}`,
|
|
23
|
-
'.env',
|
|
24
|
-
].filter(Boolean);
|
|
25
|
-
// Set the environment variable to indicate that the application is running in CLI mode
|
|
26
|
-
process.env[SITECORE_CLI_MODE_ENV_VAR] = 'true';
|
|
27
|
-
// inspired by https://github.com/entropitor/dotenv-cli/blob/v4.0.0/cli.js#L53-L55
|
|
28
|
-
dotenvFiles.forEach(function (env) {
|
|
29
|
-
dotenvExpand.expand(dotenv.config({ path: path.resolve(dir, env) }));
|
|
30
|
-
});
|
|
31
|
-
}
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import * as dotenv from 'dotenv';
|
|
3
|
+
import dotenvExpand from 'dotenv-expand';
|
|
4
|
+
import { SITECORE_CLI_MODE_ENV_VAR } from '@sitecore-content-sdk/core/config-cli';
|
|
5
|
+
/**
|
|
6
|
+
* Loads and processes environment variables from `.env` files in the specified directory.
|
|
7
|
+
* It supports multiple `.env` files, including
|
|
8
|
+
* environment-specific files (e.g., `.env.development`, `.env.production`) and local overrides
|
|
9
|
+
* (e.g., `.env.local`, `.env.development.local`).
|
|
10
|
+
* @param {string} dir - The directory to search for `.env` files.
|
|
11
|
+
*/
|
|
12
|
+
export default function processEnv(dir) {
|
|
13
|
+
// replicate Next.js handling/behavior, but without a default NODE_ENV
|
|
14
|
+
// https://github.com/vercel/next.js/blob/v10.0.5/packages/next-env/index.ts#L80-L90
|
|
15
|
+
const mode = process.env.NODE_ENV;
|
|
16
|
+
const dotenvFiles = [
|
|
17
|
+
mode && `.env.${mode}.local`,
|
|
18
|
+
// Don't include `.env.local` for `test` environment
|
|
19
|
+
// since normally you expect tests to produce the same
|
|
20
|
+
// results for everyone
|
|
21
|
+
mode !== 'test' && '.env.local',
|
|
22
|
+
mode && `.env.${mode}`,
|
|
23
|
+
'.env',
|
|
24
|
+
].filter(Boolean);
|
|
25
|
+
// Set the environment variable to indicate that the application is running in CLI mode
|
|
26
|
+
process.env[SITECORE_CLI_MODE_ENV_VAR] = 'true';
|
|
27
|
+
// inspired by https://github.com/entropitor/dotenv-cli/blob/v4.0.0/cli.js#L53-L55
|
|
28
|
+
dotenvFiles.forEach(function (env) {
|
|
29
|
+
dotenvExpand.expand(dotenv.config({ path: path.resolve(dir, env) }));
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import chokidar from 'chokidar';
|
|
2
|
-
/**
|
|
3
|
-
* Run watch mode, watching on @var paths
|
|
4
|
-
* @param {string[]} paths paths to watch by chokidar
|
|
5
|
-
* @param {Function<void>} cb callback to run on file change
|
|
6
|
-
*/
|
|
7
|
-
export function watchItems(paths, cb) {
|
|
8
|
-
chokidar
|
|
9
|
-
.watch(paths, { ignoreInitial: true, awaitWriteFinish: true })
|
|
10
|
-
.on('add', cb)
|
|
11
|
-
.on('unlink', cb);
|
|
12
|
-
}
|
|
1
|
+
import chokidar from 'chokidar';
|
|
2
|
+
/**
|
|
3
|
+
* Run watch mode, watching on @var paths
|
|
4
|
+
* @param {string[]} paths paths to watch by chokidar
|
|
5
|
+
* @param {Function<void>} cb callback to run on file change
|
|
6
|
+
*/
|
|
7
|
+
export function watchItems(paths, cb) {
|
|
8
|
+
chokidar
|
|
9
|
+
.watch(paths, { ignoreInitial: true, awaitWriteFinish: true })
|
|
10
|
+
.on('add', cb)
|
|
11
|
+
.on('unlink', cb);
|
|
12
|
+
}
|