@exdst-sitecore-content-sdk/create-astro 0.0.1 → 0.0.22
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/README.md +3 -0
- package/dist/bin.js +119 -0
- package/dist/common/base/Initializer.js +2 -0
- package/dist/common/base/args.js +2 -0
- package/dist/common/base/prompts.js +7 -0
- package/dist/common/index.js +18 -0
- package/dist/common/processes/install.js +55 -0
- package/dist/common/processes/next.js +112 -0
- package/dist/common/processes/transform.js +116 -0
- package/dist/common/utils/cmd.js +53 -0
- package/dist/common/utils/helpers.js +80 -0
- package/dist/index.js +6 -0
- package/dist/initialize.js +71 -0
- package/dist/initializers/astro/args.js +2 -0
- package/dist/initializers/astro/index.js +30 -0
- package/dist/initializers/astro/prompts.js +26 -0
- package/dist/templates/astro/.env.container.example +27 -0
- package/dist/templates/astro/.env.remote.example +39 -0
- package/dist/templates/astro/.prettierignore +2 -0
- package/dist/templates/astro/.prettierrc +17 -0
- package/dist/templates/astro/LICENSE.txt +202 -0
- package/dist/templates/astro/README.MD +1 -0
- package/dist/templates/astro/astro.config.mjs +46 -0
- package/dist/templates/astro/eslint.config.mjs +21 -0
- package/dist/templates/astro/package.json +45 -0
- package/dist/templates/astro/public/favicon.ico +0 -0
- package/dist/templates/astro/public/favicon.svg +9 -0
- package/dist/templates/astro/sitecore.cli.config.ts +15 -0
- package/dist/templates/astro/sitecore.config.ts +6 -0
- package/dist/templates/astro/sitecore.config.ts.example +31 -0
- package/dist/templates/astro/src/Bootstrap.astro +77 -0
- package/dist/templates/astro/src/Layout.astro +57 -0
- package/dist/templates/astro/src/NotFound.astro +21 -0
- package/dist/templates/astro/src/Scripts.astro +9 -0
- package/dist/templates/astro/src/components/content-sdk/CdpPageView.astro +73 -0
- package/dist/templates/astro/src/components/content-sdk/SitecoreStyles.astro +20 -0
- package/dist/templates/astro/src/env.d.ts +10 -0
- package/dist/templates/astro/src/lib/component-props/index.ts +23 -0
- package/dist/templates/astro/src/lib/languages.ts +3 -0
- package/dist/templates/astro/src/lib/sitecore-client.ts +8 -0
- package/dist/templates/astro/src/middleware/index.ts +50 -0
- package/dist/templates/astro/src/pages/-/[...media].ts +20 -0
- package/dist/templates/astro/src/pages/404.astro +5 -0
- package/dist/templates/astro/src/pages/[...path].astro +118 -0
- package/dist/templates/astro/src/pages/api/editing/config.ts +17 -0
- package/dist/templates/astro/src/pages/api/editing/render.ts +19 -0
- package/dist/templates/astro/src/pages/robots.txt.ts +18 -0
- package/dist/templates/astro/src/pages/sitemap-[id].xml.ts +17 -0
- package/dist/templates/astro/src/pages/sitemap.xml.ts +17 -0
- package/dist/templates/astro/tsconfig.json +14 -0
- package/package.json +74 -22
package/README.md
ADDED
package/dist/bin.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.main = exports.promptDestination = exports.getDestination = exports.parseArgs = void 0;
|
|
16
|
+
const fs_1 = __importDefault(require("fs"));
|
|
17
|
+
const path_1 = require("path");
|
|
18
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
19
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
20
|
+
const initialize_1 = require("./initialize");
|
|
21
|
+
const minimist_1 = __importDefault(require("minimist"));
|
|
22
|
+
const common_1 = require("./common");
|
|
23
|
+
const parseArgs = () => {
|
|
24
|
+
// parse any command line arguments passed into `npx create-content-sdk-app`
|
|
25
|
+
// to pass to the generator prompts and skip them.
|
|
26
|
+
// useful for CI and testing purposes
|
|
27
|
+
const options = {
|
|
28
|
+
boolean: ['force', 'noInstall', 'yes', 'silent'],
|
|
29
|
+
string: ['destination', 'template'],
|
|
30
|
+
default: {},
|
|
31
|
+
};
|
|
32
|
+
const args = (0, minimist_1.default)(process.argv.slice(2), options);
|
|
33
|
+
// we need to coerce string parameters in minimist above (to prevent string options without a value e.g. `--template` from coming in as a boolean `true`).
|
|
34
|
+
// however, coersion will result in an empty string and inquirer will treat this as a valid answer value (and not prompt!).
|
|
35
|
+
// we need to go back through and remove these to prevent this.
|
|
36
|
+
options.string.forEach((key) => {
|
|
37
|
+
args[key] === '' && delete args[key];
|
|
38
|
+
});
|
|
39
|
+
return args;
|
|
40
|
+
};
|
|
41
|
+
exports.parseArgs = parseArgs;
|
|
42
|
+
const getDestination = (args, template) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
if (!template) {
|
|
44
|
+
throw new Error('Unable to get destinations, provided template is empty');
|
|
45
|
+
}
|
|
46
|
+
// validate/gather destination
|
|
47
|
+
// remove the (beta) from the template name
|
|
48
|
+
const defaultBaseDestination = `${process.cwd()}${path_1.sep}${template.replace(' (beta)', '')}`;
|
|
49
|
+
let destination = args.destination;
|
|
50
|
+
if (!destination) {
|
|
51
|
+
destination = args.yes
|
|
52
|
+
? defaultBaseDestination
|
|
53
|
+
: yield (0, exports.promptDestination)('Where would you like your new app created?', defaultBaseDestination);
|
|
54
|
+
}
|
|
55
|
+
return destination;
|
|
56
|
+
});
|
|
57
|
+
exports.getDestination = getDestination;
|
|
58
|
+
const promptDestination = (prompt, defaultDestination) => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
return (yield inquirer_1.default.prompt({
|
|
60
|
+
type: 'input',
|
|
61
|
+
name: 'destination',
|
|
62
|
+
message: prompt,
|
|
63
|
+
default: () => defaultDestination,
|
|
64
|
+
})).destination;
|
|
65
|
+
});
|
|
66
|
+
exports.promptDestination = promptDestination;
|
|
67
|
+
const main = (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
var _a;
|
|
69
|
+
let template = '';
|
|
70
|
+
// check if template was provided
|
|
71
|
+
if (((_a = args._) === null || _a === void 0 ? void 0 : _a.length) > 0 && args._[0] !== undefined) {
|
|
72
|
+
// use positional parameter
|
|
73
|
+
template = args._[0];
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// use --template arg
|
|
77
|
+
template = args.template || '';
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
// validate template
|
|
81
|
+
const allTemplates = (0, common_1.getAllTemplates)();
|
|
82
|
+
if (!template || !allTemplates.includes(template)) {
|
|
83
|
+
if (args.yes) {
|
|
84
|
+
throw new Error(`No or unknown template provided: '${template}'`);
|
|
85
|
+
}
|
|
86
|
+
if (template) {
|
|
87
|
+
console.log(chalk_1.default.yellow(`Unknown template provided: '${template}'...`));
|
|
88
|
+
}
|
|
89
|
+
const answer = yield inquirer_1.default.prompt({
|
|
90
|
+
type: 'list',
|
|
91
|
+
name: 'template',
|
|
92
|
+
message: 'Which template would you like to create?',
|
|
93
|
+
choices: allTemplates,
|
|
94
|
+
default: 'astro',
|
|
95
|
+
});
|
|
96
|
+
template = answer.template;
|
|
97
|
+
}
|
|
98
|
+
const destination = yield (0, exports.getDestination)(args, template);
|
|
99
|
+
if (!args.force && fs_1.default.existsSync(destination) && fs_1.default.readdirSync(destination).length > 0) {
|
|
100
|
+
if (args.yes) {
|
|
101
|
+
throw new Error(`Directory '${destination}' not empty. To overwrite it, use the --force flag.`);
|
|
102
|
+
}
|
|
103
|
+
const answer = yield inquirer_1.default.prompt({
|
|
104
|
+
type: 'confirm',
|
|
105
|
+
name: 'continue',
|
|
106
|
+
message: `Directory '${destination}' not empty. Are you sure you want to continue?`,
|
|
107
|
+
});
|
|
108
|
+
if (!answer.continue) {
|
|
109
|
+
process.exit();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
yield (0, initialize_1.initialize)(template, Object.assign(Object.assign({}, args), { destination, template }));
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
console.log(chalk_1.default.red('An error occurred:', error));
|
|
116
|
+
process.exit(1);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
exports.main = main;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lintFix = exports.installPackages = exports.nextSteps = exports.transform = exports.removeFile = exports.getAllTemplates = exports.writeJsonFile = exports.openJsonFile = exports.isDevEnvironment = exports.baseAppPrompts = void 0;
|
|
4
|
+
var prompts_1 = require("./base/prompts");
|
|
5
|
+
Object.defineProperty(exports, "baseAppPrompts", { enumerable: true, get: function () { return prompts_1.baseAppPrompts; } });
|
|
6
|
+
var helpers_1 = require("./utils/helpers");
|
|
7
|
+
Object.defineProperty(exports, "isDevEnvironment", { enumerable: true, get: function () { return helpers_1.isDevEnvironment; } });
|
|
8
|
+
Object.defineProperty(exports, "openJsonFile", { enumerable: true, get: function () { return helpers_1.openJsonFile; } });
|
|
9
|
+
Object.defineProperty(exports, "writeJsonFile", { enumerable: true, get: function () { return helpers_1.writeJsonFile; } });
|
|
10
|
+
Object.defineProperty(exports, "getAllTemplates", { enumerable: true, get: function () { return helpers_1.getAllTemplates; } });
|
|
11
|
+
Object.defineProperty(exports, "removeFile", { enumerable: true, get: function () { return helpers_1.removeFile; } });
|
|
12
|
+
var transform_1 = require("./processes/transform");
|
|
13
|
+
Object.defineProperty(exports, "transform", { enumerable: true, get: function () { return transform_1.transform; } });
|
|
14
|
+
var next_1 = require("./processes/next");
|
|
15
|
+
Object.defineProperty(exports, "nextSteps", { enumerable: true, get: function () { return next_1.nextSteps; } });
|
|
16
|
+
var install_1 = require("./processes/install");
|
|
17
|
+
Object.defineProperty(exports, "installPackages", { enumerable: true, get: function () { return install_1.installPackages; } });
|
|
18
|
+
Object.defineProperty(exports, "lintFix", { enumerable: true, get: function () { return install_1.lintFix; } });
|
|
@@ -0,0 +1,55 @@
|
|
|
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.lintFix = exports.installPackages = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const cmd_1 = require("../utils/cmd");
|
|
10
|
+
const helpers_1 = require("../utils/helpers");
|
|
11
|
+
/**
|
|
12
|
+
* Executes packages installation, depending on the environment
|
|
13
|
+
* @param {string} projectFolder path to the app folder
|
|
14
|
+
* @param {boolean} [silent] suppress logs
|
|
15
|
+
*/
|
|
16
|
+
const installPackages = (projectFolder, silent) => {
|
|
17
|
+
silent || console.log(chalk_1.default.cyan('Installing packages...'));
|
|
18
|
+
if ((0, helpers_1.isDevEnvironment)(projectFolder)) {
|
|
19
|
+
silent || console.log(chalk_1.default.yellow('Detected development environment.'));
|
|
20
|
+
(0, cmd_1.run)('yarn', ['install'], {
|
|
21
|
+
cwd: projectFolder,
|
|
22
|
+
encoding: 'utf8',
|
|
23
|
+
env: Object.assign(Object.assign({}, process.env), { NODE_NO_WARNINGS: '1' }),
|
|
24
|
+
}, silent);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
(0, cmd_1.run)('npm', ['install', '--loglevel=error'], {
|
|
28
|
+
cwd: projectFolder,
|
|
29
|
+
encoding: 'utf8',
|
|
30
|
+
}, silent);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.installPackages = installPackages;
|
|
34
|
+
/**
|
|
35
|
+
* Fixes possible linting issues
|
|
36
|
+
* @param {string} projectFolder path to the app folder
|
|
37
|
+
* @param {boolean} [silent] suppress logs
|
|
38
|
+
*/
|
|
39
|
+
const lintFix = (projectFolder, silent) => {
|
|
40
|
+
var _a;
|
|
41
|
+
const pkg = getPackageJson(projectFolder);
|
|
42
|
+
if (!((_a = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _a === void 0 ? void 0 : _a.lint)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
silent || console.log(chalk_1.default.cyan('Linting app...'));
|
|
46
|
+
(0, cmd_1.run)('npm', ['run', 'lint', '--', '--fix'], {
|
|
47
|
+
cwd: projectFolder,
|
|
48
|
+
encoding: 'utf8',
|
|
49
|
+
}, silent);
|
|
50
|
+
};
|
|
51
|
+
exports.lintFix = lintFix;
|
|
52
|
+
const getPackageJson = (projectFolder) => {
|
|
53
|
+
const packagePath = path_1.default.join(projectFolder, 'package.json');
|
|
54
|
+
return (0, helpers_1.openJsonFile)(packagePath);
|
|
55
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.nextSteps = void 0;
|
|
16
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
17
|
+
/**
|
|
18
|
+
* Logs app creation completion message and next steps
|
|
19
|
+
* @param {string} appName application name for the new app
|
|
20
|
+
* @param {string} nextStepsText next steps to be performed after app is created
|
|
21
|
+
*/
|
|
22
|
+
const nextSteps = (appName, nextStepsText) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
const successMessage = `Content SDK application ${chalk_1.default.green(appName)} is ready!`;
|
|
24
|
+
console.log(chalk_1.default.red(' -/oyhdmNNNNmdhyo/- '));
|
|
25
|
+
console.log(chalk_1.default.red(' :sdMMMMMMMMMMMMMMMMMMMMds: '));
|
|
26
|
+
console.log(chalk_1.default.red(' :yNMMMMMMMMMMMMMMMMMMMMMMMMMMNy: '));
|
|
27
|
+
console.log(chalk_1.default.red(' /mMMMMMMMMMNdyo+//://+shmMMMMMMMMMm/ '));
|
|
28
|
+
console.log(chalk_1.default.red(' :mMMMMMMMMh+. `:smMMMMMMMm: '));
|
|
29
|
+
console.log(chalk_1.default.red(' `yMMMMMMMm+` :yMMMMMMMs` '));
|
|
30
|
+
console.log(chalk_1.default.red(' `dMMMMMMN/ .hMMMMMMd` '));
|
|
31
|
+
console.log(chalk_1.default.red(' `mMMMMMMh` -s/+MMMMMMd` '));
|
|
32
|
+
console.log(chalk_1.default.red(' yMMMMMMh `:yNMMMs/MMMMMMy '));
|
|
33
|
+
console.log(chalk_1.default.red(' :MMMMMMm` `hMMMMMMMsoMMMMMM-'));
|
|
34
|
+
console.log(chalk_1.default.red(' yMMMMMM/ dMMMMMMM:mMMMMMy'));
|
|
35
|
+
console.log(chalk_1.default.red(' NMMMMMN` oMyossss:sMMMMMm'));
|
|
36
|
+
console.log(chalk_1.default.red(' MMMMMMN yM:NMMMMyoMMMMMN'));
|
|
37
|
+
console.log(chalk_1.default.red(' mMMMMMM` :Md+MMMMMoyMMMMMm'));
|
|
38
|
+
console.log(chalk_1.default.red(' yMMMMMM+ :NN+NMMMMM-NMMMMMy'));
|
|
39
|
+
console.log(chalk_1.default.red(' :MMMMMMN:- `sMdyMNymMMosMMMMMM-'));
|
|
40
|
+
console.log(chalk_1.default.red(' yMMMMMMd/o` .oNdhmMhhMmh++MMMMMMy '));
|
|
41
|
+
console.log(chalk_1.default.red(' `dMMMMMMm+do.- ./oyhhhNNhyNMMNosMMMMMMd` '));
|
|
42
|
+
console.log(chalk_1.default.red(' `dMMMMMMMssNdhsoo+/+oyyyydMmhhhMMMNs+mMMMMMMd` '));
|
|
43
|
+
console.log(chalk_1.default.red(' `yMMMMMMMNyydMNddddddddddhmMMMMho+dMMMMMMMy` '));
|
|
44
|
+
console.log(chalk_1.default.red(' :mMMMMMMMMmhhhdNMMMMMMMMmhssohMMMMMMMMm: '));
|
|
45
|
+
console.log(chalk_1.default.red(' /mMMMMMMMMMMNdhyyyyyyyhmMMMMMMMMMMm/ '));
|
|
46
|
+
console.log(chalk_1.default.red(' :yNMMMMMMMMMMMMMMMMMMMMMMMMMMNy: '));
|
|
47
|
+
console.log(chalk_1.default.red(' :sdMMMMMMMMMMMMMMMMMMMMds: '));
|
|
48
|
+
console.log(chalk_1.default.red(' `-/oyhdmNNNNmdhyo/- '));
|
|
49
|
+
console.log();
|
|
50
|
+
console.log();
|
|
51
|
+
console.log(' .................... ');
|
|
52
|
+
console.log(' #@@@@@@@@@@@@@@@@@@@@@+ ');
|
|
53
|
+
console.log(' +@@@@@@@@@@@@@@@@@@@@@@@- ');
|
|
54
|
+
console.log(' :@@@@@@@@@@@@@@@@@@@@@@@@@: ');
|
|
55
|
+
console.log(' @@@@@@@@@@@@@@@@@@@@@@@@@@@. ');
|
|
56
|
+
console.log(' %@@@@@@@@@@@@@@@@@@@@@@@@@@@# ');
|
|
57
|
+
console.log(' *@@@@@@@@@@@@@@@@@@@@@@@@@@@@@= ');
|
|
58
|
+
console.log(' -@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@. ');
|
|
59
|
+
console.log(' .@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@% ');
|
|
60
|
+
console.log(' #@@@@@@@@@@@@@@@+-*@@@@@@@@@@@@@@@+ ');
|
|
61
|
+
console.log(' =@@@@@@@@@@@@@@@= =@@@@@@@@@@@@@@@- ');
|
|
62
|
+
console.log(' :@@@@@@@@@@@@@@@# *@@@@@@@@@@@@@@@- ');
|
|
63
|
+
console.log(' .@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@ ');
|
|
64
|
+
console.log(' %@@@@@@@@@@@@@@@- =@@@@@@@@@@@@@@@* ');
|
|
65
|
+
console.log(' +@@@@@@@@@@@@@@@# %@@@@@@@@@@@@@@@- ');
|
|
66
|
+
console.log(' :@@@@@@@@@@@@@@@@. -@@@@@@@@@@@@@@@@ ');
|
|
67
|
+
console.log(' %@@@@@@@@@@@@@@@= *@@@@@@@@@@@@@@@# ');
|
|
68
|
+
console.log(' +@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@= ');
|
|
69
|
+
console.log(' =@@@@@@@@@@@@@@@@: =@@@@@@@@@@@@@@@@. ');
|
|
70
|
+
console.log(' -@@@@@@@@@@@@@@@@= #@@@@@@@@@@@@@@@@. ');
|
|
71
|
+
console.log(' @@@@@@@@@@@@@@@@# %@@@@@@@@@@@@@@@% ');
|
|
72
|
+
console.log(' *@@@@@%#*+=-::.. ..:--=+*%@@@@@= ');
|
|
73
|
+
console.log('-@#*=: .-+#@. ');
|
|
74
|
+
console.log('. .');
|
|
75
|
+
console.log();
|
|
76
|
+
console.log();
|
|
77
|
+
console.log(' :*###+. :+++=: ');
|
|
78
|
+
console.log(' :*###+. :+++=: ');
|
|
79
|
+
console.log('###########. :*###+. :+++=: #######+- :+#%##+. .%%%%%%%%%%%');
|
|
80
|
+
console.log('@@@++++++++. :*###+. -+++=: @@%+++*@@@: #@@#++%@@* ++++@@@++++');
|
|
81
|
+
console.log('@@% :+###+. .+++=: @@* %@@ +@@- =@@- @@% ');
|
|
82
|
+
console.log('@@% :+###+:.-: @@* *@@ =@@= @@% ');
|
|
83
|
+
console.log('@@% .+###*: @@* *@@ +@@%= @@% ');
|
|
84
|
+
console.log('@@@@@@@@@@@. :####+ @@* *@@ .+@@@+. @@% ');
|
|
85
|
+
console.log('@@%-------- -####= @@* *@@ =%@@*. @@% ');
|
|
86
|
+
console.log('@@% -####=.: @@* *@@ -%@@: @@% ');
|
|
87
|
+
console.log('@@% -####= .=++- @@* #@@ -++. -@@= @@% ');
|
|
88
|
+
console.log('@@%:::::::: -####- .=+++- @@#:::-*@@+ :@@%=::=@@%. @@% ');
|
|
89
|
+
console.log('@@@@@@@@@@@: =####- .=+++- @@@@@@@@#: .+%@@@@%+ @@% ');
|
|
90
|
+
console.log('........... =####- .=+++-. ....... .. ... ');
|
|
91
|
+
console.log(' =####- .=+++-. ');
|
|
92
|
+
console.log();
|
|
93
|
+
console.log(chalk_1.default.white(`
|
|
94
|
+
____ ___ _ _ _____ _____ _ _ _____ ____ ____ _ __
|
|
95
|
+
/ ___/ _ \\| \\ | |_ _| ____| \\ | |_ _| / ___|| _ \\| |/ /
|
|
96
|
+
| | | | | | \\| | | | | _| | \\| | | |____\\___ \\| | | | ' /
|
|
97
|
+
| |__| |_| | |\\ | | | | |___| |\\ | | |_____|__) | |_| | . \\
|
|
98
|
+
\\____\\___/|_| \\_| |_| |_____|_| \\_| |_| |____/|____/|_|\\_\\
|
|
99
|
+
`));
|
|
100
|
+
console.log();
|
|
101
|
+
console.log(successMessage);
|
|
102
|
+
console.log();
|
|
103
|
+
console.log(chalk_1.default.yellow('Next steps:'));
|
|
104
|
+
if (nextStepsText) {
|
|
105
|
+
console.log(nextStepsText);
|
|
106
|
+
}
|
|
107
|
+
console.log('* Enable source control (i.e. git init) (optional)');
|
|
108
|
+
console.log('* Check out the Content SDK documentation at https://doc.sitecore.com/xmc/en/developers/content-sdk/index.html');
|
|
109
|
+
console.log();
|
|
110
|
+
console.log(chalk_1.default.green('Enjoy!'));
|
|
111
|
+
});
|
|
112
|
+
exports.nextSteps = nextSteps;
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
ignore: ['**/node_modules/**', '**/.astro/**', '**/dist/**'],
|
|
85
|
+
});
|
|
86
|
+
for (const file of files) {
|
|
87
|
+
try {
|
|
88
|
+
let pathToNewFile = `${destinationPath}${path_1.sep}${file}`;
|
|
89
|
+
const pathToTemplate = path_1.default.join(templatePath, file);
|
|
90
|
+
// Rename gitignore after the fact to prevent npm from renaming it to .npmignore
|
|
91
|
+
// See: https://github.com/npm/npm/issues/1862
|
|
92
|
+
if (!file.endsWith('.gitignore') && file.endsWith('gitignore')) {
|
|
93
|
+
pathToNewFile = pathToNewFile.replace(/\gitignore$/, '.gitignore');
|
|
94
|
+
}
|
|
95
|
+
if (isFileForSkip && isFileForSkip(file)) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
// if the directory doesn't exist, create it
|
|
99
|
+
fs_extra_1.default.mkdirsSync(path_1.default.dirname(pathToNewFile));
|
|
100
|
+
if (isFileForCopy ? isFileForCopy(file, fileForCopyRegExp) : file.match(fileForCopyRegExp)) {
|
|
101
|
+
// pdfs may have <% encoded, which throws an error for ejs.
|
|
102
|
+
// we simply want to copy file if it's a pdf, not render it with ejs.
|
|
103
|
+
fs_extra_1.default.copySync(pathToTemplate, pathToNewFile);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
// holds the content to be written to the new file
|
|
107
|
+
const renderedFile = yield (0, ejs_1.renderFile)(path_1.default.resolve(pathToTemplate), ejsData);
|
|
108
|
+
(0, helpers_1.writeFileToPath)(pathToNewFile, renderedFile);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
console.log(chalk_1.default.red(error));
|
|
112
|
+
console.log(`Error occurred when trying to render to ${chalk_1.default.yellow(path_1.default.resolve(file))}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
exports.transform = transform;
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +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;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
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.getInitializer = exports.initialize = void 0;
|
|
49
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
50
|
+
const path_1 = __importStar(require("path"));
|
|
51
|
+
const common_1 = require("./common");
|
|
52
|
+
const initialize = (template, args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
const initializer = yield (0, exports.getInitializer)(template);
|
|
54
|
+
args.silent || console.log(chalk_1.default.cyan(`Initializing '${template}'...`));
|
|
55
|
+
const response = yield initializer.init(args);
|
|
56
|
+
// final steps (install, lint)
|
|
57
|
+
if (!args.noInstall) {
|
|
58
|
+
(0, common_1.installPackages)(args.destination, args.silent);
|
|
59
|
+
(0, common_1.lintFix)(args.destination, args.silent);
|
|
60
|
+
}
|
|
61
|
+
if (!args.silent) {
|
|
62
|
+
const pkg = (0, common_1.openJsonFile)(path_1.default.resolve(`${args.destination}${path_1.sep}package.json`));
|
|
63
|
+
(0, common_1.nextSteps)(pkg.name, response.nextSteps);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
exports.initialize = initialize;
|
|
67
|
+
const getInitializer = (template) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
const { default: Initializer } = yield Promise.resolve(`${path_1.default.resolve(__dirname, 'initializers', template, 'index')}`).then(s => __importStar(require(s)));
|
|
69
|
+
return new Initializer();
|
|
70
|
+
});
|
|
71
|
+
exports.getInitializer = getInitializer;
|