@sitecore-jss/sitecore-jss-dev-tools 21.2.0-canary.34 → 21.2.0-canary.36
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/cjs/templating/nextjs/generate-component-builder.js +61 -0
- package/dist/cjs/templating/nextjs/index.js +7 -0
- package/dist/cjs/templating/nextjs/templates/component-builder.js +54 -0
- package/dist/cjs/templating/plugins.js +10 -12
- package/dist/cjs/templating/react/templates/component-builder.js +1 -1
- package/dist/esm/templating/nextjs/generate-component-builder.js +52 -0
- package/dist/esm/templating/nextjs/index.js +2 -0
- package/dist/esm/templating/nextjs/templates/component-builder.js +50 -0
- package/dist/esm/templating/plugins.js +10 -12
- package/dist/esm/templating/react/templates/component-builder.js +1 -1
- package/nextjs.d.ts +1 -0
- package/nextjs.js +3 -0
- package/package.json +3 -3
- package/types/templating/nextjs/generate-component-builder.d.ts +39 -0
- package/types/templating/nextjs/index.d.ts +2 -0
- package/types/templating/nextjs/templates/component-builder.d.ts +7 -0
- package/types/templating/plugins.d.ts +15 -9
- package/types/templating/react/templates/component-builder.d.ts +1 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.writeComponentBuilder = exports.watchComponentBuilder = exports.generateComponentBuilder = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const component_builder_1 = require("./templates/component-builder");
|
|
10
|
+
const components_1 = require("../components");
|
|
11
|
+
const utils_1 = require("../utils");
|
|
12
|
+
// Default destination path for component builder
|
|
13
|
+
const defaultComponentBuilderOutputPath = 'src/temp/componentBuilder.ts';
|
|
14
|
+
const defaultComponentRootPath = 'src/components';
|
|
15
|
+
/**
|
|
16
|
+
* Generate component builder based on provided settings
|
|
17
|
+
* @param {Object} [settings] settings for component builder generation
|
|
18
|
+
* @param {string} [settings.componentRootPath] path to components root
|
|
19
|
+
* @param {string} [settings.componentBuilderOutputPath] path to component builder output
|
|
20
|
+
* @param {PackageDefinition[]} [settings.packages] list of packages to include in component builder
|
|
21
|
+
* @param {boolean} [settings.watch] whether to watch for changes to component builder sources
|
|
22
|
+
*/
|
|
23
|
+
function generateComponentBuilder({ componentRootPath = defaultComponentRootPath, componentBuilderOutputPath = defaultComponentBuilderOutputPath, packages = [], watch, } = {}) {
|
|
24
|
+
if (watch) {
|
|
25
|
+
watchComponentBuilder({ componentRootPath, componentBuilderOutputPath, packages });
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
writeComponentBuilder({ componentRootPath, componentBuilderOutputPath, packages });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.generateComponentBuilder = generateComponentBuilder;
|
|
32
|
+
/**
|
|
33
|
+
* Watch for changes to component builder sources
|
|
34
|
+
* @param {Object} settings settings for component builder generation
|
|
35
|
+
* @param {string} settings.componentRootPath path to components root
|
|
36
|
+
* @param {string} settings.componentBuilderOutputPath path to component builder output
|
|
37
|
+
* @param {PackageDefinition[]} settings.packages list of packages to include in component builder
|
|
38
|
+
*/
|
|
39
|
+
function watchComponentBuilder({ componentRootPath, componentBuilderOutputPath, packages, }) {
|
|
40
|
+
console.log(`Watching for changes to component builder sources in ${componentRootPath}...`);
|
|
41
|
+
(0, utils_1.watchItems)([componentRootPath], writeComponentBuilder.bind(null, { componentRootPath, componentBuilderOutputPath, packages }));
|
|
42
|
+
}
|
|
43
|
+
exports.watchComponentBuilder = watchComponentBuilder;
|
|
44
|
+
/**
|
|
45
|
+
* Write component builder to file
|
|
46
|
+
* @param {Object} settings settings for component builder generation
|
|
47
|
+
* @param {string} settings.componentRootPath path to components root
|
|
48
|
+
* @param {string} settings.componentBuilderOutputPath path to component builder output
|
|
49
|
+
* @param {PackageDefinition[]} settings.packages list of packages to include in component builder
|
|
50
|
+
*/
|
|
51
|
+
function writeComponentBuilder({ componentRootPath, componentBuilderOutputPath, packages, }) {
|
|
52
|
+
const components = (0, components_1.getComponentList)(componentRootPath);
|
|
53
|
+
components.unshift(...packages);
|
|
54
|
+
const componentBuilderPath = path_1.default.resolve(componentBuilderOutputPath);
|
|
55
|
+
const fileContent = (0, component_builder_1.getComponentBuilderTemplate)(components);
|
|
56
|
+
console.log(`Writing component builder to ${componentBuilderPath}`);
|
|
57
|
+
fs_1.default.writeFileSync(componentBuilderPath, fileContent, {
|
|
58
|
+
encoding: 'utf8',
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
exports.writeComponentBuilder = writeComponentBuilder;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getComponentBuilderTemplate = exports.generateComponentBuilder = void 0;
|
|
4
|
+
var generate_component_builder_1 = require("./generate-component-builder");
|
|
5
|
+
Object.defineProperty(exports, "generateComponentBuilder", { enumerable: true, get: function () { return generate_component_builder_1.generateComponentBuilder; } });
|
|
6
|
+
var component_builder_1 = require("./templates/component-builder");
|
|
7
|
+
Object.defineProperty(exports, "getComponentBuilderTemplate", { enumerable: true, get: function () { return component_builder_1.getComponentBuilderTemplate; } });
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getComponentBuilderTemplate = void 0;
|
|
4
|
+
const isLazyLoadingModule = (componentPath) => componentPath.includes('.dynamic');
|
|
5
|
+
const removeDynamicModuleNameEnding = (moduleName) => moduleName.replace(/\.?dynamic$/i, '');
|
|
6
|
+
/**
|
|
7
|
+
* Generate component builder template
|
|
8
|
+
* @param {(PackageDefinition | ComponentFile)[]} components components to include in component builder
|
|
9
|
+
* @returns generated component builder template
|
|
10
|
+
*/
|
|
11
|
+
const getComponentBuilderTemplate = (components) => {
|
|
12
|
+
const componentFiles = components.filter((component) => component.componentName);
|
|
13
|
+
const packages = components.filter((component) => component.components);
|
|
14
|
+
const hasLazyModules = componentFiles.find((component) => isLazyLoadingModule(component.path));
|
|
15
|
+
return `/* eslint-disable */
|
|
16
|
+
// Do not edit this file, it is auto-generated at build time!
|
|
17
|
+
// See scripts/generate-component-builder/index.ts to modify the generation of this file.
|
|
18
|
+
|
|
19
|
+
${hasLazyModules ? "import dynamic from 'next/dynamic';" : ''}
|
|
20
|
+
import { ComponentBuilder } from '@sitecore-jss/sitecore-jss-nextjs';
|
|
21
|
+
|
|
22
|
+
${packages.map((pkg) => {
|
|
23
|
+
const list = pkg.components.map((c) => c.moduleName).join(', ');
|
|
24
|
+
return `import { ${list} } from '${pkg.name}'`;
|
|
25
|
+
})}
|
|
26
|
+
${componentFiles
|
|
27
|
+
.map((component) => {
|
|
28
|
+
if (isLazyLoadingModule(component.path)) {
|
|
29
|
+
const moduleName = removeDynamicModuleNameEnding(component.moduleName);
|
|
30
|
+
return `const ${moduleName} = {
|
|
31
|
+
module: () => import('${component.path}'),
|
|
32
|
+
element: (isEditing?: boolean) => isEditing ? require('${component.path}')?.default : dynamic(${moduleName}.module)
|
|
33
|
+
}`;
|
|
34
|
+
}
|
|
35
|
+
return `import * as ${component.moduleName} from '${component.path}';`;
|
|
36
|
+
})
|
|
37
|
+
.join('\n')}
|
|
38
|
+
|
|
39
|
+
const components = new Map();
|
|
40
|
+
${packages.map((p) => p.components.map((component) => `components.set('${component.componentName}', ${component.moduleName})`))}
|
|
41
|
+
${componentFiles
|
|
42
|
+
.map((component) => `components.set('${isLazyLoadingModule(component.path)
|
|
43
|
+
? removeDynamicModuleNameEnding(component.componentName)
|
|
44
|
+
: component.componentName}', ${isLazyLoadingModule(component.path)
|
|
45
|
+
? removeDynamicModuleNameEnding(component.moduleName)
|
|
46
|
+
: component.moduleName});`)
|
|
47
|
+
.join('\n')}
|
|
48
|
+
|
|
49
|
+
export const componentBuilder = new ComponentBuilder({ components });
|
|
50
|
+
|
|
51
|
+
export const moduleFactory = componentBuilder.getModuleFactory();
|
|
52
|
+
`;
|
|
53
|
+
};
|
|
54
|
+
exports.getComponentBuilderTemplate = getComponentBuilderTemplate;
|
|
@@ -23,17 +23,19 @@ var ModuleType;
|
|
|
23
23
|
* name: 'fooPlugin'
|
|
24
24
|
* }
|
|
25
25
|
* @example getPluginList('src/foo/plugins', 'Foo')
|
|
26
|
-
* @param {
|
|
27
|
-
* @param {string}
|
|
26
|
+
* @param {Object} definition plugin definition
|
|
27
|
+
* @param {string} definition.path path to get plugin from
|
|
28
|
+
* @param {string} definition.pluginName plugin name
|
|
29
|
+
* @param {boolean} [definition.silent] whether to suppress console output
|
|
28
30
|
*/
|
|
29
|
-
function getPluginList(path, pluginName) {
|
|
31
|
+
function getPluginList({ path, pluginName, silent = false, }) {
|
|
30
32
|
const plugins = (0, utils_1.getItems)({
|
|
31
33
|
path,
|
|
32
34
|
resolveItem: (path, name) => ({
|
|
33
35
|
path: `${path}/${name}`,
|
|
34
36
|
name: `${name.replace(/-./g, (x) => x[1].toUpperCase())}Plugin`,
|
|
35
37
|
}),
|
|
36
|
-
cb: (name) => console.debug(`Registering ${pluginName} plugin ${name}`),
|
|
38
|
+
cb: (name) => !silent && console.debug(`Registering ${pluginName} plugin ${name}`),
|
|
37
39
|
});
|
|
38
40
|
return plugins;
|
|
39
41
|
}
|
|
@@ -45,17 +47,13 @@ exports.getPluginList = getPluginList;
|
|
|
45
47
|
* CJS: exports.fooPlugin = require('{pluginPath}');
|
|
46
48
|
* ESM: export { fooPlugin } from '{pluginPath}';
|
|
47
49
|
* @example generatePlugins({ distPath: 'src/temp/foo-plugins.js', rootPath: 'src/foo/plugins', moduleType: ModuleType.CJS })
|
|
48
|
-
* @param {
|
|
49
|
-
* @param {string} definition.distPath path to write plugins to
|
|
50
|
-
* @param {string} definition.rootPath plugin source path
|
|
51
|
-
* @param {string} definition.moduleType module type: CJS or ESM
|
|
52
|
-
* @param {boolean} [definition.relative] whether to use relative paths in the generated file. By default, absolute paths are used.
|
|
50
|
+
* @param {PluginDefinition} definition plugin definition
|
|
53
51
|
*/
|
|
54
52
|
function generatePlugins(definition) {
|
|
55
|
-
const { rootPath, distPath, moduleType, relative =
|
|
53
|
+
const { rootPath, distPath, moduleType, relative = false, silent } = definition;
|
|
56
54
|
const segments = rootPath.split('/');
|
|
57
55
|
const pluginName = segments[segments.length - 2];
|
|
58
|
-
const plugins = getPluginList(rootPath, pluginName);
|
|
56
|
+
const plugins = getPluginList({ path: rootPath, pluginName, silent });
|
|
59
57
|
let fileContent = '';
|
|
60
58
|
fileContent = plugins
|
|
61
59
|
.map((plugin) => {
|
|
@@ -72,7 +70,7 @@ function generatePlugins(definition) {
|
|
|
72
70
|
fileContent = moduleType === ModuleType.CJS ? 'module.exports = {};\r\n' : 'export {};\r\n';
|
|
73
71
|
}
|
|
74
72
|
const filePath = path_1.default.resolve(distPath);
|
|
75
|
-
console.log(`Writing ${pluginName} plugins to ${filePath}`);
|
|
73
|
+
!silent && console.log(`Writing ${pluginName} plugins to ${filePath}`);
|
|
76
74
|
fs_1.default.writeFileSync(filePath, fileContent, {
|
|
77
75
|
encoding: 'utf8',
|
|
78
76
|
});
|
|
@@ -7,7 +7,7 @@ exports.getComponentBuilderTemplate = void 0;
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
/**
|
|
9
9
|
* Generate component builder template
|
|
10
|
-
* @param {(PackageDefinition | ComponentFile)[]}components components to include in component builder
|
|
10
|
+
* @param {(PackageDefinition | ComponentFile)[]} components components to include in component builder
|
|
11
11
|
* @param {string} distPath destination path for component builder
|
|
12
12
|
* @returns generated component builder template
|
|
13
13
|
*/
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { getComponentBuilderTemplate } from './templates/component-builder';
|
|
4
|
+
import { getComponentList } from '../components';
|
|
5
|
+
import { watchItems } from '../utils';
|
|
6
|
+
// Default destination path for component builder
|
|
7
|
+
const defaultComponentBuilderOutputPath = 'src/temp/componentBuilder.ts';
|
|
8
|
+
const defaultComponentRootPath = 'src/components';
|
|
9
|
+
/**
|
|
10
|
+
* Generate component builder based on provided settings
|
|
11
|
+
* @param {Object} [settings] settings for component builder generation
|
|
12
|
+
* @param {string} [settings.componentRootPath] path to components root
|
|
13
|
+
* @param {string} [settings.componentBuilderOutputPath] path to component builder output
|
|
14
|
+
* @param {PackageDefinition[]} [settings.packages] list of packages to include in component builder
|
|
15
|
+
* @param {boolean} [settings.watch] whether to watch for changes to component builder sources
|
|
16
|
+
*/
|
|
17
|
+
export function generateComponentBuilder({ componentRootPath = defaultComponentRootPath, componentBuilderOutputPath = defaultComponentBuilderOutputPath, packages = [], watch, } = {}) {
|
|
18
|
+
if (watch) {
|
|
19
|
+
watchComponentBuilder({ componentRootPath, componentBuilderOutputPath, packages });
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
writeComponentBuilder({ componentRootPath, componentBuilderOutputPath, packages });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Watch for changes to component builder sources
|
|
27
|
+
* @param {Object} settings settings for component builder generation
|
|
28
|
+
* @param {string} settings.componentRootPath path to components root
|
|
29
|
+
* @param {string} settings.componentBuilderOutputPath path to component builder output
|
|
30
|
+
* @param {PackageDefinition[]} settings.packages list of packages to include in component builder
|
|
31
|
+
*/
|
|
32
|
+
export function watchComponentBuilder({ componentRootPath, componentBuilderOutputPath, packages, }) {
|
|
33
|
+
console.log(`Watching for changes to component builder sources in ${componentRootPath}...`);
|
|
34
|
+
watchItems([componentRootPath], writeComponentBuilder.bind(null, { componentRootPath, componentBuilderOutputPath, packages }));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Write component builder to file
|
|
38
|
+
* @param {Object} settings settings for component builder generation
|
|
39
|
+
* @param {string} settings.componentRootPath path to components root
|
|
40
|
+
* @param {string} settings.componentBuilderOutputPath path to component builder output
|
|
41
|
+
* @param {PackageDefinition[]} settings.packages list of packages to include in component builder
|
|
42
|
+
*/
|
|
43
|
+
export function writeComponentBuilder({ componentRootPath, componentBuilderOutputPath, packages, }) {
|
|
44
|
+
const components = getComponentList(componentRootPath);
|
|
45
|
+
components.unshift(...packages);
|
|
46
|
+
const componentBuilderPath = path.resolve(componentBuilderOutputPath);
|
|
47
|
+
const fileContent = getComponentBuilderTemplate(components);
|
|
48
|
+
console.log(`Writing component builder to ${componentBuilderPath}`);
|
|
49
|
+
fs.writeFileSync(componentBuilderPath, fileContent, {
|
|
50
|
+
encoding: 'utf8',
|
|
51
|
+
});
|
|
52
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const isLazyLoadingModule = (componentPath) => componentPath.includes('.dynamic');
|
|
2
|
+
const removeDynamicModuleNameEnding = (moduleName) => moduleName.replace(/\.?dynamic$/i, '');
|
|
3
|
+
/**
|
|
4
|
+
* Generate component builder template
|
|
5
|
+
* @param {(PackageDefinition | ComponentFile)[]} components components to include in component builder
|
|
6
|
+
* @returns generated component builder template
|
|
7
|
+
*/
|
|
8
|
+
export const getComponentBuilderTemplate = (components) => {
|
|
9
|
+
const componentFiles = components.filter((component) => component.componentName);
|
|
10
|
+
const packages = components.filter((component) => component.components);
|
|
11
|
+
const hasLazyModules = componentFiles.find((component) => isLazyLoadingModule(component.path));
|
|
12
|
+
return `/* eslint-disable */
|
|
13
|
+
// Do not edit this file, it is auto-generated at build time!
|
|
14
|
+
// See scripts/generate-component-builder/index.ts to modify the generation of this file.
|
|
15
|
+
|
|
16
|
+
${hasLazyModules ? "import dynamic from 'next/dynamic';" : ''}
|
|
17
|
+
import { ComponentBuilder } from '@sitecore-jss/sitecore-jss-nextjs';
|
|
18
|
+
|
|
19
|
+
${packages.map((pkg) => {
|
|
20
|
+
const list = pkg.components.map((c) => c.moduleName).join(', ');
|
|
21
|
+
return `import { ${list} } from '${pkg.name}'`;
|
|
22
|
+
})}
|
|
23
|
+
${componentFiles
|
|
24
|
+
.map((component) => {
|
|
25
|
+
if (isLazyLoadingModule(component.path)) {
|
|
26
|
+
const moduleName = removeDynamicModuleNameEnding(component.moduleName);
|
|
27
|
+
return `const ${moduleName} = {
|
|
28
|
+
module: () => import('${component.path}'),
|
|
29
|
+
element: (isEditing?: boolean) => isEditing ? require('${component.path}')?.default : dynamic(${moduleName}.module)
|
|
30
|
+
}`;
|
|
31
|
+
}
|
|
32
|
+
return `import * as ${component.moduleName} from '${component.path}';`;
|
|
33
|
+
})
|
|
34
|
+
.join('\n')}
|
|
35
|
+
|
|
36
|
+
const components = new Map();
|
|
37
|
+
${packages.map((p) => p.components.map((component) => `components.set('${component.componentName}', ${component.moduleName})`))}
|
|
38
|
+
${componentFiles
|
|
39
|
+
.map((component) => `components.set('${isLazyLoadingModule(component.path)
|
|
40
|
+
? removeDynamicModuleNameEnding(component.componentName)
|
|
41
|
+
: component.componentName}', ${isLazyLoadingModule(component.path)
|
|
42
|
+
? removeDynamicModuleNameEnding(component.moduleName)
|
|
43
|
+
: component.moduleName});`)
|
|
44
|
+
.join('\n')}
|
|
45
|
+
|
|
46
|
+
export const componentBuilder = new ComponentBuilder({ components });
|
|
47
|
+
|
|
48
|
+
export const moduleFactory = componentBuilder.getModuleFactory();
|
|
49
|
+
`;
|
|
50
|
+
};
|
|
@@ -17,17 +17,19 @@ export var ModuleType;
|
|
|
17
17
|
* name: 'fooPlugin'
|
|
18
18
|
* }
|
|
19
19
|
* @example getPluginList('src/foo/plugins', 'Foo')
|
|
20
|
-
* @param {
|
|
21
|
-
* @param {string}
|
|
20
|
+
* @param {Object} definition plugin definition
|
|
21
|
+
* @param {string} definition.path path to get plugin from
|
|
22
|
+
* @param {string} definition.pluginName plugin name
|
|
23
|
+
* @param {boolean} [definition.silent] whether to suppress console output
|
|
22
24
|
*/
|
|
23
|
-
export function getPluginList(path, pluginName) {
|
|
25
|
+
export function getPluginList({ path, pluginName, silent = false, }) {
|
|
24
26
|
const plugins = getItems({
|
|
25
27
|
path,
|
|
26
28
|
resolveItem: (path, name) => ({
|
|
27
29
|
path: `${path}/${name}`,
|
|
28
30
|
name: `${name.replace(/-./g, (x) => x[1].toUpperCase())}Plugin`,
|
|
29
31
|
}),
|
|
30
|
-
cb: (name) => console.debug(`Registering ${pluginName} plugin ${name}`),
|
|
32
|
+
cb: (name) => !silent && console.debug(`Registering ${pluginName} plugin ${name}`),
|
|
31
33
|
});
|
|
32
34
|
return plugins;
|
|
33
35
|
}
|
|
@@ -38,17 +40,13 @@ export function getPluginList(path, pluginName) {
|
|
|
38
40
|
* CJS: exports.fooPlugin = require('{pluginPath}');
|
|
39
41
|
* ESM: export { fooPlugin } from '{pluginPath}';
|
|
40
42
|
* @example generatePlugins({ distPath: 'src/temp/foo-plugins.js', rootPath: 'src/foo/plugins', moduleType: ModuleType.CJS })
|
|
41
|
-
* @param {
|
|
42
|
-
* @param {string} definition.distPath path to write plugins to
|
|
43
|
-
* @param {string} definition.rootPath plugin source path
|
|
44
|
-
* @param {string} definition.moduleType module type: CJS or ESM
|
|
45
|
-
* @param {boolean} [definition.relative] whether to use relative paths in the generated file. By default, absolute paths are used.
|
|
43
|
+
* @param {PluginDefinition} definition plugin definition
|
|
46
44
|
*/
|
|
47
45
|
export function generatePlugins(definition) {
|
|
48
|
-
const { rootPath, distPath, moduleType, relative =
|
|
46
|
+
const { rootPath, distPath, moduleType, relative = false, silent } = definition;
|
|
49
47
|
const segments = rootPath.split('/');
|
|
50
48
|
const pluginName = segments[segments.length - 2];
|
|
51
|
-
const plugins = getPluginList(rootPath, pluginName);
|
|
49
|
+
const plugins = getPluginList({ path: rootPath, pluginName, silent });
|
|
52
50
|
let fileContent = '';
|
|
53
51
|
fileContent = plugins
|
|
54
52
|
.map((plugin) => {
|
|
@@ -65,7 +63,7 @@ export function generatePlugins(definition) {
|
|
|
65
63
|
fileContent = moduleType === ModuleType.CJS ? 'module.exports = {};\r\n' : 'export {};\r\n';
|
|
66
64
|
}
|
|
67
65
|
const filePath = path.resolve(distPath);
|
|
68
|
-
console.log(`Writing ${pluginName} plugins to ${filePath}`);
|
|
66
|
+
!silent && console.log(`Writing ${pluginName} plugins to ${filePath}`);
|
|
69
67
|
fs.writeFileSync(filePath, fileContent, {
|
|
70
68
|
encoding: 'utf8',
|
|
71
69
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
/**
|
|
3
3
|
* Generate component builder template
|
|
4
|
-
* @param {(PackageDefinition | ComponentFile)[]}components components to include in component builder
|
|
4
|
+
* @param {(PackageDefinition | ComponentFile)[]} components components to include in component builder
|
|
5
5
|
* @param {string} distPath destination path for component builder
|
|
6
6
|
* @returns generated component builder template
|
|
7
7
|
*/
|
package/nextjs.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types/templating/nextjs/index';
|
package/nextjs.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-dev-tools",
|
|
3
|
-
"version": "21.2.0-canary.
|
|
3
|
+
"version": "21.2.0-canary.36",
|
|
4
4
|
"description": "Utilities to assist in the development and deployment of Sitecore JSS apps.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"url": "https://github.com/sitecore/jss/issues"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@sitecore-jss/sitecore-jss": "^21.2.0-canary.
|
|
36
|
+
"@sitecore-jss/sitecore-jss": "^21.2.0-canary.36",
|
|
37
37
|
"axios": "^1.3.2",
|
|
38
38
|
"chalk": "^4.1.2",
|
|
39
39
|
"chokidar": "^3.5.3",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"typescript": "~4.9.5"
|
|
85
85
|
},
|
|
86
86
|
"types": "types/index.d.ts",
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "a37e8ba8b467c29b9c8c8c1aca111ca673d66b04",
|
|
88
88
|
"files": [
|
|
89
89
|
"dist",
|
|
90
90
|
"types",
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { PackageDefinition } from '../components';
|
|
2
|
+
/**
|
|
3
|
+
* Generate component builder based on provided settings
|
|
4
|
+
* @param {Object} [settings] settings for component builder generation
|
|
5
|
+
* @param {string} [settings.componentRootPath] path to components root
|
|
6
|
+
* @param {string} [settings.componentBuilderOutputPath] path to component builder output
|
|
7
|
+
* @param {PackageDefinition[]} [settings.packages] list of packages to include in component builder
|
|
8
|
+
* @param {boolean} [settings.watch] whether to watch for changes to component builder sources
|
|
9
|
+
*/
|
|
10
|
+
export declare function generateComponentBuilder({ componentRootPath, componentBuilderOutputPath, packages, watch, }?: {
|
|
11
|
+
componentRootPath?: string;
|
|
12
|
+
componentBuilderOutputPath?: string;
|
|
13
|
+
packages?: PackageDefinition[];
|
|
14
|
+
watch?: boolean;
|
|
15
|
+
}): void;
|
|
16
|
+
/**
|
|
17
|
+
* Watch for changes to component builder sources
|
|
18
|
+
* @param {Object} settings settings for component builder generation
|
|
19
|
+
* @param {string} settings.componentRootPath path to components root
|
|
20
|
+
* @param {string} settings.componentBuilderOutputPath path to component builder output
|
|
21
|
+
* @param {PackageDefinition[]} settings.packages list of packages to include in component builder
|
|
22
|
+
*/
|
|
23
|
+
export declare function watchComponentBuilder({ componentRootPath, componentBuilderOutputPath, packages, }: {
|
|
24
|
+
componentRootPath: string;
|
|
25
|
+
componentBuilderOutputPath: string;
|
|
26
|
+
packages: PackageDefinition[];
|
|
27
|
+
}): void;
|
|
28
|
+
/**
|
|
29
|
+
* Write component builder to file
|
|
30
|
+
* @param {Object} settings settings for component builder generation
|
|
31
|
+
* @param {string} settings.componentRootPath path to components root
|
|
32
|
+
* @param {string} settings.componentBuilderOutputPath path to component builder output
|
|
33
|
+
* @param {PackageDefinition[]} settings.packages list of packages to include in component builder
|
|
34
|
+
*/
|
|
35
|
+
export declare function writeComponentBuilder({ componentRootPath, componentBuilderOutputPath, packages, }: {
|
|
36
|
+
componentRootPath: string;
|
|
37
|
+
componentBuilderOutputPath: string;
|
|
38
|
+
packages: PackageDefinition[];
|
|
39
|
+
}): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ComponentFile, PackageDefinition } from '../../components';
|
|
2
|
+
/**
|
|
3
|
+
* Generate component builder template
|
|
4
|
+
* @param {(PackageDefinition | ComponentFile)[]} components components to include in component builder
|
|
5
|
+
* @returns generated component builder template
|
|
6
|
+
*/
|
|
7
|
+
export declare const getComponentBuilderTemplate: (components: (PackageDefinition | ComponentFile)[]) => string;
|
|
@@ -29,9 +29,13 @@ export interface PluginDefinition {
|
|
|
29
29
|
*/
|
|
30
30
|
moduleType: ModuleType;
|
|
31
31
|
/**
|
|
32
|
-
* whether to use relative or absolute paths in the generated file. By default,
|
|
32
|
+
* whether to use relative or absolute paths in the generated file. By default, absolute paths are used.
|
|
33
33
|
*/
|
|
34
34
|
relative?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* whether to suppress console output
|
|
37
|
+
*/
|
|
38
|
+
silent?: boolean;
|
|
35
39
|
}
|
|
36
40
|
/**
|
|
37
41
|
* Get list of plugins from @var path
|
|
@@ -41,10 +45,16 @@ export interface PluginDefinition {
|
|
|
41
45
|
* name: 'fooPlugin'
|
|
42
46
|
* }
|
|
43
47
|
* @example getPluginList('src/foo/plugins', 'Foo')
|
|
44
|
-
* @param {
|
|
45
|
-
* @param {string}
|
|
48
|
+
* @param {Object} definition plugin definition
|
|
49
|
+
* @param {string} definition.path path to get plugin from
|
|
50
|
+
* @param {string} definition.pluginName plugin name
|
|
51
|
+
* @param {boolean} [definition.silent] whether to suppress console output
|
|
46
52
|
*/
|
|
47
|
-
export declare function getPluginList(path
|
|
53
|
+
export declare function getPluginList({ path, pluginName, silent, }: {
|
|
54
|
+
path: string;
|
|
55
|
+
pluginName: string;
|
|
56
|
+
silent?: boolean;
|
|
57
|
+
}): PluginFile[];
|
|
48
58
|
/**
|
|
49
59
|
* Generates the plugins file and saves it to the filesystem.
|
|
50
60
|
* By convention, we expect to find plugins under {pluginName}/plugins/** (subfolders are searched recursively).
|
|
@@ -52,10 +62,6 @@ export declare function getPluginList(path: string, pluginName: string): PluginF
|
|
|
52
62
|
* CJS: exports.fooPlugin = require('{pluginPath}');
|
|
53
63
|
* ESM: export { fooPlugin } from '{pluginPath}';
|
|
54
64
|
* @example generatePlugins({ distPath: 'src/temp/foo-plugins.js', rootPath: 'src/foo/plugins', moduleType: ModuleType.CJS })
|
|
55
|
-
* @param {
|
|
56
|
-
* @param {string} definition.distPath path to write plugins to
|
|
57
|
-
* @param {string} definition.rootPath plugin source path
|
|
58
|
-
* @param {string} definition.moduleType module type: CJS or ESM
|
|
59
|
-
* @param {boolean} [definition.relative] whether to use relative paths in the generated file. By default, absolute paths are used.
|
|
65
|
+
* @param {PluginDefinition} definition plugin definition
|
|
60
66
|
*/
|
|
61
67
|
export declare function generatePlugins(definition: PluginDefinition): void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ComponentFile, PackageDefinition } from '../../components';
|
|
2
2
|
/**
|
|
3
3
|
* Generate component builder template
|
|
4
|
-
* @param {(PackageDefinition | ComponentFile)[]}components components to include in component builder
|
|
4
|
+
* @param {(PackageDefinition | ComponentFile)[]} components components to include in component builder
|
|
5
5
|
* @param {string} distPath destination path for component builder
|
|
6
6
|
* @returns generated component builder template
|
|
7
7
|
*/
|