@sitecore-jss/sitecore-jss-dev-tools 21.2.0-canary.9 → 21.2.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.
Files changed (43) hide show
  1. package/LICENSE.txt +202 -202
  2. package/README.md +7 -7
  3. package/dist/cjs/index.js +2 -3
  4. package/dist/cjs/templating/components.js +27 -0
  5. package/dist/cjs/templating/index.js +10 -0
  6. package/dist/cjs/templating/nextjs/generate-component-builder.js +61 -0
  7. package/dist/cjs/templating/nextjs/index.js +7 -0
  8. package/dist/cjs/templating/nextjs/templates/component-builder.js +54 -0
  9. package/dist/cjs/templating/plugins.js +78 -0
  10. package/dist/cjs/templating/react/generate-component-builder.js +56 -0
  11. package/dist/cjs/templating/react/index.js +7 -0
  12. package/dist/cjs/templating/react/templates/component-builder.js +48 -0
  13. package/dist/cjs/templating/scaffold.js +38 -0
  14. package/dist/cjs/templating/utils.js +56 -0
  15. package/dist/esm/index.js +1 -1
  16. package/dist/esm/templating/components.js +23 -0
  17. package/dist/esm/templating/index.js +3 -0
  18. package/dist/esm/templating/nextjs/generate-component-builder.js +52 -0
  19. package/dist/esm/templating/nextjs/index.js +2 -0
  20. package/dist/esm/templating/nextjs/templates/component-builder.js +50 -0
  21. package/dist/esm/templating/plugins.js +70 -0
  22. package/dist/esm/templating/react/generate-component-builder.js +47 -0
  23. package/dist/esm/templating/react/index.js +2 -0
  24. package/dist/esm/templating/react/templates/component-builder.js +41 -0
  25. package/dist/esm/templating/scaffold.js +30 -0
  26. package/dist/esm/templating/utils.js +48 -0
  27. package/nextjs.d.ts +1 -0
  28. package/nextjs.js +3 -0
  29. package/package.json +6 -4
  30. package/react.d.ts +1 -0
  31. package/react.js +3 -0
  32. package/types/index.d.ts +1 -1
  33. package/types/templating/components.d.ts +29 -0
  34. package/types/templating/index.d.ts +4 -0
  35. package/types/templating/nextjs/generate-component-builder.d.ts +39 -0
  36. package/types/templating/nextjs/index.d.ts +2 -0
  37. package/types/templating/nextjs/templates/component-builder.d.ts +7 -0
  38. package/types/templating/plugins.d.ts +67 -0
  39. package/types/templating/react/generate-component-builder.d.ts +25 -0
  40. package/types/templating/react/index.d.ts +2 -0
  41. package/types/templating/react/templates/component-builder.d.ts +8 -0
  42. package/types/templating/scaffold.d.ts +15 -0
  43. package/types/templating/utils.d.ts +38 -0
@@ -0,0 +1,48 @@
1
+ import fs from 'fs';
2
+ import chokidar from 'chokidar';
3
+ /**
4
+ * Using @var path find all files and generate output using @var resolveItem function for each file
5
+ * Can be used to generate list of components, templates, etc.
6
+ * @param {GetItemsSettings} settings
7
+ * @returns {Item[]} list of items
8
+ */
9
+ export function getItems(settings) {
10
+ const { recursive = true, path, resolveItem, cb, fileFormat = new RegExp(/(.+)(?<!\.d)\.[jt]sx?$/), } = settings;
11
+ const items = [];
12
+ const folders = [];
13
+ if (!fs.existsSync(path))
14
+ return [];
15
+ fs.readdirSync(path, { withFileTypes: true }).forEach((item) => {
16
+ if (item.isDirectory()) {
17
+ folders.push(item);
18
+ }
19
+ if (fileFormat.test(item.name)) {
20
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
21
+ const name = item.name.match(fileFormat)[1];
22
+ items.push(resolveItem(path, name));
23
+ cb && cb(name);
24
+ }
25
+ });
26
+ for (const folder of folders) {
27
+ recursive
28
+ ? items.push(...getItems({
29
+ path: `${path}/${folder.name}`,
30
+ resolveItem,
31
+ cb,
32
+ fileFormat,
33
+ }))
34
+ : items.push(resolveItem(`${path}/${folder.name}`, folder.name));
35
+ }
36
+ return items;
37
+ }
38
+ /**
39
+ * Run watch mode, watching on @var paths
40
+ * @param {string[]} paths paths to watch by chokidar
41
+ * @param {Function<void>} cb callback to run on file change
42
+ */
43
+ export function watchItems(paths, cb) {
44
+ chokidar
45
+ .watch(paths, { ignoreInitial: true, awaitWriteFinish: true })
46
+ .on('add', cb)
47
+ .on('unlink', cb);
48
+ }
package/nextjs.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './types/templating/nextjs/index';
package/nextjs.js ADDED
@@ -0,0 +1,3 @@
1
+ const templating = require('./dist/cjs/templating/nextjs/index');
2
+
3
+ module.exports = { ...templating };
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.9",
3
+ "version": "21.2.0",
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.9",
36
+ "@sitecore-jss/sitecore-jss": "21.2.0",
37
37
  "axios": "^1.3.2",
38
38
  "chalk": "^4.1.2",
39
39
  "chokidar": "^3.5.3",
@@ -84,9 +84,11 @@
84
84
  "typescript": "~4.9.5"
85
85
  },
86
86
  "types": "types/index.d.ts",
87
- "gitHead": "d4ac1db367d5ce2060cd22d543c38019b1d230bb",
87
+ "gitHead": "579fe8bc9bf89855b9f878fca9d0430e10a36fd0",
88
88
  "files": [
89
89
  "dist",
90
- "types"
90
+ "types",
91
+ "/*.js",
92
+ "/*.d.ts"
91
93
  ]
92
94
  }
package/react.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './types/templating/react/index';
package/react.js ADDED
@@ -0,0 +1,3 @@
1
+ const templating = require('./dist/cjs/templating/react/index');
2
+
3
+ module.exports = { ...templating };
package/types/index.d.ts CHANGED
@@ -13,7 +13,7 @@ export { createDisconnectedDictionaryService, DisconnectedDictionaryServiceOptio
13
13
  export { createDefaultDocumentMiddleware, DefaultDocumentMiddlewareOptions, } from './disconnected-server/default-document';
14
14
  export { createDefaultDisconnectedServer, DisconnectedServerOptions, } from './disconnected-server/create-default-disconnected-server';
15
15
  export { ScJssConfig, JssConfiguration, resolveScJssConfig } from './resolve-scjssconfig';
16
- export { strip } from './templating/strip';
16
+ export * from './templating';
17
17
  export * from './manifest';
18
18
  export * from './pipelines';
19
19
  export * from './update';
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Describes a file that represents a component definition
3
+ */
4
+ export interface ComponentFile {
5
+ path: string;
6
+ moduleName: string;
7
+ componentName: string;
8
+ }
9
+ /**
10
+ * Describes a package and components to be imported
11
+ */
12
+ export interface PackageDefinition {
13
+ name: string;
14
+ components: {
15
+ moduleName: string;
16
+ componentName: string;
17
+ }[];
18
+ }
19
+ /**
20
+ * Get list of components from @var path
21
+ * Returns a list of components in the following format:
22
+ * {
23
+ * path: 'path/to/component',
24
+ * componentName: 'ComponentName',
25
+ * moduleName: 'ComponentName'
26
+ * }
27
+ * @param {string} path path to search
28
+ */
29
+ export declare function getComponentList(path: string): (PackageDefinition | ComponentFile)[];
@@ -0,0 +1,4 @@
1
+ export { ComponentFile, PackageDefinition } from './components';
2
+ export { PluginDefinition, generatePlugins, ModuleType } from './plugins';
3
+ export { scaffoldFile } from './scaffold';
4
+ export { strip } from './strip';
@@ -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,2 @@
1
+ export { generateComponentBuilder } from './generate-component-builder';
2
+ export { getComponentBuilderTemplate } from './templates/component-builder';
@@ -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;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Identifies the format of the module to be compiled
3
+ */
4
+ export declare enum ModuleType {
5
+ CJS = 0,
6
+ ESM = 1
7
+ }
8
+ /**
9
+ * Type to specify plugin file details
10
+ */
11
+ export interface PluginFile {
12
+ path: string;
13
+ name: string;
14
+ }
15
+ /**
16
+ * Definition to be used for plugin registration during bootstrap
17
+ */
18
+ export interface PluginDefinition {
19
+ /**
20
+ * destination path to compile plugins to
21
+ */
22
+ distPath: string;
23
+ /**
24
+ * source path for where the plugins are defined
25
+ */
26
+ rootPath: string;
27
+ /**
28
+ * CJS or ESM - which type to compile plugins to
29
+ */
30
+ moduleType: ModuleType;
31
+ /**
32
+ * whether to use relative or absolute paths in the generated file. By default, absolute paths are used.
33
+ */
34
+ relative?: boolean;
35
+ /**
36
+ * whether to suppress console output
37
+ */
38
+ silent?: boolean;
39
+ }
40
+ /**
41
+ * Get list of plugins from @var path
42
+ * Returns a list of plugins in the following format:
43
+ * {
44
+ * path: 'path/to/plugin/foo',
45
+ * name: 'fooPlugin'
46
+ * }
47
+ * @example getPluginList('src/foo/plugins', 'Foo')
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
52
+ */
53
+ export declare function getPluginList({ path, pluginName, silent, }: {
54
+ path: string;
55
+ pluginName: string;
56
+ silent?: boolean;
57
+ }): PluginFile[];
58
+ /**
59
+ * Generates the plugins file and saves it to the filesystem.
60
+ * By convention, we expect to find plugins under {pluginName}/plugins/** (subfolders are searched recursively).
61
+ * generated file will be saved to @var {distPath} and will contain a list of plugins in the following format:
62
+ * CJS: exports.fooPlugin = require('{pluginPath}');
63
+ * ESM: export { fooPlugin } from '{pluginPath}';
64
+ * @example generatePlugins({ distPath: 'src/temp/foo-plugins.js', rootPath: 'src/foo/plugins', moduleType: ModuleType.CJS })
65
+ * @param {PluginDefinition} definition plugin definition
66
+ */
67
+ export declare function generatePlugins(definition: PluginDefinition): void;
@@ -0,0 +1,25 @@
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 {PackageDefinition[]} settings.packages list of packages to include in component builder
7
+ * @param {boolean} settings.watch whether to watch for changes to component builder sources
8
+ */
9
+ export declare function generateComponentBuilder({ componentRootPath, packages, watch, }: {
10
+ componentRootPath?: string;
11
+ packages?: PackageDefinition[];
12
+ watch?: boolean;
13
+ }): void;
14
+ /**
15
+ * Watch for changes to component builder sources
16
+ * @param {string} componentRootPath root path to components
17
+ * @param {PackageDefinition[]} [packages] packages to include in component builder
18
+ */
19
+ export declare function watchComponentBuilder(componentRootPath: string, packages?: PackageDefinition[]): void;
20
+ /**
21
+ * Write component builder to file
22
+ * @param {string} componentRootPath root path to components
23
+ * @param {PackageDefinition[]} [packages] packages to include in component builder
24
+ */
25
+ export declare function writeComponentBuilder(componentRootPath: string, packages?: PackageDefinition[]): void;
@@ -0,0 +1,2 @@
1
+ export { getComponentBuilderTemplate } from './templates/component-builder';
2
+ export { generateComponentBuilder } from './generate-component-builder';
@@ -0,0 +1,8 @@
1
+ import { ComponentFile, PackageDefinition } from '../../components';
2
+ /**
3
+ * Generate component builder template
4
+ * @param {(PackageDefinition | ComponentFile)[]} components components to include in component builder
5
+ * @param {string} distPath destination path for component builder
6
+ * @returns generated component builder template
7
+ */
8
+ export declare const getComponentBuilderTemplate: (components: (PackageDefinition | ComponentFile)[], distPath: string) => string;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Force to use `crlf` line endings, we are using `crlf` across the project.
3
+ * Replace: `lf` (\n), `cr` (\r)
4
+ * @param {string} content
5
+ */
6
+ export declare function editLineEndings(content: string): string;
7
+ /**
8
+ * Creates a file relative to the specified path if the file doesn't exist.
9
+ * Creates directories as needed.
10
+ * Does not overwrite existing files.
11
+ * @param {string} filePath - the file path
12
+ * @param {string} fileContent - the file content
13
+ * @returns {string} the file path if the file was created, otherwise null
14
+ */
15
+ export declare function scaffoldFile(filePath: string, fileContent: string): string | null;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Settings for @var getItems function
3
+ */
4
+ export type GetItemsSettings<Item> = {
5
+ /**
6
+ * items path
7
+ */
8
+ path: string;
9
+ /**
10
+ * Resolve item in required data format
11
+ */
12
+ resolveItem: (path: string, name: string) => Item;
13
+ /**
14
+ * Will be called when new file is found
15
+ */
16
+ cb?: (name: string) => void;
17
+ /**
18
+ * Matches specific files format
19
+ */
20
+ fileFormat?: RegExp;
21
+ /**
22
+ * Wether to search recursively
23
+ */
24
+ recursive?: boolean;
25
+ };
26
+ /**
27
+ * Using @var path find all files and generate output using @var resolveItem function for each file
28
+ * Can be used to generate list of components, templates, etc.
29
+ * @param {GetItemsSettings} settings
30
+ * @returns {Item[]} list of items
31
+ */
32
+ export declare function getItems<Item>(settings: GetItemsSettings<Item>): Item[];
33
+ /**
34
+ * Run watch mode, watching on @var paths
35
+ * @param {string[]} paths paths to watch by chokidar
36
+ * @param {Function<void>} cb callback to run on file change
37
+ */
38
+ export declare function watchItems(paths: string[], cb: () => void): void;