@sitecore-jss/sitecore-jss-dev-tools 22.0.0-canary.9 → 22.1.0-canary.2

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 (52) hide show
  1. package/README.md +7 -2
  2. package/dist/cjs/index.js +2 -3
  3. package/dist/cjs/pipelines/runner.js +2 -2
  4. package/dist/cjs/templating/components.js +27 -0
  5. package/dist/cjs/templating/index.js +14 -0
  6. package/dist/cjs/templating/metadata.js +32 -0
  7. package/dist/cjs/templating/nextjs/component-props.loader.js +91 -0
  8. package/dist/cjs/templating/nextjs/generate-component-builder.js +72 -0
  9. package/dist/cjs/templating/nextjs/index.js +7 -0
  10. package/dist/cjs/templating/nextjs/templates/component-builder.js +59 -0
  11. package/dist/cjs/templating/plugins.js +78 -0
  12. package/dist/cjs/templating/react/generate-component-builder.js +64 -0
  13. package/dist/cjs/templating/react/index.js +7 -0
  14. package/dist/cjs/templating/react/templates/component-builder.js +49 -0
  15. package/dist/cjs/templating/scaffold.js +38 -0
  16. package/dist/cjs/templating/utils.js +56 -0
  17. package/dist/esm/index.js +1 -1
  18. package/dist/esm/pipelines/runner.js +2 -2
  19. package/dist/esm/templating/components.js +23 -0
  20. package/dist/esm/templating/index.js +5 -0
  21. package/dist/esm/templating/metadata.js +25 -0
  22. package/dist/esm/templating/nextjs/component-props.loader.js +65 -0
  23. package/dist/esm/templating/nextjs/generate-component-builder.js +63 -0
  24. package/dist/esm/templating/nextjs/index.js +2 -0
  25. package/dist/esm/templating/nextjs/templates/component-builder.js +55 -0
  26. package/dist/esm/templating/plugins.js +70 -0
  27. package/dist/esm/templating/react/generate-component-builder.js +55 -0
  28. package/dist/esm/templating/react/index.js +2 -0
  29. package/dist/esm/templating/react/templates/component-builder.js +42 -0
  30. package/dist/esm/templating/scaffold.js +30 -0
  31. package/dist/esm/templating/utils.js +48 -0
  32. package/nextjs-component-props-loader.d.ts +1 -0
  33. package/nextjs-component-props-loader.js +3 -0
  34. package/nextjs.d.ts +1 -0
  35. package/nextjs.js +3 -0
  36. package/package.json +12 -8
  37. package/react.d.ts +1 -0
  38. package/react.js +3 -0
  39. package/types/index.d.ts +2 -1
  40. package/types/templating/components.d.ts +29 -0
  41. package/types/templating/index.d.ts +5 -0
  42. package/types/templating/metadata.d.ts +5 -0
  43. package/types/templating/nextjs/component-props.loader.d.ts +7 -0
  44. package/types/templating/nextjs/generate-component-builder.d.ts +45 -0
  45. package/types/templating/nextjs/index.d.ts +2 -0
  46. package/types/templating/nextjs/templates/component-builder.d.ts +7 -0
  47. package/types/templating/plugins.d.ts +67 -0
  48. package/types/templating/react/generate-component-builder.d.ts +39 -0
  49. package/types/templating/react/index.d.ts +2 -0
  50. package/types/templating/react/templates/component-builder.d.ts +8 -0
  51. package/types/templating/scaffold.d.ts +15 -0
  52. package/types/templating/utils.d.ts +38 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-jss/sitecore-jss-dev-tools",
3
- "version": "22.0.0-canary.9",
3
+ "version": "22.1.0-canary.2",
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",
@@ -9,15 +9,14 @@
9
9
  "build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig-esm.json",
10
10
  "watch": "npm run build -- --watch",
11
11
  "clean": "del-cli dist types",
12
- "lint": "eslint ./src/**/*.ts",
12
+ "lint": "eslint \"./src/**/*.ts\"",
13
13
  "test": "mocha --require ts-node/register -r tsconfig-paths/register \"./src/**/*.test.ts\"",
14
14
  "prepublishOnly": "npm run build",
15
15
  "coverage": "nyc npm test",
16
16
  "generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --readme none --out ../../ref-docs/sitecore-jss-dev-tools src/index.ts --githubPages false"
17
17
  },
18
18
  "engines": {
19
- "node": ">=12",
20
- "npm": ">=6"
19
+ "node": ">=18"
21
20
  },
22
21
  "bin": {
23
22
  "scjss-deploy": "./dist/cjs/bin/deploy.js",
@@ -33,7 +32,8 @@
33
32
  "url": "https://github.com/sitecore/jss/issues"
34
33
  },
35
34
  "dependencies": {
36
- "@sitecore-jss/sitecore-jss": "^22.0.0-canary.9",
35
+ "@babel/parser": "^7.24.0",
36
+ "@sitecore-jss/sitecore-jss": "^22.1.0-canary.2",
37
37
  "axios": "^1.3.2",
38
38
  "chalk": "^4.1.2",
39
39
  "chokidar": "^3.5.3",
@@ -48,6 +48,7 @@
48
48
  "jszip": "^3.10.1",
49
49
  "module-alias": "^2.2.2",
50
50
  "readline-sync": "^1.4.10",
51
+ "recast": "^0.23.5",
51
52
  "resolve": "^1.22.1",
52
53
  "ts-node": "^10.9.1",
53
54
  "url-join": "^4.0.1",
@@ -55,6 +56,8 @@
55
56
  "yargs": "^17.6.2"
56
57
  },
57
58
  "devDependencies": {
59
+ "@babel/core": "^7.24.4",
60
+ "@babel/register": "^7.23.7",
58
61
  "@types/chai": "^4.3.4",
59
62
  "@types/chokidar": "^2.1.3",
60
63
  "@types/del": "^4.0.0",
@@ -70,7 +73,6 @@
70
73
  "@types/url-join": "^4.0.1",
71
74
  "@types/uuid": "^9.0.0",
72
75
  "@types/yargs": "^17.0.22",
73
- "babel-core": "^6.26.3",
74
76
  "chai": "^4.3.7",
75
77
  "cross-env": "^7.0.3",
76
78
  "del-cli": "^5.0.0",
@@ -84,9 +86,11 @@
84
86
  "typescript": "~4.9.5"
85
87
  },
86
88
  "types": "types/index.d.ts",
87
- "gitHead": "f28c2255e8bc93787848a7778b6a32355590e7b4",
89
+ "gitHead": "2b1c20b7ab1f2bc95bc9e363a944a12bac7363f1",
88
90
  "files": [
89
91
  "dist",
90
- "types"
92
+ "types",
93
+ "/*.js",
94
+ "/*.d.ts"
91
95
  ]
92
96
  }
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,8 @@ 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 { Metadata } from '@sitecore-jss/sitecore-jss/utils';
17
+ export * from './templating';
17
18
  export * from './manifest';
18
19
  export * from './pipelines';
19
20
  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): ComponentFile[];
@@ -0,0 +1,5 @@
1
+ export { ComponentFile, PackageDefinition, getComponentList } from './components';
2
+ export { PluginDefinition, generatePlugins, ModuleType } from './plugins';
3
+ export { scaffoldFile } from './scaffold';
4
+ export { strip } from './strip';
5
+ export { getMetadata } from './metadata';
@@ -0,0 +1,5 @@
1
+ import { Metadata } from '@sitecore-jss/sitecore-jss/utils';
2
+ /**
3
+ * Get application metadata
4
+ */
5
+ export declare function getMetadata(): Metadata;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Webpack loader to strip functions from the source code
3
+ * Strips the `getServerSideProps` and `getStaticProps` functions from the source code
4
+ * @param {string} source file source code
5
+ * @returns {string} output file source code with stripped functions
6
+ */
7
+ export default function componentPropsLoader(source: string): string;
@@ -0,0 +1,45 @@
1
+ import { ComponentFile, 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 {ComponentFile[]} [settings.components] list of components to include in component builder
9
+ * @param {boolean} [settings.watch] whether to watch for changes to component builder sources
10
+ */
11
+ export declare function generateComponentBuilder({ componentRootPath, componentBuilderOutputPath, packages, components, watch, }?: {
12
+ componentRootPath?: string;
13
+ componentBuilderOutputPath?: string;
14
+ packages?: PackageDefinition[];
15
+ components?: ComponentFile[];
16
+ watch?: boolean;
17
+ }): void;
18
+ /**
19
+ * Watch for changes to component builder sources
20
+ * @param {Object} settings settings for component builder generation
21
+ * @param {string} settings.componentRootPath path to components root
22
+ * @param {string} settings.componentBuilderOutputPath path to component builder output
23
+ * @param {PackageDefinition[]} settings.packages list of packages to include in component builder
24
+ * @param {ComponentFile[]} settings.components list of components to include in component builder
25
+ */
26
+ export declare function watchComponentBuilder({ componentRootPath, componentBuilderOutputPath, packages, components, }: {
27
+ componentRootPath: string;
28
+ componentBuilderOutputPath: string;
29
+ packages: PackageDefinition[];
30
+ components: ComponentFile[];
31
+ }): void;
32
+ /**
33
+ * Write component builder to file
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
+ * @param {ComponentFile[]} settings.components list of components to include in component builder
39
+ */
40
+ export declare function writeComponentBuilder({ componentRootPath, componentBuilderOutputPath, packages, components, }: {
41
+ componentRootPath: string;
42
+ componentBuilderOutputPath: string;
43
+ packages: PackageDefinition[];
44
+ components: ComponentFile[];
45
+ }): 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,39 @@
1
+ import { ComponentFile, 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 {ComponentFile[]} [settings.components] list of components 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, packages, components, watch, }: {
11
+ componentRootPath?: string;
12
+ packages?: PackageDefinition[];
13
+ components?: ComponentFile[];
14
+ watch?: boolean;
15
+ }): void;
16
+ /**
17
+ * Watch for changes to component builder sources
18
+ * @param {object} config configuration for component builder watcher
19
+ * @param {string} config.componentRootPath root path to components
20
+ * @param {PackageDefinition[]} config.packages packages to include in component builder
21
+ * @param {ComponentFile[]} config.components components to include in component builder
22
+ */
23
+ export declare function watchComponentBuilder({ componentRootPath, packages, components, }: {
24
+ componentRootPath: string;
25
+ packages: PackageDefinition[];
26
+ components: ComponentFile[];
27
+ }): void;
28
+ /**
29
+ * Write component builder to file
30
+ * @param {Object} settings settings for component builder generation
31
+ * @param {string} settings.componentRootPath root path to components
32
+ * @param {PackageDefinition[]} settings.packages packages to include in component builder
33
+ * @param {ComponentFile[]} settings.components list of components to include in component builder
34
+ */
35
+ export declare function writeComponentBuilder({ componentRootPath, packages, components, }: {
36
+ componentRootPath: string;
37
+ packages: PackageDefinition[];
38
+ components: ComponentFile[];
39
+ }): 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;