@public-ui/kolibri-cli 1.7.0-rc.7 → 1.7.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 (47) hide show
  1. package/README.md +17 -10
  2. package/dist/index.js +0 -0
  3. package/dist/migrate/index.js +65 -12
  4. package/dist/migrate/runner/task-runner.js +10 -0
  5. package/dist/migrate/runner/tasks/common/ExecTask.js +30 -0
  6. package/dist/migrate/runner/tasks/common/GenericRenameSlotNameTask.js +44 -0
  7. package/dist/migrate/runner/tasks/common/GitIgnoreAddRuleTask.js +40 -0
  8. package/dist/migrate/runner/tasks/common/HandleDependencyTask.js +56 -0
  9. package/dist/migrate/runner/tasks/common/JsonTask.js +47 -0
  10. package/dist/migrate/runner/tasks/common/LabelExpertSlot.js +7 -3
  11. package/dist/migrate/runner/tasks/common/MarkRemovedSlotTask.js +17 -0
  12. package/dist/migrate/runner/tasks/common/MergeHtmlTask.js +36 -0
  13. package/dist/migrate/runner/tasks/common/NpmRcAddRuleTask.js +40 -0
  14. package/dist/migrate/runner/tasks/common/RefactorPropertyLabelReplaceFalse.js +53 -0
  15. package/dist/migrate/runner/tasks/common/RemoveTask.js +18 -0
  16. package/dist/migrate/runner/tasks/common/RenameSlotNameTask.js +17 -0
  17. package/dist/migrate/runner/tasks/common/TsConfigReconfigureTask.js +51 -0
  18. package/dist/migrate/runner/tasks/common/VsCodeSettingsReconfigureTask.js +54 -0
  19. package/dist/migrate/runner/tasks/index.js +17 -0
  20. package/dist/migrate/runner/tasks/test/index.js +2 -4
  21. package/dist/migrate/runner/tasks/test/test-version-next-99.js +10 -0
  22. package/dist/migrate/runner/tasks/v1/abbr.js +2 -1
  23. package/dist/migrate/runner/tasks/v1/assets.js +34 -0
  24. package/dist/migrate/runner/tasks/v1/button.js +2 -1
  25. package/dist/migrate/runner/tasks/v1/icon.js +2 -1
  26. package/dist/migrate/runner/tasks/v1/index.js +52 -22
  27. package/dist/migrate/runner/tasks/v1/input-checkbox.js +2 -1
  28. package/dist/migrate/runner/tasks/v1/input-color.js +2 -1
  29. package/dist/migrate/runner/tasks/v1/input-date.js +2 -1
  30. package/dist/migrate/runner/tasks/v1/input-email.js +2 -1
  31. package/dist/migrate/runner/tasks/v1/input-file.js +5 -0
  32. package/dist/migrate/runner/tasks/v1/input-number.js +2 -1
  33. package/dist/migrate/runner/tasks/v1/input-password.js +5 -0
  34. package/dist/migrate/runner/tasks/v1/input-range.js +2 -1
  35. package/dist/migrate/runner/tasks/v1/input-text.js +2 -1
  36. package/dist/migrate/runner/tasks/v1/input.js +5 -0
  37. package/dist/migrate/runner/tasks/v1/nav.js +3 -2
  38. package/dist/migrate/runner/tasks/v1/pagination.js +4 -1
  39. package/dist/migrate/runner/tasks/v1/select.js +2 -1
  40. package/dist/migrate/runner/tasks/v1/span.js +2 -1
  41. package/dist/migrate/runner/tasks/v1/split-button.js +3 -1
  42. package/dist/migrate/runner/tasks/v1/tabs.js +2 -1
  43. package/dist/migrate/runner/tasks/v1/toast.js +3 -1
  44. package/dist/migrate/shares/reuse.js +21 -7
  45. package/package.json +64 -62
  46. package/dist/migrate/runner/tasks/test/test-version-next-2.js +0 -10
  47. package/dist/migrate/runner/tasks/test/test-version-next-3.js +0 -10
package/README.md CHANGED
@@ -50,15 +50,20 @@ With the `migrate` command you can migrate your project to the latest version of
50
50
  Actually the following migrations are available:
51
51
 
52
52
  - Component renaming ✓
53
- - Component removal
53
+ - Component removal (no one yet)
54
54
  - Property renaming ✓
55
55
  - Property removal ✓
56
- - Property type change
57
- - Logic refactoring
56
+ - Slots renaming (`content`)
57
+ - Slots removal (`footer`, `header`) ✓
58
+ - Logic refactoring (no one yet)
58
59
  - Expert-Slot refactoring ⏰
59
- - `.vscode/settings.json` add IntelliSense for HTML ⏰
60
- - `.gitignore` exclude `.kolibri.migrate.json` ⏰
61
- - `.tsconfig` add `@public-ui/components` to `types` array
60
+ - Move `innerText` to property
61
+ - Property type change (remove `_label={false}`)
62
+ - Set `_label=""` to activate the expert slot
63
+ - `.vscode/settings.json` add IntelliSense for HTML ✓
64
+ - `.gitignore` exclude `.kolibri.migrate.json` ✓
65
+ - `.tsconfig` add `@public-ui/components` to `types` array ✓
66
+ - Format modified files (`prettier@^3`) ✓
62
67
 
63
68
  #### How does it work?
64
69
 
@@ -84,10 +89,12 @@ kolibri migrate <path>
84
89
 
85
90
  #### Options
86
91
 
87
- | Option | Description | Type | Default |
88
- | ------------------------------ | ----------------------------------------- | :------------------: | :------: |
89
- | `--ignore-uncommitted-changes` | Allows execution with uncommitted changes | boolean | false |
90
- | `--remove-mode` | Prefix property name or delete property | `delete` \| `prefix` | `prefix` |
92
+ | Option | Description | Type | Default |
93
+ | ------------------------------ | ---------------------------------------------- | :------------------: | :------: |
94
+ | `--format` | Try to format the modified files with prettier | boolean | true |
95
+ | `--ignore-greater-version` | Allows execution with greater versions | boolean | false |
96
+ | `--ignore-uncommitted-changes` | Allows execution with uncommitted changes | boolean | false |
97
+ | `--remove-mode` | Prefix property name or delete property | `delete` \| `prefix` | `prefix` |
91
98
 
92
99
  #### Configuration
93
100
 
package/dist/index.js CHANGED
File without changes
@@ -3,13 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const chalk_1 = __importDefault(require("chalk"));
6
7
  const child_process_1 = require("child_process");
7
8
  const commander_1 = require("commander");
8
9
  const fs_1 = __importDefault(require("fs"));
10
+ const node_child_process_1 = __importDefault(require("node:child_process"));
9
11
  const path_1 = __importDefault(require("path"));
12
+ const semver_1 = __importDefault(require("semver"));
10
13
  const task_runner_1 = require("./runner/task-runner");
14
+ const tasks_1 = require("./runner/tasks");
11
15
  const test_1 = require("./runner/tasks/test");
12
16
  const v1_1 = require("./runner/tasks/v1");
17
+ const assets_1 = require("./runner/tasks/v1/assets");
13
18
  const reuse_1 = require("./shares/reuse");
14
19
  const types_1 = require("./types");
15
20
  /**
@@ -21,6 +26,8 @@ function default_1(program) {
21
26
  .command('migrate')
22
27
  .description('This command migrates KoliBri code to the current version.')
23
28
  .argument('[string]', 'Source code folder to migrate', 'src')
29
+ .addOption(new commander_1.Option('--format', 'Try to format the modified files with prettier').default(true))
30
+ .addOption(new commander_1.Option('--ignore-greater-version', 'Allows execution with greater versions').default(false))
24
31
  .addOption(new commander_1.Option('--ignore-uncommitted-changes', 'Allows execution with uncommitted changes').default(false))
25
32
  .addOption(new commander_1.Option('--remove-mode <mode>', 'Prefix property name or delete property').choices(types_1.REMOVE_MODE).default('prefix'))
26
33
  .addOption(new commander_1.Option('--test-tasks', 'Run additional test tasks').default(false).hideHelp())
@@ -40,6 +47,9 @@ function default_1(program) {
40
47
  Current version of @public-ui/components: ${versionOfPublicUiComponents}
41
48
  Source folder to migrate: ${baseDir}
42
49
  `);
50
+ if (!options.ignoreGreaterVersion && semver_1.default.lt(versionOfPublicUiKoliBriCli, versionOfPublicUiComponents)) {
51
+ throw (0, reuse_1.logAndCreateError)('Your current version of @public-ui/components is greater than the version of @public-ui/kolibri-cli. Please update @public-ui/kolibri-cli or force the migration with --ignore-greater-version.');
52
+ }
43
53
  const configFile = path_1.default.resolve(process.cwd(), '.kolibri.config.json');
44
54
  let config = {};
45
55
  if (fs_1.default.existsSync(configFile)) {
@@ -51,7 +61,9 @@ Source folder to migrate: ${baseDir}
51
61
  }
52
62
  }
53
63
  const runner = new task_runner_1.TaskRunner(baseDir, versionOfPublicUiKoliBriCli, versionOfPublicUiComponents, config);
64
+ runner.registerTasks(tasks_1.commonTasks);
54
65
  runner.registerTasks(v1_1.v1Tasks);
66
+ runner.registerTasks((0, assets_1.getAssetTasks)(baseDir));
55
67
  if (options.testTasks) {
56
68
  runner.registerTasks(test_1.testTasks);
57
69
  }
@@ -68,7 +80,7 @@ Source folder to migrate: ${baseDir}
68
80
  fs_1.default.writeFileSync(path_1.default.resolve(process.cwd(), 'package.json'), packageJson);
69
81
  runner.setProjectVersion(version);
70
82
  console.log(`- Update @public-ui/* to version ${version}`);
71
- (0, child_process_1.exec)((0, reuse_1.getPackageManagerInstallCommand)(), (err) => {
83
+ (0, child_process_1.exec)((0, reuse_1.getPackageManagerCommand)('install'), (err) => {
72
84
  if (err) {
73
85
  console.error(`exec error: ${err.message}`);
74
86
  return;
@@ -76,23 +88,64 @@ Source folder to migrate: ${baseDir}
76
88
  runLoop();
77
89
  });
78
90
  }
91
+ else if (semver_1.default.lt(version, versionOfPublicUiComponents)) {
92
+ version = versionOfPublicUiComponents;
93
+ let packageJson = (0, reuse_1.getContentOfProjectPkgJson)();
94
+ packageJson = packageJson.replace(/"(@public-ui\/[^"]+)":\s*".*"/g, `"$1": "${version}"`);
95
+ fs_1.default.writeFileSync(path_1.default.resolve(process.cwd(), 'package.json'), packageJson);
96
+ runner.setProjectVersion(version);
97
+ console.log(`- Update @public-ui/* to version ${version}`);
98
+ (0, child_process_1.exec)((0, reuse_1.getPackageManagerCommand)('install'), (err) => {
99
+ if (err) {
100
+ console.error(`exec error: ${err.message}`);
101
+ return;
102
+ }
103
+ finish();
104
+ });
105
+ }
79
106
  else {
80
- console.log(`
107
+ finish();
108
+ }
109
+ }
110
+ /**
111
+ * Prints the status of the task runner and the modified files.
112
+ */
113
+ function finish() {
114
+ console.log(`
81
115
  Status of all executed Tasks:`);
82
- const status = runner.getStatus(true);
83
- fs_1.default.writeFileSync(configFile, JSON.stringify(status.config, null, 2));
84
- console.log(`
116
+ const status = runner.getStatus(true);
117
+ fs_1.default.writeFileSync(configFile, JSON.stringify(status.config, null, 2));
118
+ console.log(`
85
119
  Modified files: ${reuse_1.MODIFIED_FILES.size}`);
86
- reuse_1.MODIFIED_FILES.forEach((file) => {
87
- console.log(`- ${file}`);
88
- });
120
+ reuse_1.MODIFIED_FILES.forEach((file) => {
121
+ console.log(`- ${file}`);
122
+ });
123
+ if (reuse_1.MODIFIED_FILES.size > 0 && options.format) {
89
124
  console.log(`
90
- After the code migration has gone through, the code formatting may no longer be as desired. Therefore, please reformat your code afterwards if necessary.
125
+ We try to format the modified files with prettier...`);
126
+ try {
127
+ node_child_process_1.default.execFileSync('npx', ['prettier', '-w', ...Array.from(reuse_1.MODIFIED_FILES)], {
128
+ encoding: 'utf-8',
129
+ });
130
+ console.log(`Modified files have been formatted.`);
131
+ }
132
+ catch (e) {
133
+ console.log(`Modified files could not be formatted. Please format them manually: npx prettier ${baseDir} -w`);
134
+ }
135
+ console.log();
136
+ }
137
+ console.log(chalk_1.default.cyan(`
138
+ ${chalk_1.default.bold.bgCyan(`The migration is complete.`)} Please check the modified files and commit them if necessary.`));
139
+ console.log(chalk_1.default.magenta(`
140
+ Despite the best possible preparation of migration steps, we will certainly not be able to fully migrate every individual source code in the project. After running the migration tool, please see where you may still need to help yourself and feel free to provide feedback on what we can improve.
91
141
 
92
- Afterwards, it may be that functions or themes in newer major versions have changed or are no longer included. This should be checked finally and corrected manually if necessary.
142
+ After all the changes are made, the modified files are formatted using Prettier.
93
143
 
94
- Is anything wrong, you can reset the migration with "git reset --hard HEAD~1" or by discarding the affected files. For more information read the troubleshooting section in the README.`);
95
- }
144
+ When migrating the labels, the text (innerText) is assigned 1 to 1 to the _label property. There could be the following situation, where manual corrections have to be made: ${chalk_1.default.italic.white(`_label={\`I am {count} years old.\`}`)} -> ${chalk_1.default.italic.white(`_label={\`I am \${count} years old.\`}`)} (add a $)
145
+
146
+ Afterwards, it may be that functions or themes have changed or are no longer included in newer major versions. This should be checked finally and corrected manually if necessary.
147
+
148
+ If something is wrong, the migration can be reverted with ${chalk_1.default.italic.white(`git reset --hard HEAD~1`)} or by discarding the affected files. For more information, read the troubleshooting section in the README.`));
96
149
  }
97
150
  const status = runner.getStatus();
98
151
  console.log(`
@@ -53,12 +53,22 @@ class TaskRunner {
53
53
  }
54
54
  registerTasks(tasks) {
55
55
  tasks.forEach((task) => {
56
+ const dependentTasks = task.getDependentTasks();
57
+ if (dependentTasks.length > 0) {
58
+ this.registerTasks(dependentTasks);
59
+ }
56
60
  if (semver_1.default.gtr(this.projectVersion, task.getVersionRange(), {
57
61
  includePrerelease: true,
58
62
  })) {
59
63
  console.log(`Task "${task.getTitle()}" will be excluded. The current version (${this.projectVersion}) is greater than the task version range (${task.getVersionRange()}).`);
60
64
  this.config.migrate.tasks[task.getIdentifier()] = false;
61
65
  }
66
+ else if (semver_1.default.ltr(this.cliVersion, task.getVersionRange(), {
67
+ includePrerelease: true,
68
+ })) {
69
+ console.log(`Task "${task.getTitle()}" will be excluded. The target version (${this.cliVersion}) is lower than the task version range (${task.getVersionRange()}).`);
70
+ this.config.migrate.tasks[task.getIdentifier()] = false;
71
+ }
62
72
  else {
63
73
  this.tasks.set(task.getIdentifier(), task);
64
74
  }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExecTask = void 0;
4
+ const child_process_1 = require("child_process");
5
+ const abstract_task_1 = require("../../abstract-task");
6
+ class ExecTask extends abstract_task_1.AbstractTask {
7
+ constructor(identifier, title, command, versionRange, dependentTasks, options) {
8
+ super(identifier, title, [], versionRange, dependentTasks, options);
9
+ this.command = command;
10
+ }
11
+ static getInstance(command, versionRange, dependentTasks = [], options = {}) {
12
+ const identifier = `exec-${command}`;
13
+ const title = `Exec ${command}.`;
14
+ if (!this.instances.has(identifier)) {
15
+ this.instances.set(identifier, new ExecTask(identifier, title, command, versionRange, dependentTasks, options));
16
+ }
17
+ return this.instances.get(identifier);
18
+ }
19
+ run() {
20
+ try {
21
+ (0, child_process_1.execSync)(this.command, {
22
+ encoding: 'utf8',
23
+ });
24
+ }
25
+ catch (error) {
26
+ console.warn(error);
27
+ }
28
+ }
29
+ }
30
+ exports.ExecTask = ExecTask;
@@ -0,0 +1,44 @@
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.GenericRenameSlotNameTask = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const types_1 = require("../../../../types");
9
+ const reuse_1 = require("../../../shares/reuse");
10
+ const abstract_task_1 = require("../../abstract-task");
11
+ class GenericRenameSlotNameTask extends abstract_task_1.AbstractTask {
12
+ constructor(identifier, description, tag, oldSlotName, newSlotName, slotAttributeName, versionRange, dependentTasks, options) {
13
+ super(identifier, description, types_1.MARKUP_EXTENSIONS, versionRange, dependentTasks, options);
14
+ this.newSlotName = newSlotName;
15
+ this.slotAttributeName = slotAttributeName;
16
+ if (!reuse_1.isTagKebabCaseRegExp.test(tag)) {
17
+ throw (0, reuse_1.logAndCreateError)(`Tag "${tag}" is not in kebab case.`);
18
+ }
19
+ if (!reuse_1.isKebabCaseRegExp.test(oldSlotName)) {
20
+ throw (0, reuse_1.logAndCreateError)(`Slot name "${oldSlotName}" is not in kebab case.`);
21
+ }
22
+ if (!reuse_1.isKebabCaseRegExp.test(newSlotName)) {
23
+ throw (0, reuse_1.logAndCreateError)(`New slot name "${newSlotName}" is not in kebab case.`);
24
+ }
25
+ this.regExpCurlyBrackets = new RegExp(`(data-removed-)*slot=\\{'${oldSlotName}'\\}`, 'g');
26
+ this.regExpQuotationMarks = new RegExp(`(data-removed-)*slot="${oldSlotName}"`, 'g');
27
+ this.regExpCurlyBracketsAndQuotationMarks = new RegExp(`(data-removed-)*slot=\\{"${oldSlotName}"\\}`, 'g');
28
+ }
29
+ run(baseDir) {
30
+ (0, reuse_1.filterFilesByExt)(baseDir, types_1.COMPONENT_FILE_EXTENSIONS).forEach((file) => {
31
+ const content = fs_1.default.readFileSync(file, 'utf8');
32
+ const newContent = content
33
+ // Replacements
34
+ .replace(this.regExpCurlyBrackets, `${this.slotAttributeName}="${this.newSlotName}"`)
35
+ .replace(this.regExpQuotationMarks, `${this.slotAttributeName}="${this.newSlotName}"`)
36
+ .replace(this.regExpCurlyBracketsAndQuotationMarks, `${this.slotAttributeName}="${this.newSlotName}"`);
37
+ if (content !== newContent) {
38
+ reuse_1.MODIFIED_FILES.add(file);
39
+ fs_1.default.writeFileSync(file, newContent);
40
+ }
41
+ });
42
+ }
43
+ }
44
+ exports.GenericRenameSlotNameTask = GenericRenameSlotNameTask;
@@ -0,0 +1,40 @@
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.GitIgnoreAddRuleTask = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const reuse_1 = require("../../../shares/reuse");
10
+ const abstract_task_1 = require("../../abstract-task");
11
+ class GitIgnoreAddRuleTask extends abstract_task_1.AbstractTask {
12
+ constructor(identifier, rule, versionRange, dependentTasks = [], options = {}) {
13
+ super(identifier, `Add the rule "${rule}" to the .gitignore of your project.`, [], versionRange, dependentTasks, options);
14
+ this.rule = rule;
15
+ if (typeof rule !== 'string') {
16
+ throw (0, reuse_1.logAndCreateError)(`Definition of task "${this.identifier}" is not a string.`);
17
+ }
18
+ }
19
+ static getInstance(rule, versionRange, dependentTasks = [], options = {}) {
20
+ const identifier = `.gitignore-add-rule-${rule}`;
21
+ if (!this.instances.has(identifier)) {
22
+ this.instances.set(identifier, new GitIgnoreAddRuleTask(identifier, rule, versionRange, dependentTasks, options));
23
+ }
24
+ return this.instances.get(identifier);
25
+ }
26
+ run() {
27
+ const gitignorePath = path_1.default.join(process.cwd(), '.gitignore');
28
+ const lineToAdd = this.rule.trim();
29
+ if (!fs_1.default.existsSync(gitignorePath)) {
30
+ fs_1.default.writeFileSync(gitignorePath, lineToAdd + '\n');
31
+ }
32
+ else {
33
+ const fileContent = fs_1.default.readFileSync(gitignorePath, 'utf8');
34
+ if (!fileContent.split('\n').includes(lineToAdd)) {
35
+ fs_1.default.appendFileSync(gitignorePath, '\n' + lineToAdd);
36
+ }
37
+ }
38
+ }
39
+ }
40
+ exports.GitIgnoreAddRuleTask = GitIgnoreAddRuleTask;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HandleDependencyTask = void 0;
4
+ const child_process_1 = require("child_process");
5
+ const abstract_task_1 = require("../../abstract-task");
6
+ const reuse_1 = require("../../../shares/reuse");
7
+ class HandleDependencyTask extends abstract_task_1.AbstractTask {
8
+ constructor(identifier, title, command, dependencies, // Map<string, string | null>
9
+ devDependencies, // Map<string, string | null>
10
+ versionRange, dependentTasks, options) {
11
+ super(identifier, title, [], versionRange, dependentTasks, options);
12
+ this.command = command;
13
+ this.dependencies = dependencies;
14
+ this.devDependencies = devDependencies;
15
+ }
16
+ static getInstance(command, dependencies, devDependencies, versionRange, dependentTasks = [], options = {}) {
17
+ const identifier = `${command}-${Object.keys(dependencies !== null && dependencies !== void 0 ? dependencies : {}).join(',')}-${Object.keys(devDependencies !== null && devDependencies !== void 0 ? devDependencies : {}).join(',')}`;
18
+ const title = `${command === 'add' ? 'Add' : command === 'install' ? 'Install' : 'Remove'} dependency "${Object.keys(dependencies !== null && dependencies !== void 0 ? dependencies : {}).join(', ')}" and devDependency "${Object.keys(devDependencies !== null && devDependencies !== void 0 ? devDependencies : {}).join(', ')}".`;
19
+ if (!this.instances.has(identifier)) {
20
+ this.instances.set(identifier, new HandleDependencyTask(identifier, title, command, dependencies, devDependencies, versionRange, dependentTasks, options));
21
+ }
22
+ return this.instances.get(identifier);
23
+ }
24
+ run() {
25
+ var _a, _b, _c, _d;
26
+ if (Object.keys((_a = this.dependencies) !== null && _a !== void 0 ? _a : {}).length > 0) {
27
+ let command = `${(0, reuse_1.getPackageManagerCommand)(this.command)}`;
28
+ Object.keys((_b = this.dependencies) !== null && _b !== void 0 ? _b : {}).forEach((dependency) => {
29
+ command += ` ${dependency}@${this.dependencies[dependency]}`;
30
+ });
31
+ try {
32
+ (0, child_process_1.execSync)(command, {
33
+ encoding: 'utf8',
34
+ });
35
+ }
36
+ catch (error) {
37
+ console.warn(error);
38
+ }
39
+ }
40
+ if (Object.keys((_c = this.devDependencies) !== null && _c !== void 0 ? _c : {}).length > 0) {
41
+ let command = `${(0, reuse_1.getPackageManagerCommand)(this.command)} -D`;
42
+ Object.keys((_d = this.devDependencies) !== null && _d !== void 0 ? _d : {}).forEach((dependency) => {
43
+ command += ` ${dependency}`;
44
+ });
45
+ try {
46
+ (0, child_process_1.execSync)(command, {
47
+ encoding: 'utf8',
48
+ });
49
+ }
50
+ catch (error) {
51
+ console.warn(error);
52
+ }
53
+ }
54
+ }
55
+ }
56
+ exports.HandleDependencyTask = HandleDependencyTask;
@@ -0,0 +1,47 @@
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.JsonTask = void 0;
7
+ const deepmerge_1 = __importDefault(require("deepmerge"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const reuse_1 = require("../../../shares/reuse");
11
+ const abstract_task_1 = require("../../abstract-task");
12
+ class JsonTask extends abstract_task_1.AbstractTask {
13
+ constructor(identifier, key, json, versionRange, dependentTasks = [], options = {}) {
14
+ super(identifier, `Reconfigure "${key}" in package.json of your project.`, [], versionRange, dependentTasks, options);
15
+ this.json = json;
16
+ if (typeof key !== 'string') {
17
+ throw (0, reuse_1.logAndCreateError)(`Key of task "${this.identifier}" is not a string.`);
18
+ }
19
+ try {
20
+ JSON.stringify(json);
21
+ }
22
+ catch (_a) {
23
+ throw (0, reuse_1.logAndCreateError)(`Value of task "${this.identifier}" is not able to stringify (JSON).`);
24
+ }
25
+ }
26
+ static getInstance(key, json, versionRange, dependentTasks = [], options = {}) {
27
+ const identifier = `package.json-reconfigure-${key}`;
28
+ if (!this.instances.has(identifier)) {
29
+ this.instances.set(identifier, new JsonTask(identifier, key, json, versionRange, dependentTasks, options));
30
+ }
31
+ return this.instances.get(identifier);
32
+ }
33
+ run() {
34
+ const configPath = path_1.default.join(process.cwd(), 'package.json');
35
+ if (fs_1.default.existsSync(configPath)) {
36
+ try {
37
+ const fileContent = (0, deepmerge_1.default)(JSON.parse(fs_1.default.readFileSync(configPath, 'utf8')), this.json);
38
+ fs_1.default.writeFileSync(configPath, JSON.stringify(fileContent, null, 2));
39
+ reuse_1.MODIFIED_FILES.add(configPath);
40
+ }
41
+ catch (e) {
42
+ // empty
43
+ }
44
+ }
45
+ }
46
+ }
47
+ exports.JsonTask = JsonTask;
@@ -26,6 +26,8 @@ class LabelExpertSlot extends abstract_task_1.AbstractTask {
26
26
  // https://regex101.com/r/WkEKxu/1
27
27
  this.componentRegExp = new RegExp(`(<${tagCapitalCase}[^>]*)>([^<]+(\\n\\s*)*)(<\\/${tagCapitalCase}>)`, 'g');
28
28
  this.customElementRegExp = new RegExp(`(<${tag}[^>]*)>([^<]+(\\n\\s*)*)(<\\/${tag}>)`, 'g');
29
+ this.componentRegExp = new RegExp(`(<${tagCapitalCase}[^>]*)>([^<>]+)(<\\/${tagCapitalCase}>)`, 'g');
30
+ this.customElementRegExp = new RegExp(`(<${tag}[^>]*)>([^<>]+)(<\\/${tag}>)`, 'g');
29
31
  }
30
32
  static getInstance(tag, property, versionRange, dependentTasks = [], options = {}) {
31
33
  const identifier = `${tag}-move-innerText-to-property-${property}`;
@@ -44,7 +46,8 @@ class LabelExpertSlot extends abstract_task_1.AbstractTask {
44
46
  const newContent = content
45
47
  // Replacements
46
48
  .replace(this.componentRegExp, removeLineBreaksAndSpaces)
47
- .replace(this.componentRegExp, `$1 ${this.propertyInCamelCase}="$2">$4`);
49
+ // @todo: We could add a $ before all { inside the innerText ($2)
50
+ .replace(this.componentRegExp, `$1 ${this.propertyInCamelCase}={\`$2\`}/>`);
48
51
  if (content !== newContent) {
49
52
  reuse_1.MODIFIED_FILES.add(file);
50
53
  fs_1.default.writeFileSync(file, newContent);
@@ -57,10 +60,11 @@ class LabelExpertSlot extends abstract_task_1.AbstractTask {
57
60
  const newContent = content
58
61
  // Replacements
59
62
  .replace(this.customElementRegExp, removeLineBreaksAndSpaces)
60
- .replace(this.customElementRegExp, `$1 ${this.property}="$2">$4`);
63
+ // @todo: We could add a $ before all { inside the innerText ($2)
64
+ .replace(this.customElementRegExp, `$1 ${this.property}={\`$2\`}/>`);
61
65
  if (content !== newContent) {
62
66
  reuse_1.MODIFIED_FILES.add(file);
63
- // fs.writeFileSync(file, newContent);
67
+ fs_1.default.writeFileSync(file, newContent);
64
68
  }
65
69
  });
66
70
  }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MarkRemovedSlotTask = void 0;
4
+ const GenericRenameSlotNameTask_1 = require("./GenericRenameSlotNameTask");
5
+ class MarkRemovedSlotTask extends GenericRenameSlotNameTask_1.GenericRenameSlotNameTask {
6
+ constructor(identifier, tag, slotName, versionRange, dependentTasks, options) {
7
+ super(identifier, `Mark removed slot "${slotName}" of "${tag}" component`, tag, slotName, `${slotName}`, 'data-removed-slot', versionRange, dependentTasks, options);
8
+ }
9
+ static getInstance(tag, slotName, versionRange, dependentTasks = [], options = {}) {
10
+ const identifier = `${tag}-mark-removed-slot-${slotName}`;
11
+ if (!this.instances.has(identifier)) {
12
+ this.instances.set(identifier, new MarkRemovedSlotTask(identifier, tag, slotName, versionRange, dependentTasks, options));
13
+ }
14
+ return this.instances.get(identifier);
15
+ }
16
+ }
17
+ exports.MarkRemovedSlotTask = MarkRemovedSlotTask;
@@ -0,0 +1,36 @@
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.MergeHtmlTask = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const reuse_1 = require("../../../shares/reuse");
9
+ const abstract_task_1 = require("../../abstract-task");
10
+ class MergeHtmlTask extends abstract_task_1.AbstractTask {
11
+ constructor(identifier, title, path, filename, html, versionRange, dependentTasks, options) {
12
+ super(identifier, title, [], versionRange, dependentTasks, options);
13
+ this.path = path;
14
+ this.filename = filename;
15
+ this.html = html;
16
+ }
17
+ static getInstance(key, path, filename, html, versionRange, dependentTasks = [], options = {}) {
18
+ const identifier = `merge-html-${key}-in-${filename}`;
19
+ const title = `Merge html (${key}) in ${filename}.`;
20
+ if (!this.instances.has(identifier)) {
21
+ this.instances.set(identifier, new MergeHtmlTask(identifier, title, path, filename, html, versionRange, dependentTasks, options));
22
+ }
23
+ return this.instances.get(identifier);
24
+ }
25
+ run() {
26
+ if (fs_1.default.existsSync(this.path)) {
27
+ const content = fs_1.default.readFileSync(this.path, 'utf8');
28
+ if (!content.includes(this.html)) {
29
+ fs_1.default.writeFileSync(this.path, content.replace(/(>)([^<]+<\/head>)/, `$1
30
+ ${this.html}$2`));
31
+ reuse_1.MODIFIED_FILES.add(this.path);
32
+ }
33
+ }
34
+ }
35
+ }
36
+ exports.MergeHtmlTask = MergeHtmlTask;
@@ -0,0 +1,40 @@
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.NpmRcAddRuleTask = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const reuse_1 = require("../../../shares/reuse");
10
+ const abstract_task_1 = require("../../abstract-task");
11
+ class NpmRcAddRuleTask extends abstract_task_1.AbstractTask {
12
+ constructor(identifier, rule, versionRange, dependentTasks = [], options = {}) {
13
+ super(identifier, `Add the rule "${rule}" to the .npmrc of your project.`, [], versionRange, dependentTasks, options);
14
+ this.rule = rule;
15
+ if (typeof rule !== 'string') {
16
+ throw (0, reuse_1.logAndCreateError)(`Definition of task "${this.identifier}" is not a string.`);
17
+ }
18
+ }
19
+ static getInstance(rule, versionRange, dependentTasks = [], options = {}) {
20
+ const identifier = `.npmrc-add-rule-${rule}`;
21
+ if (!this.instances.has(identifier)) {
22
+ this.instances.set(identifier, new NpmRcAddRuleTask(identifier, rule, versionRange, dependentTasks, options));
23
+ }
24
+ return this.instances.get(identifier);
25
+ }
26
+ run() {
27
+ const npmrcPath = path_1.default.join(process.cwd(), '.npmrc');
28
+ const lineToAdd = this.rule.trim();
29
+ if (!fs_1.default.existsSync(npmrcPath)) {
30
+ fs_1.default.writeFileSync(npmrcPath, lineToAdd + '\n');
31
+ }
32
+ else {
33
+ const fileContent = fs_1.default.readFileSync(npmrcPath, 'utf8');
34
+ if (!fileContent.split('\n').includes(lineToAdd)) {
35
+ fs_1.default.appendFileSync(npmrcPath, '\n' + lineToAdd);
36
+ }
37
+ }
38
+ }
39
+ }
40
+ exports.NpmRcAddRuleTask = NpmRcAddRuleTask;
@@ -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.RefactorPropertyLabelReplaceFalse = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const types_1 = require("../../../../types");
9
+ const reuse_1 = require("../../../shares/reuse");
10
+ const abstract_task_1 = require("../../abstract-task");
11
+ class RefactorPropertyLabelReplaceFalse extends abstract_task_1.AbstractTask {
12
+ constructor() {
13
+ super(`refactor-property-label-replace-false`, `Refactor property "_label" - replace "false" with ""`, types_1.MARKUP_EXTENSIONS, '>=1.6 <=1.7');
14
+ this.componentRegExp = /_label={false}/g;
15
+ this.customElementRegExp = /_label="false"/g;
16
+ }
17
+ static getInstance() {
18
+ const identifier = `refact-property-label-replace-false`;
19
+ if (!this.instances.has(identifier)) {
20
+ this.instances.set(identifier, new RefactorPropertyLabelReplaceFalse());
21
+ }
22
+ return this.instances.get(identifier);
23
+ }
24
+ run(baseDir) {
25
+ this.transpileComponentFileDelete(baseDir);
26
+ this.transpileCustomElementFileDelete(baseDir);
27
+ }
28
+ transpileComponentFileDelete(baseDir) {
29
+ (0, reuse_1.filterFilesByExt)(baseDir, types_1.COMPONENT_FILE_EXTENSIONS).forEach((file) => {
30
+ const content = fs_1.default.readFileSync(file, 'utf8');
31
+ const newContent = content
32
+ // Replacements
33
+ .replace(this.componentRegExp, `_label=""`);
34
+ if (content !== newContent) {
35
+ reuse_1.MODIFIED_FILES.add(file);
36
+ fs_1.default.writeFileSync(file, newContent);
37
+ }
38
+ });
39
+ }
40
+ transpileCustomElementFileDelete(baseDir) {
41
+ (0, reuse_1.filterFilesByExt)(baseDir, types_1.CUSTOM_ELEMENT_FILE_EXTENSIONS).forEach((file) => {
42
+ const content = fs_1.default.readFileSync(file, 'utf8');
43
+ const newContent = content
44
+ // Replacements
45
+ .replace(this.customElementRegExp, `_label=""`);
46
+ if (content !== newContent) {
47
+ reuse_1.MODIFIED_FILES.add(file);
48
+ fs_1.default.writeFileSync(file, newContent);
49
+ }
50
+ });
51
+ }
52
+ }
53
+ exports.RefactorPropertyLabelReplaceFalse = RefactorPropertyLabelReplaceFalse;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RemoveTask = void 0;
4
+ const ExecTask_1 = require("./ExecTask");
5
+ class RemoveTask extends ExecTask_1.ExecTask {
6
+ constructor(identifier, title, path, versionRange, dependentTasks, options) {
7
+ super(identifier, title, `npx rimraf "${path}"`, versionRange, dependentTasks, options);
8
+ }
9
+ static getInstance(path, versionRange, dependentTasks = [], options = {}) {
10
+ const identifier = `remove-${path}`;
11
+ const title = `Remove ${path}.`;
12
+ if (!this.instances.has(identifier)) {
13
+ this.instances.set(identifier, new RemoveTask(identifier, title, path, versionRange, dependentTasks, options));
14
+ }
15
+ return this.instances.get(identifier);
16
+ }
17
+ }
18
+ exports.RemoveTask = RemoveTask;