create-content-sdk-app 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.
Files changed (71) hide show
  1. package/README.md +5 -5
  2. package/dist/bin.js +119 -119
  3. package/dist/common/base/Initializer.js +2 -2
  4. package/dist/common/base/args.js +2 -2
  5. package/dist/common/base/prompts.js +7 -7
  6. package/dist/common/index.js +18 -18
  7. package/dist/common/processes/install.js +55 -55
  8. package/dist/common/processes/next.js +63 -63
  9. package/dist/common/processes/transform.js +115 -115
  10. package/dist/common/utils/cmd.js +53 -53
  11. package/dist/common/utils/helpers.js +80 -80
  12. package/dist/index.js +6 -6
  13. package/dist/initialize.js +71 -71
  14. package/dist/initializers/nextjs/args.js +2 -2
  15. package/dist/initializers/nextjs/index.js +30 -30
  16. package/dist/initializers/nextjs/prompts.js +26 -26
  17. package/dist/initializers/nextjs-app-router (beta)/args.js +2 -2
  18. package/dist/initializers/nextjs-app-router (beta)/index.js +30 -30
  19. package/dist/initializers/nextjs-app-router (beta)/prompts.js +26 -26
  20. package/dist/templates/nextjs/.cursor/rules/general.mdc +81 -81
  21. package/dist/templates/nextjs/.cursor/rules/javascript.mdc +112 -112
  22. package/dist/templates/nextjs/.cursor/rules/project-setup.mdc +100 -100
  23. package/dist/templates/nextjs/.cursor/rules/sitecore.mdc +147 -147
  24. package/dist/templates/nextjs/.env.container.example +27 -27
  25. package/dist/templates/nextjs/.env.remote.example +45 -44
  26. package/dist/templates/nextjs/.gitattributes +11 -11
  27. package/dist/templates/nextjs/.prettierrc +8 -8
  28. package/dist/templates/nextjs/.vscode/extensions.json +8 -8
  29. package/dist/templates/nextjs/.vscode/launch.json +15 -15
  30. package/dist/templates/nextjs/.windsurfrules +183 -183
  31. package/dist/templates/nextjs/CLAUDE.md +170 -170
  32. package/dist/templates/nextjs/LICENSE.txt +202 -202
  33. package/dist/templates/nextjs/LLMs.txt +179 -179
  34. package/dist/templates/nextjs/README.md +7 -7
  35. package/dist/templates/nextjs/copilot-instructions.md +170 -170
  36. package/dist/templates/nextjs/eslint.config.mjs +81 -81
  37. package/dist/templates/nextjs/gitignore +28 -28
  38. package/dist/templates/nextjs/package.json +68 -68
  39. package/dist/templates/nextjs/sitecore.config.ts.example +38 -38
  40. package/dist/templates/nextjs/src/middleware.ts +16 -7
  41. package/dist/templates/nextjs/tsconfig.json +40 -40
  42. package/dist/templates/nextjs-app-router (beta)/.cursor/rules/app-router-setup.mdc +116 -116
  43. package/dist/templates/nextjs-app-router (beta)/.cursor/rules/general.mdc +80 -80
  44. package/dist/templates/nextjs-app-router (beta)/.cursor/rules/javascript.mdc +112 -112
  45. package/dist/templates/nextjs-app-router (beta)/.cursor/rules/sitecore.mdc +171 -171
  46. package/dist/templates/nextjs-app-router (beta)/.env.container.example +27 -27
  47. package/dist/templates/nextjs-app-router (beta)/.env.remote.example +45 -44
  48. package/dist/templates/nextjs-app-router (beta)/.gitattributes +11 -11
  49. package/dist/templates/nextjs-app-router (beta)/.sitecore/import-map.server.ts +60 -0
  50. package/dist/templates/nextjs-app-router (beta)/.windsurfrules +287 -287
  51. package/dist/templates/nextjs-app-router (beta)/CLAUDE.md +271 -271
  52. package/dist/templates/nextjs-app-router (beta)/LLMs.txt +236 -236
  53. package/dist/templates/nextjs-app-router (beta)/README.md +7 -7
  54. package/dist/templates/nextjs-app-router (beta)/copilot-instructions.md +271 -271
  55. package/dist/templates/nextjs-app-router (beta)/eslint.config.mjs +29 -29
  56. package/dist/templates/nextjs-app-router (beta)/gitignore +31 -29
  57. package/dist/templates/nextjs-app-router (beta)/package.json +54 -54
  58. package/dist/templates/nextjs-app-router (beta)/postcss.config.mjs +5 -5
  59. package/dist/templates/nextjs-app-router (beta)/sitecore.config.ts.example +38 -38
  60. package/dist/templates/nextjs-app-router (beta)/src/Layout.tsx +9 -3
  61. package/dist/templates/nextjs-app-router (beta)/src/Providers.tsx +9 -17
  62. package/dist/templates/nextjs-app-router (beta)/src/app/[site]/[locale]/[[...path]]/page.tsx +1 -5
  63. package/dist/templates/nextjs-app-router (beta)/src/app/api/editing/config/route.ts +2 -0
  64. package/dist/templates/nextjs-app-router (beta)/src/app/api/editing/render/route.ts +1 -1
  65. package/dist/templates/nextjs-app-router (beta)/src/app/globals.css +1 -1
  66. package/dist/templates/nextjs-app-router (beta)/src/middleware.ts +12 -1
  67. package/dist/templates/nextjs-app-router (beta)/tsconfig.json +48 -48
  68. package/package.json +73 -74
  69. package/LICENSE.MD +0 -202
  70. package/dist/templates/nextjs-app-router (beta)/src/DesignLibraryLayout.tsx +0 -7
  71. /package/dist/templates/nextjs-app-router (beta)/.sitecore/{import-map.ts → import-map.client.ts} +0 -0
@@ -1,115 +1,115 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- var __importDefault = (this && this.__importDefault) || function (mod) {
45
- return (mod && mod.__esModule) ? mod : { "default": mod };
46
- };
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.transform = exports.populateEjsData = void 0;
49
- const chalk_1 = __importDefault(require("chalk"));
50
- const fs_extra_1 = __importDefault(require("fs-extra"));
51
- const glob = __importStar(require("glob"));
52
- const path_1 = __importStar(require("path"));
53
- const ejs_1 = require("ejs");
54
- const helpers_1 = require("../utils/helpers");
55
- const { version } = require('../../../package.json');
56
- const FILE_FOR_COPY_REGEXP = /(index\.html)$|\.(gif|jpg|jpeg|tiff|png|svg|ashx|ico|pdf|jar|eot|woff|ttf|woff2)$/;
57
- const populateEjsData = (args, destination) => {
58
- // pass in helper to args object
59
- // Use exact version for Content SDK dependencies in beta and canary versions
60
- const contentSdkVersion = version.match(/(\-[a-zA-Z]+\.\d+)$/) ? version : `~${version}`;
61
- const ejsData = Object.assign(Object.assign({}, args), { version: contentSdkVersion, helper: {
62
- isDev: (0, helpers_1.isDevEnvironment)(destination || args.destination),
63
- } });
64
- return ejsData;
65
- };
66
- exports.populateEjsData = populateEjsData;
67
- /**
68
- * Handles each template file and applies ejs renderer, also:
69
- * - Determines files for copy.
70
- * - Determines files for skip.
71
- * @param {string} templatePath path to the template
72
- * @param {BaseArgs} args CLI arguments
73
- * @param {TransformOptions} options custom options
74
- */
75
- const transform = (templatePath_1, args_1, ...args_2) => __awaiter(void 0, [templatePath_1, args_1, ...args_2], void 0, function* (templatePath, args, options = {}) {
76
- const { isFileForCopy, isFileForSkip, fileForCopyRegExp = FILE_FOR_COPY_REGEXP } = options;
77
- const destinationPath = path_1.default.resolve(args.destination);
78
- const ejsData = (0, exports.populateEjsData)(args);
79
- // the templates to be run through ejs render or copied directly
80
- const files = glob.sync('**/*', {
81
- cwd: templatePath,
82
- dot: true,
83
- nodir: true,
84
- });
85
- for (const file of files) {
86
- try {
87
- let pathToNewFile = `${destinationPath}${path_1.sep}${file}`;
88
- const pathToTemplate = path_1.default.join(templatePath, file);
89
- // Rename gitignore after the fact to prevent npm from renaming it to .npmignore
90
- // See: https://github.com/npm/npm/issues/1862
91
- if (!file.endsWith('.gitignore') && file.endsWith('gitignore')) {
92
- pathToNewFile = pathToNewFile.replace(/\gitignore$/, '.gitignore');
93
- }
94
- if (isFileForSkip && isFileForSkip(file)) {
95
- continue;
96
- }
97
- // if the directory doesn't exist, create it
98
- fs_extra_1.default.mkdirsSync(path_1.default.dirname(pathToNewFile));
99
- if (isFileForCopy ? isFileForCopy(file, fileForCopyRegExp) : file.match(fileForCopyRegExp)) {
100
- // pdfs may have <% encoded, which throws an error for ejs.
101
- // we simply want to copy file if it's a pdf, not render it with ejs.
102
- fs_extra_1.default.copySync(pathToTemplate, pathToNewFile);
103
- continue;
104
- }
105
- // holds the content to be written to the new file
106
- const renderedFile = yield (0, ejs_1.renderFile)(path_1.default.resolve(pathToTemplate), ejsData);
107
- (0, helpers_1.writeFileToPath)(pathToNewFile, renderedFile);
108
- }
109
- catch (error) {
110
- console.log(chalk_1.default.red(error));
111
- console.log(`Error occurred when trying to render to ${chalk_1.default.yellow(path_1.default.resolve(file))}`);
112
- }
113
- }
114
- });
115
- exports.transform = transform;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ var __importDefault = (this && this.__importDefault) || function (mod) {
45
+ return (mod && mod.__esModule) ? mod : { "default": mod };
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.transform = exports.populateEjsData = void 0;
49
+ const chalk_1 = __importDefault(require("chalk"));
50
+ const fs_extra_1 = __importDefault(require("fs-extra"));
51
+ const glob = __importStar(require("glob"));
52
+ const path_1 = __importStar(require("path"));
53
+ const ejs_1 = require("ejs");
54
+ const helpers_1 = require("../utils/helpers");
55
+ const { version } = require('../../../package.json');
56
+ const FILE_FOR_COPY_REGEXP = /(index\.html)$|\.(gif|jpg|jpeg|tiff|png|svg|ashx|ico|pdf|jar|eot|woff|ttf|woff2)$/;
57
+ const populateEjsData = (args, destination) => {
58
+ // pass in helper to args object
59
+ // Use exact version for Content SDK dependencies in beta and canary versions
60
+ const contentSdkVersion = version.match(/(\-[a-zA-Z]+\.\d+)$/) ? version : `~${version}`;
61
+ const ejsData = Object.assign(Object.assign({}, args), { version: contentSdkVersion, helper: {
62
+ isDev: (0, helpers_1.isDevEnvironment)(destination || args.destination),
63
+ } });
64
+ return ejsData;
65
+ };
66
+ exports.populateEjsData = populateEjsData;
67
+ /**
68
+ * Handles each template file and applies ejs renderer, also:
69
+ * - Determines files for copy.
70
+ * - Determines files for skip.
71
+ * @param {string} templatePath path to the template
72
+ * @param {BaseArgs} args CLI arguments
73
+ * @param {TransformOptions} options custom options
74
+ */
75
+ const transform = (templatePath_1, args_1, ...args_2) => __awaiter(void 0, [templatePath_1, args_1, ...args_2], void 0, function* (templatePath, args, options = {}) {
76
+ const { isFileForCopy, isFileForSkip, fileForCopyRegExp = FILE_FOR_COPY_REGEXP } = options;
77
+ const destinationPath = path_1.default.resolve(args.destination);
78
+ const ejsData = (0, exports.populateEjsData)(args);
79
+ // the templates to be run through ejs render or copied directly
80
+ const files = glob.sync('**/*', {
81
+ cwd: templatePath,
82
+ dot: true,
83
+ nodir: true,
84
+ });
85
+ for (const file of files) {
86
+ try {
87
+ let pathToNewFile = `${destinationPath}${path_1.sep}${file}`;
88
+ const pathToTemplate = path_1.default.join(templatePath, file);
89
+ // Rename gitignore after the fact to prevent npm from renaming it to .npmignore
90
+ // See: https://github.com/npm/npm/issues/1862
91
+ if (!file.endsWith('.gitignore') && file.endsWith('gitignore')) {
92
+ pathToNewFile = pathToNewFile.replace(/\gitignore$/, '.gitignore');
93
+ }
94
+ if (isFileForSkip && isFileForSkip(file)) {
95
+ continue;
96
+ }
97
+ // if the directory doesn't exist, create it
98
+ fs_extra_1.default.mkdirsSync(path_1.default.dirname(pathToNewFile));
99
+ if (isFileForCopy ? isFileForCopy(file, fileForCopyRegExp) : file.match(fileForCopyRegExp)) {
100
+ // pdfs may have <% encoded, which throws an error for ejs.
101
+ // we simply want to copy file if it's a pdf, not render it with ejs.
102
+ fs_extra_1.default.copySync(pathToTemplate, pathToNewFile);
103
+ continue;
104
+ }
105
+ // holds the content to be written to the new file
106
+ const renderedFile = yield (0, ejs_1.renderFile)(path_1.default.resolve(pathToTemplate), ejsData);
107
+ (0, helpers_1.writeFileToPath)(pathToNewFile, renderedFile);
108
+ }
109
+ catch (error) {
110
+ console.log(chalk_1.default.red(error));
111
+ console.log(`Error occurred when trying to render to ${chalk_1.default.yellow(path_1.default.resolve(file))}`);
112
+ }
113
+ }
114
+ });
115
+ exports.transform = transform;
@@ -1,53 +1,53 @@
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.spawnFunc = exports.run = void 0;
7
- const cross_spawn_1 = __importDefault(require("cross-spawn"));
8
- /**
9
- * @param {string} command
10
- * @param {string[]} args
11
- * @param {SpawnSyncOptionsWithStringEncoding} options
12
- * @param {boolean} silent
13
- */
14
- const run = (command, args, options, silent) => {
15
- silent || console.log(`> ${command} ${args.join(' ')}`);
16
- (0, exports.spawnFunc)(command, args, options);
17
- };
18
- exports.run = run;
19
- /**
20
- * @param {string} command
21
- * @param {string[]} args
22
- * @param {SpawnSyncOptionsWithStringEncoding} options
23
- * @param {NodeJS.Process} parentProcess
24
- */
25
- const spawnFunc = (command, args, options, parentProcess) => {
26
- const parent = parentProcess !== null && parentProcess !== void 0 ? parentProcess : process;
27
- // Use 'inherit' (better UX) when being run within a TTY context, use 'pipe' otherwise.
28
- // In most cases, TTY will be the case. However, when running inside of our dotnet template,
29
- // stderr is not TTY (will be a socket instead of a WriteStream) and commands such as
30
- // `npm install` will error out if using 'inherit' (and ultimately hang the parent process).
31
- const defaults = {
32
- stdio: [
33
- parent.stdin.isTTY ? 'inherit' : 'pipe',
34
- parent.stdout.isTTY ? 'inherit' : 'pipe',
35
- parent.stderr.isTTY ? 'inherit' : 'pipe',
36
- ],
37
- };
38
- const result = cross_spawn_1.default.sync(command, args, Object.assign(defaults, options));
39
- if (result.signal === 'SIGKILL') {
40
- console.log('The operation failed because the process exited too early. ' +
41
- 'This probably means the system ran out of memory or someone called ' +
42
- '`kill -9` on the process.');
43
- }
44
- else if (result.signal === 'SIGTERM') {
45
- console.log('The operation failed because the process exited too early. ' +
46
- 'Someone might have called `kill` or `killall`, or the system could ' +
47
- 'be shutting down.');
48
- }
49
- if (result.status && result.status > 0) {
50
- parent.exit(result.status);
51
- }
52
- };
53
- exports.spawnFunc = spawnFunc;
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.spawnFunc = exports.run = void 0;
7
+ const cross_spawn_1 = __importDefault(require("cross-spawn"));
8
+ /**
9
+ * @param {string} command
10
+ * @param {string[]} args
11
+ * @param {SpawnSyncOptionsWithStringEncoding} options
12
+ * @param {boolean} silent
13
+ */
14
+ const run = (command, args, options, silent) => {
15
+ silent || console.log(`> ${command} ${args.join(' ')}`);
16
+ (0, exports.spawnFunc)(command, args, options);
17
+ };
18
+ exports.run = run;
19
+ /**
20
+ * @param {string} command
21
+ * @param {string[]} args
22
+ * @param {SpawnSyncOptionsWithStringEncoding} options
23
+ * @param {NodeJS.Process} parentProcess
24
+ */
25
+ const spawnFunc = (command, args, options, parentProcess) => {
26
+ const parent = parentProcess !== null && parentProcess !== void 0 ? parentProcess : process;
27
+ // Use 'inherit' (better UX) when being run within a TTY context, use 'pipe' otherwise.
28
+ // In most cases, TTY will be the case. However, when running inside of our dotnet template,
29
+ // stderr is not TTY (will be a socket instead of a WriteStream) and commands such as
30
+ // `npm install` will error out if using 'inherit' (and ultimately hang the parent process).
31
+ const defaults = {
32
+ stdio: [
33
+ parent.stdin.isTTY ? 'inherit' : 'pipe',
34
+ parent.stdout.isTTY ? 'inherit' : 'pipe',
35
+ parent.stderr.isTTY ? 'inherit' : 'pipe',
36
+ ],
37
+ };
38
+ const result = cross_spawn_1.default.sync(command, args, Object.assign(defaults, options));
39
+ if (result.signal === 'SIGKILL') {
40
+ console.log('The operation failed because the process exited too early. ' +
41
+ 'This probably means the system ran out of memory or someone called ' +
42
+ '`kill -9` on the process.');
43
+ }
44
+ else if (result.signal === 'SIGTERM') {
45
+ console.log('The operation failed because the process exited too early. ' +
46
+ 'Someone might have called `kill` or `killall`, or the system could ' +
47
+ 'be shutting down.');
48
+ }
49
+ if (result.status && result.status > 0) {
50
+ parent.exit(result.status);
51
+ }
52
+ };
53
+ exports.spawnFunc = spawnFunc;
@@ -1,80 +1,80 @@
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.removeFile = exports.writeFileToPath = exports.getAllTemplates = exports.sortKeys = exports.writeJsonFile = exports.openJsonFile = exports.isDevEnvironment = void 0;
7
- const chalk_1 = __importDefault(require("chalk"));
8
- const fs_1 = __importDefault(require("fs"));
9
- const path_1 = __importDefault(require("path"));
10
- /**
11
- * Determines whether you are in a dev environment.
12
- * It's `true` if you are inside the monorepo
13
- * @param {string} [cwd] path to the current working directory
14
- * @returns {boolean} is a development environment
15
- */
16
- const isDevEnvironment = (cwd) => {
17
- const currentPath = path_1.default.resolve(cwd || process.cwd());
18
- // TODO: is there a better way to detect this?
19
- const lernaPath = path_1.default.join(currentPath, '..', '..');
20
- return fs_1.default.existsSync(path_1.default.join(lernaPath, 'lerna.json'));
21
- };
22
- exports.isDevEnvironment = isDevEnvironment;
23
- /**
24
- * Provides json data from a file
25
- * @param {string} jsonFilePath path to the .json file.
26
- * @returns json data
27
- */
28
- const openJsonFile = (jsonFilePath) => {
29
- try {
30
- const data = fs_1.default.readFileSync(jsonFilePath, 'utf8');
31
- return data ? JSON.parse(data) : undefined;
32
- }
33
- catch (error) {
34
- console.log(chalk_1.default.red(`The following error occurred while trying to read ${jsonFilePath}:`));
35
- console.log(chalk_1.default.red(error));
36
- }
37
- };
38
- exports.openJsonFile = openJsonFile;
39
- /**
40
- * Creates a .json file and inserts provided data
41
- * @param {object} data data to be written into the .json file
42
- * @param {string} jsonFilePath a path to a file.
43
- */
44
- const writeJsonFile = (data, jsonFilePath) => {
45
- try {
46
- fs_1.default.writeFileSync(jsonFilePath, JSON.stringify(data, null, 2), {
47
- encoding: 'utf8',
48
- });
49
- }
50
- catch (error) {
51
- console.log(chalk_1.default.red(`The following error occurred while trying to write ${jsonFilePath}:`));
52
- console.log(chalk_1.default.red(error));
53
- }
54
- };
55
- exports.writeJsonFile = writeJsonFile;
56
- const sortKeys = (obj) => {
57
- const sorted = {};
58
- Object.keys(obj)
59
- .sort()
60
- .forEach((key) => (sorted[key] = obj[key]));
61
- return sorted;
62
- };
63
- exports.sortKeys = sortKeys;
64
- /**
65
- * Returns all templates
66
- * @returns {string[]} templates
67
- */
68
- const getAllTemplates = () => {
69
- const templatePath = path_1.default.resolve(__dirname, './../../templates');
70
- return fs_1.default.readdirSync(templatePath, 'utf8');
71
- };
72
- exports.getAllTemplates = getAllTemplates;
73
- const writeFileToPath = (destinationPath, content) => {
74
- fs_1.default.writeFileSync(destinationPath, content, 'utf8');
75
- };
76
- exports.writeFileToPath = writeFileToPath;
77
- const removeFile = (filePath) => {
78
- fs_1.default.unlinkSync(filePath);
79
- };
80
- exports.removeFile = removeFile;
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.removeFile = exports.writeFileToPath = exports.getAllTemplates = exports.sortKeys = exports.writeJsonFile = exports.openJsonFile = exports.isDevEnvironment = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ /**
11
+ * Determines whether you are in a dev environment.
12
+ * It's `true` if you are inside the monorepo
13
+ * @param {string} [cwd] path to the current working directory
14
+ * @returns {boolean} is a development environment
15
+ */
16
+ const isDevEnvironment = (cwd) => {
17
+ const currentPath = path_1.default.resolve(cwd || process.cwd());
18
+ // TODO: is there a better way to detect this?
19
+ const lernaPath = path_1.default.join(currentPath, '..', '..');
20
+ return fs_1.default.existsSync(path_1.default.join(lernaPath, 'lerna.json'));
21
+ };
22
+ exports.isDevEnvironment = isDevEnvironment;
23
+ /**
24
+ * Provides json data from a file
25
+ * @param {string} jsonFilePath path to the .json file.
26
+ * @returns json data
27
+ */
28
+ const openJsonFile = (jsonFilePath) => {
29
+ try {
30
+ const data = fs_1.default.readFileSync(jsonFilePath, 'utf8');
31
+ return data ? JSON.parse(data) : undefined;
32
+ }
33
+ catch (error) {
34
+ console.log(chalk_1.default.red(`The following error occurred while trying to read ${jsonFilePath}:`));
35
+ console.log(chalk_1.default.red(error));
36
+ }
37
+ };
38
+ exports.openJsonFile = openJsonFile;
39
+ /**
40
+ * Creates a .json file and inserts provided data
41
+ * @param {object} data data to be written into the .json file
42
+ * @param {string} jsonFilePath a path to a file.
43
+ */
44
+ const writeJsonFile = (data, jsonFilePath) => {
45
+ try {
46
+ fs_1.default.writeFileSync(jsonFilePath, JSON.stringify(data, null, 2), {
47
+ encoding: 'utf8',
48
+ });
49
+ }
50
+ catch (error) {
51
+ console.log(chalk_1.default.red(`The following error occurred while trying to write ${jsonFilePath}:`));
52
+ console.log(chalk_1.default.red(error));
53
+ }
54
+ };
55
+ exports.writeJsonFile = writeJsonFile;
56
+ const sortKeys = (obj) => {
57
+ const sorted = {};
58
+ Object.keys(obj)
59
+ .sort()
60
+ .forEach((key) => (sorted[key] = obj[key]));
61
+ return sorted;
62
+ };
63
+ exports.sortKeys = sortKeys;
64
+ /**
65
+ * Returns all templates
66
+ * @returns {string[]} templates
67
+ */
68
+ const getAllTemplates = () => {
69
+ const templatePath = path_1.default.resolve(__dirname, './../../templates');
70
+ return fs_1.default.readdirSync(templatePath, 'utf8');
71
+ };
72
+ exports.getAllTemplates = getAllTemplates;
73
+ const writeFileToPath = (destinationPath, content) => {
74
+ fs_1.default.writeFileSync(destinationPath, content, 'utf8');
75
+ };
76
+ exports.writeFileToPath = writeFileToPath;
77
+ const removeFile = (filePath) => {
78
+ fs_1.default.unlinkSync(filePath);
79
+ };
80
+ exports.removeFile = removeFile;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const bin_1 = require("./bin");
5
- const args = (0, bin_1.parseArgs)();
6
- (0, bin_1.main)(args);
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const bin_1 = require("./bin");
5
+ const args = (0, bin_1.parseArgs)();
6
+ (0, bin_1.main)(args);