@codeleap/cli 5.8.9 → 5.8.10
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.
|
@@ -0,0 +1,111 @@
|
|
|
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 __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.createComponentCommand = void 0;
|
|
40
|
+
var Command_1 = require("../../lib/Command");
|
|
41
|
+
var lib_1 = require("../../lib");
|
|
42
|
+
var utils_1 = require("./utils");
|
|
43
|
+
var constants_1 = require("../../constants");
|
|
44
|
+
var commandName = 'create-component';
|
|
45
|
+
exports.createComponentCommand = (0, Command_1.codeleapCommand)({
|
|
46
|
+
name: commandName,
|
|
47
|
+
settingsRequired: true,
|
|
48
|
+
parameters: [],
|
|
49
|
+
help: {
|
|
50
|
+
description: 'Command to create all files for a new component.',
|
|
51
|
+
examples: [
|
|
52
|
+
"codeleap ".concat(commandName),
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
}, function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
56
|
+
var answers, answerName, componentFolder, componentName, componentsFileDir, stylesheetsDir, componentsDir, componentFileName, stylesheetFileName, componentFilePath, stylesheetFilePath, componentContent, stylesheetContent;
|
|
57
|
+
var _a, _b;
|
|
58
|
+
return __generator(this, function (_c) {
|
|
59
|
+
switch (_c.label) {
|
|
60
|
+
case 0: return [4 /*yield*/, lib_1.inquirer.prompt([
|
|
61
|
+
{
|
|
62
|
+
name: 'componentName',
|
|
63
|
+
message: 'Component Name?',
|
|
64
|
+
validate: function (input) {
|
|
65
|
+
if (!input || input.trim().length === 0) {
|
|
66
|
+
return 'Component name is required';
|
|
67
|
+
}
|
|
68
|
+
if (!/^[A-Za-z][A-Za-z0-9]*$/.test(input.trim())) {
|
|
69
|
+
return 'Component name must start with a letter and contain only letters and numbers';
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'componentNameFolder',
|
|
76
|
+
message: 'In which folder would you like to create the component? (default is shared)',
|
|
77
|
+
default: 'shared',
|
|
78
|
+
},
|
|
79
|
+
])];
|
|
80
|
+
case 1:
|
|
81
|
+
answers = _c.sent();
|
|
82
|
+
answerName = answers.componentName.trim();
|
|
83
|
+
componentFolder = answers.componentNameFolder.trim();
|
|
84
|
+
componentName = (0, utils_1.formatComponentName)(answerName);
|
|
85
|
+
componentsFileDir = lib_1.path.join(constants_1.cliDir, constants_1.USER_CONFIG.components.componentsDir, componentFolder);
|
|
86
|
+
stylesheetsDir = lib_1.path.join(constants_1.cliDir, constants_1.USER_CONFIG.components.stylesheetsDir);
|
|
87
|
+
componentsDir = lib_1.path.join(constants_1.cliDir, constants_1.USER_CONFIG.components.componentsDir);
|
|
88
|
+
componentFileName = "".concat(componentName, ".tsx");
|
|
89
|
+
stylesheetFileName = "".concat(componentName, ".ts");
|
|
90
|
+
componentFilePath = lib_1.path.join(componentsFileDir, componentFileName);
|
|
91
|
+
stylesheetFilePath = lib_1.path.join(stylesheetsDir, stylesheetFileName);
|
|
92
|
+
componentContent = (0, utils_1.generateComponentFile)(componentName, (_a = constants_1.USER_CONFIG.components) === null || _a === void 0 ? void 0 : _a.app);
|
|
93
|
+
stylesheetContent = (0, utils_1.generateStylesheetFile)(componentName, (_b = constants_1.USER_CONFIG.components) === null || _b === void 0 ? void 0 : _b.app);
|
|
94
|
+
(0, utils_1.createFile)({
|
|
95
|
+
dir: componentsFileDir,
|
|
96
|
+
filePath: componentFilePath,
|
|
97
|
+
content: componentContent,
|
|
98
|
+
fileName: "".concat(componentName, ".tsx"),
|
|
99
|
+
});
|
|
100
|
+
(0, utils_1.createFile)({
|
|
101
|
+
dir: stylesheetsDir,
|
|
102
|
+
filePath: stylesheetFilePath,
|
|
103
|
+
content: stylesheetContent,
|
|
104
|
+
fileName: "".concat(componentName, ".ts"),
|
|
105
|
+
});
|
|
106
|
+
(0, utils_1.updateStylesheetsImport)(stylesheetsDir, componentName);
|
|
107
|
+
(0, utils_1.updateComponentsImport)(componentsDir, componentFolder, componentName);
|
|
108
|
+
return [2 /*return*/];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}); });
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateComponentsImport = exports.updateStylesheetsImport = exports.createFile = exports.generateStylesheetFile = exports.generateComponentFile = exports.formatComponentName = exports.capitalize = void 0;
|
|
4
|
+
var lib_1 = require("../../lib");
|
|
5
|
+
function capitalize(name) {
|
|
6
|
+
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
7
|
+
}
|
|
8
|
+
exports.capitalize = capitalize;
|
|
9
|
+
function formatComponentName(name) {
|
|
10
|
+
return capitalize(name.charAt(0).toUpperCase() + name.slice(1));
|
|
11
|
+
}
|
|
12
|
+
exports.formatComponentName = formatComponentName;
|
|
13
|
+
function generateComponentFile(componentName, app) {
|
|
14
|
+
var rootDir = app === 'web' ? '@/config' : '@/app';
|
|
15
|
+
return "import { React, StyleRegistry, StyleSheets } from '".concat(rootDir, "'\nimport { StyledComponent } from '@codeleap/styles'\nimport { useStylesFor } from '@codeleap/").concat(app, "'\n\ntype ").concat(componentName, "Props = {\n \n}\n\nexport const ").concat(componentName, ": StyledComponent<typeof StyleSheets.").concat(componentName, "Styles, ").concat(componentName, "Props> = (props) => {\n const { style } = props\n\n const styles = useStylesFor(").concat(componentName, ".styleRegistryName, style)\n\n return null\n}\n\n").concat(componentName, ".styleRegistryName = '").concat(componentName, "'\n").concat(componentName, ".elements = ['wrapper']\n\nStyleRegistry.registerComponent(").concat(componentName, ")\n");
|
|
16
|
+
}
|
|
17
|
+
exports.generateComponentFile = generateComponentFile;
|
|
18
|
+
function generateStylesheetFile(componentName, app) {
|
|
19
|
+
return "import { createStyles } from '@codeleap/styles'\nimport { StyleRegistry } from '../styles'\n\nexport type ".concat(componentName, "Composition = ''\n\nconst create").concat(componentName, "Variant = createStyles<").concat(componentName, "Composition>\n\nexport const ").concat(componentName, "Styles = {\n default: create").concat(componentName, "Variant(theme => ({})),\n}\n\nStyleRegistry.registerVariants('").concat(componentName, "', ").concat(componentName, "Styles)\n");
|
|
20
|
+
}
|
|
21
|
+
exports.generateStylesheetFile = generateStylesheetFile;
|
|
22
|
+
function createFile(_a) {
|
|
23
|
+
var dir = _a.dir, filePath = _a.filePath, content = _a.content, fileName = _a.fileName;
|
|
24
|
+
if (lib_1.fs.existsSync(filePath)) {
|
|
25
|
+
console.error("\u274C ".concat(fileName, " already exists in ").concat(filePath, "."));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (!lib_1.fs.existsSync(dir)) {
|
|
29
|
+
lib_1.fs.mkdirSync(dir, { recursive: true });
|
|
30
|
+
console.log("\uD83D\uDCC1 Created directory: ".concat(dir));
|
|
31
|
+
}
|
|
32
|
+
lib_1.fs.writeFileSync(filePath, content, 'utf-8');
|
|
33
|
+
console.log("\u2705 ".concat(fileName, " created successfully at: ").concat(filePath));
|
|
34
|
+
}
|
|
35
|
+
exports.createFile = createFile;
|
|
36
|
+
function updateStylesheetsImport(stylesheetsDir, componentName) {
|
|
37
|
+
var indexTsPath = "".concat(stylesheetsDir, "/index.ts");
|
|
38
|
+
var indexTsxPath = "".concat(stylesheetsDir, "/index.tsx");
|
|
39
|
+
var indexPath;
|
|
40
|
+
if (lib_1.fs.existsSync(indexTsPath)) {
|
|
41
|
+
indexPath = indexTsPath;
|
|
42
|
+
}
|
|
43
|
+
else if (lib_1.fs.existsSync(indexTsxPath)) {
|
|
44
|
+
indexPath = indexTsxPath;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
console.error("\u274C index.ts or index.tsx not found in ".concat(stylesheetsDir));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
var currentContent = lib_1.fs.readFileSync(indexPath, 'utf-8');
|
|
51
|
+
var exportStatement = "export { ".concat(componentName, "Styles } from './").concat(componentName, "'");
|
|
52
|
+
var updatedContent = currentContent.trimEnd() + '\n' + exportStatement + '\n';
|
|
53
|
+
lib_1.fs.writeFileSync(indexPath, updatedContent, 'utf-8');
|
|
54
|
+
console.log("\u2705 Added export for ".concat(componentName, "Styles to ").concat(indexPath));
|
|
55
|
+
}
|
|
56
|
+
exports.updateStylesheetsImport = updateStylesheetsImport;
|
|
57
|
+
function updateComponentsImport(componentsDir, componentFolder, componentName) {
|
|
58
|
+
var indexTsPath = lib_1.path.join(componentsDir, 'index.ts');
|
|
59
|
+
var indexTsxPath = lib_1.path.join(componentsDir, 'index.tsx');
|
|
60
|
+
var indexPath;
|
|
61
|
+
if (lib_1.fs.existsSync(indexTsPath)) {
|
|
62
|
+
indexPath = indexTsPath;
|
|
63
|
+
}
|
|
64
|
+
else if (lib_1.fs.existsSync(indexTsxPath)) {
|
|
65
|
+
indexPath = indexTsxPath;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
console.error("\u274C index.ts or index.tsx not found in ".concat(componentsDir));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
var currentContent = lib_1.fs.readFileSync(indexPath, 'utf-8');
|
|
72
|
+
var exportPattern = "export * from './".concat(componentFolder, "'");
|
|
73
|
+
if (!currentContent.includes(exportPattern)) {
|
|
74
|
+
var updatedContent = currentContent.trimEnd() + '\n' + exportPattern + '\n';
|
|
75
|
+
lib_1.fs.writeFileSync(indexPath, updatedContent, 'utf-8');
|
|
76
|
+
console.log("\u2705 Added export for ".concat(componentFolder, " to ").concat(indexPath));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
console.log("\uD83D\uDCAC Export for ".concat(componentFolder, " already exists in ").concat(indexPath));
|
|
80
|
+
}
|
|
81
|
+
var componentIndexTsPath = lib_1.path.join(componentsDir, componentFolder, 'index.ts'); //`${componentsDir}/${componentFolder}/index.ts`
|
|
82
|
+
var componentIndexTsxPath = lib_1.path.join(componentsDir, componentFolder, 'index.tsx'); //`${componentsDir}/${componentFolder}/index.tsx`
|
|
83
|
+
var componentIndexPath;
|
|
84
|
+
if (lib_1.fs.existsSync(componentIndexTsPath)) {
|
|
85
|
+
componentIndexPath = componentIndexTsPath;
|
|
86
|
+
}
|
|
87
|
+
else if (lib_1.fs.existsSync(componentIndexTsxPath)) {
|
|
88
|
+
componentIndexPath = componentIndexTsxPath;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
componentIndexPath = componentIndexTsPath;
|
|
92
|
+
lib_1.fs.writeFileSync(componentIndexPath, '', 'utf-8');
|
|
93
|
+
console.log("\uD83D\uDCC1 Created file: ".concat(componentIndexPath));
|
|
94
|
+
}
|
|
95
|
+
var componentCurrentContent = lib_1.fs.readFileSync(componentIndexPath, 'utf-8');
|
|
96
|
+
var componentExportStatement = "export * from './".concat(componentName, "'");
|
|
97
|
+
var componentUpdatedContent = componentCurrentContent.trimEnd() + '\n' + componentExportStatement + '\n';
|
|
98
|
+
lib_1.fs.writeFileSync(componentIndexPath, componentUpdatedContent, 'utf-8');
|
|
99
|
+
console.log("\u2705 Added export for ".concat(componentName, " to ").concat(componentIndexPath));
|
|
100
|
+
}
|
|
101
|
+
exports.updateComponentsImport = updateComponentsImport;
|
package/dist/index.js
CHANGED
|
@@ -12,11 +12,13 @@ var convertorWebp_1 = require("./commands/convertorWebp");
|
|
|
12
12
|
var configureTheme_1 = require("./commands/configureTheme");
|
|
13
13
|
var linguiTranslate_1 = require("./commands/linguiTranslate");
|
|
14
14
|
var configureSplash_1 = require("./commands/configureSplash");
|
|
15
|
+
var createComponent_1 = require("./commands/createComponent");
|
|
15
16
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
16
17
|
var packageJson = require('../package.json');
|
|
17
18
|
(0, cleye_1.cli)({
|
|
18
19
|
name: 'codeleap',
|
|
19
20
|
commands: [
|
|
21
|
+
createComponent_1.createComponentCommand,
|
|
20
22
|
keystoresAndroid_1.generateReleaseKey,
|
|
21
23
|
rename_1.renameMobileCommand,
|
|
22
24
|
createApp_1.createAppCommand,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/cli",
|
|
3
|
-
"version": "5.8.
|
|
3
|
+
"version": "5.8.10",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"repository": "git@github.com:codeleap-uk/codeleap-lib.git",
|
|
6
6
|
"author": "Paulo Henrique De Souza <paulosouza300272@gmail.com>",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"codeleap-cli": "./dist/index.js"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"@codeleap/config": "5.8.
|
|
13
|
+
"@codeleap/config": "5.8.10",
|
|
14
14
|
"@types/inquirer": "^8.2.0",
|
|
15
15
|
"@types/libsodium-wrappers": "^0.7.10",
|
|
16
16
|
"cross-env": "^7.0.3"
|