@git.zone/cli 2.13.8 → 2.13.11

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 (106) hide show
  1. package/assets/templates/gitignore/_gitignore +4 -0
  2. package/assets/templates/{npmextra/npmextra.json → smartconfig/_smartconfig.json} +3 -0
  3. package/dist_ts/00_commitinfo_data.js +2 -2
  4. package/dist_ts/classes.gitzoneconfig.js +4 -4
  5. package/dist_ts/gitzone.cli.js +1 -15
  6. package/dist_ts/mod_commit/index.js +4 -4
  7. package/dist_ts/mod_config/classes.commitconfig.d.ts +3 -3
  8. package/dist_ts/mod_config/classes.commitconfig.js +20 -20
  9. package/dist_ts/mod_config/classes.releaseconfig.d.ts +3 -3
  10. package/dist_ts/mod_config/classes.releaseconfig.js +21 -21
  11. package/dist_ts/mod_config/index.js +12 -12
  12. package/dist_ts/mod_format/classes.baseformatter.d.ts +2 -9
  13. package/dist_ts/mod_format/classes.baseformatter.js +13 -26
  14. package/dist_ts/mod_format/classes.formatplanner.d.ts +1 -3
  15. package/dist_ts/mod_format/classes.formatplanner.js +11 -39
  16. package/dist_ts/mod_format/classes.formatstats.d.ts +0 -5
  17. package/dist_ts/mod_format/classes.formatstats.js +3 -35
  18. package/dist_ts/mod_format/formatters/cleanup.formatter.js +1 -2
  19. package/dist_ts/mod_format/formatters/copy.formatter.js +5 -8
  20. package/dist_ts/mod_format/formatters/gitignore.formatter.d.ts +5 -0
  21. package/dist_ts/mod_format/formatters/gitignore.formatter.js +23 -29
  22. package/dist_ts/mod_format/formatters/packagejson.formatter.js +5 -5
  23. package/dist_ts/mod_format/formatters/prettier.formatter.js +4 -12
  24. package/dist_ts/mod_format/formatters/{npmextra.formatter.d.ts → smartconfig.formatter.d.ts} +6 -1
  25. package/dist_ts/mod_format/formatters/smartconfig.formatter.js +180 -0
  26. package/dist_ts/mod_format/formatters/templates.formatter.js +1 -10
  27. package/dist_ts/mod_format/formatters/tsconfig.formatter.js +6 -4
  28. package/dist_ts/mod_format/index.d.ts +0 -4
  29. package/dist_ts/mod_format/index.js +27 -78
  30. package/dist_ts/mod_format/interfaces.format.d.ts +1 -18
  31. package/dist_ts/mod_format/interfaces.format.js +16 -2
  32. package/dist_ts/mod_format/mod.plugins.d.ts +2 -7
  33. package/dist_ts/mod_format/mod.plugins.js +3 -8
  34. package/dist_ts/mod_services/classes.globalregistry.js +2 -2
  35. package/dist_ts/mod_services/classes.servicemanager.d.ts +2 -2
  36. package/dist_ts/mod_services/classes.servicemanager.js +21 -21
  37. package/dist_ts/plugins.d.ts +2 -2
  38. package/dist_ts/plugins.js +3 -3
  39. package/package.json +11 -17
  40. package/readme.md +231 -218
  41. package/ts/00_commitinfo_data.ts +1 -1
  42. package/ts/classes.gitzoneconfig.ts +3 -3
  43. package/ts/gitzone.cli.ts +0 -17
  44. package/ts/mod_commit/index.ts +3 -3
  45. package/ts/mod_config/classes.commitconfig.ts +19 -19
  46. package/ts/mod_config/classes.releaseconfig.ts +20 -20
  47. package/ts/mod_config/index.ts +11 -11
  48. package/ts/mod_format/classes.baseformatter.ts +14 -25
  49. package/ts/mod_format/classes.formatplanner.ts +10 -39
  50. package/ts/mod_format/classes.formatstats.ts +2 -42
  51. package/ts/mod_format/formatters/cleanup.formatter.ts +0 -1
  52. package/ts/mod_format/formatters/copy.formatter.ts +4 -8
  53. package/ts/mod_format/formatters/gitignore.formatter.ts +25 -29
  54. package/ts/mod_format/formatters/packagejson.formatter.ts +4 -4
  55. package/ts/mod_format/formatters/prettier.formatter.ts +3 -13
  56. package/ts/mod_format/formatters/smartconfig.formatter.ts +213 -0
  57. package/ts/mod_format/formatters/templates.formatter.ts +0 -9
  58. package/ts/mod_format/formatters/tsconfig.formatter.ts +6 -3
  59. package/ts/mod_format/index.ts +35 -98
  60. package/ts/mod_format/interfaces.format.ts +16 -19
  61. package/ts/mod_format/mod.plugins.ts +2 -12
  62. package/ts/mod_services/classes.globalregistry.ts +2 -2
  63. package/ts/mod_services/classes.servicemanager.ts +20 -20
  64. package/ts/plugins.ts +2 -2
  65. package/dist_ts/mod_format/classes.changecache.d.ts +0 -26
  66. package/dist_ts/mod_format/classes.changecache.js +0 -181
  67. package/dist_ts/mod_format/classes.dependency-analyzer.d.ts +0 -13
  68. package/dist_ts/mod_format/classes.dependency-analyzer.js +0 -93
  69. package/dist_ts/mod_format/classes.rollbackmanager.d.ts +0 -22
  70. package/dist_ts/mod_format/classes.rollbackmanager.js +0 -259
  71. package/dist_ts/mod_format/format.cleanup.d.ts +0 -2
  72. package/dist_ts/mod_format/format.cleanup.js +0 -25
  73. package/dist_ts/mod_format/format.copy.d.ts +0 -24
  74. package/dist_ts/mod_format/format.copy.js +0 -77
  75. package/dist_ts/mod_format/format.gitignore.d.ts +0 -2
  76. package/dist_ts/mod_format/format.gitignore.js +0 -48
  77. package/dist_ts/mod_format/format.license.d.ts +0 -2
  78. package/dist_ts/mod_format/format.license.js +0 -26
  79. package/dist_ts/mod_format/format.npmextra.d.ts +0 -5
  80. package/dist_ts/mod_format/format.npmextra.js +0 -125
  81. package/dist_ts/mod_format/format.packagejson.d.ts +0 -2
  82. package/dist_ts/mod_format/format.packagejson.js +0 -145
  83. package/dist_ts/mod_format/format.prettier.d.ts +0 -2
  84. package/dist_ts/mod_format/format.prettier.js +0 -56
  85. package/dist_ts/mod_format/format.readme.d.ts +0 -1
  86. package/dist_ts/mod_format/format.readme.js +0 -29
  87. package/dist_ts/mod_format/format.templates.d.ts +0 -5
  88. package/dist_ts/mod_format/format.templates.js +0 -68
  89. package/dist_ts/mod_format/format.tsconfig.d.ts +0 -2
  90. package/dist_ts/mod_format/format.tsconfig.js +0 -28
  91. package/dist_ts/mod_format/formatters/npmextra.formatter.js +0 -142
  92. package/ts/mod_format/classes.changecache.ts +0 -235
  93. package/ts/mod_format/classes.dependency-analyzer.ts +0 -117
  94. package/ts/mod_format/classes.rollbackmanager.ts +0 -340
  95. package/ts/mod_format/format.cleanup.ts +0 -26
  96. package/ts/mod_format/format.copy.ts +0 -93
  97. package/ts/mod_format/format.gitignore.ts +0 -54
  98. package/ts/mod_format/format.license.ts +0 -32
  99. package/ts/mod_format/format.npmextra.ts +0 -151
  100. package/ts/mod_format/format.packagejson.ts +0 -196
  101. package/ts/mod_format/format.prettier.ts +0 -66
  102. package/ts/mod_format/format.readme.ts +0 -29
  103. package/ts/mod_format/format.templates.ts +0 -79
  104. package/ts/mod_format/format.tsconfig.ts +0 -31
  105. package/ts/mod_format/formatters/npmextra.formatter.ts +0 -174
  106. /package/{npmextra.json → .smartconfig.json} +0 -0
@@ -1,196 +0,0 @@
1
- import * as plugins from './mod.plugins.js';
2
- import * as paths from '../paths.js';
3
- import * as gulpFunction from '@push.rocks/gulp-function';
4
- import { Project } from '../classes.project.js';
5
-
6
- import { logger } from '../gitzone.logging.js';
7
-
8
- /**
9
- * ensures a certain dependency
10
- */
11
- const ensureDependency = async (
12
- packageJsonObjectArg: any,
13
- position: 'dep' | 'devDep' | 'everywhere',
14
- constraint: 'exclude' | 'include' | 'latest',
15
- dependencyArg: string,
16
- ) => {
17
- const [packageName, version] = dependencyArg.includes('@')
18
- ? dependencyArg.split('@').filter(Boolean)
19
- : [dependencyArg, 'latest'];
20
-
21
- const targetSections: string[] = [];
22
-
23
- switch (position) {
24
- case 'dep':
25
- targetSections.push('dependencies');
26
- break;
27
- case 'devDep':
28
- targetSections.push('devDependencies');
29
- break;
30
- case 'everywhere':
31
- targetSections.push('dependencies', 'devDependencies');
32
- break;
33
- }
34
-
35
- for (const section of targetSections) {
36
- if (!packageJsonObjectArg[section]) {
37
- packageJsonObjectArg[section] = {};
38
- }
39
-
40
- switch (constraint) {
41
- case 'exclude':
42
- delete packageJsonObjectArg[section][packageName];
43
- break;
44
- case 'include':
45
- if (!packageJsonObjectArg[section][packageName]) {
46
- packageJsonObjectArg[section][packageName] =
47
- version === 'latest' ? '^1.0.0' : version;
48
- }
49
- break;
50
- case 'latest':
51
- // Fetch latest version from npm
52
- try {
53
- const registry = new plugins.smartnpm.NpmRegistry();
54
- const packageInfo = await registry.getPackageInfo(packageName);
55
- const latestVersion = packageInfo['dist-tags'].latest;
56
- packageJsonObjectArg[section][packageName] = `^${latestVersion}`;
57
- } catch (error) {
58
- logger.log(
59
- 'warn',
60
- `Could not fetch latest version for ${packageName}, using existing or default`,
61
- );
62
- if (!packageJsonObjectArg[section][packageName]) {
63
- packageJsonObjectArg[section][packageName] =
64
- version === 'latest' ? '^1.0.0' : version;
65
- }
66
- }
67
- break;
68
- }
69
- }
70
- };
71
-
72
- export const run = async (projectArg: Project) => {
73
- const formatStreamWrapper = new plugins.smartstream.StreamWrapper([
74
- plugins.smartgulp.src([`package.json`]),
75
- gulpFunction.forEach(async (fileArg: plugins.smartfile.SmartFile) => {
76
- const npmextraConfig = new plugins.npmextra.Npmextra(paths.cwd);
77
- const gitzoneData: any = npmextraConfig.dataFor('@git.zone/cli', {});
78
- const fileString = fileArg.contents.toString();
79
- const packageJson = JSON.parse(fileString);
80
-
81
- // metadata
82
- packageJson.repository = {
83
- type: 'git',
84
- url: `https://${gitzoneData.module.githost}/${gitzoneData.module.gitscope}/${gitzoneData.module.gitrepo}.git`,
85
- };
86
- ((packageJson.bugs = {
87
- url: `https://${gitzoneData.module.githost}/${gitzoneData.module.gitscope}/${gitzoneData.module.gitrepo}/issues`,
88
- }),
89
- (packageJson.homepage = `https://${gitzoneData.module.githost}/${gitzoneData.module.gitscope}/${gitzoneData.module.gitrepo}#readme`));
90
-
91
- // Check for module type
92
- if (!packageJson.type) {
93
- logger.log('info', `setting packageJson.type to "module"`);
94
- packageJson.type = 'module';
95
- }
96
-
97
- // Check for private or public
98
- if (packageJson.private !== undefined) {
99
- logger.log(
100
- 'info',
101
- 'Success -> found private/public info in package.json!',
102
- );
103
- } else {
104
- logger.log(
105
- 'error',
106
- 'found no private boolean! Setting it to private for now!',
107
- );
108
- packageJson.private = true;
109
- }
110
-
111
- // Check for license
112
- if (packageJson.license) {
113
- logger.log('info', 'Success -> found license in package.json!');
114
- } else {
115
- logger.log(
116
- 'error',
117
- 'found no license! Setting it to UNLICENSED for now!',
118
- );
119
- packageJson.license = 'UNLICENSED';
120
- }
121
-
122
- // Check for build script
123
- if (packageJson.scripts.build) {
124
- logger.log('info', 'Success -> found build script in package.json!');
125
- } else {
126
- logger.log(
127
- 'error',
128
- 'found no build script! Putting a placeholder there for now!',
129
- );
130
- packageJson.scripts.build = `echo "Not needed for now"`;
131
- }
132
-
133
- // Check for buildDocs script
134
- if (!packageJson.scripts.buildDocs) {
135
- logger.log(
136
- 'info',
137
- 'found no buildDocs script! Putting tsdoc script there now.',
138
- );
139
- packageJson.scripts.buildDocs = `tsdoc`;
140
- }
141
-
142
- // check for files
143
- packageJson.files = [
144
- 'ts/**/*',
145
- 'ts_web/**/*',
146
- 'dist/**/*',
147
- 'dist_*/**/*',
148
- 'dist_ts/**/*',
149
- 'dist_ts_web/**/*',
150
- 'assets/**/*',
151
- 'cli.js',
152
- 'npmextra.json',
153
- 'readme.md',
154
- ];
155
-
156
- // check for dependencies
157
- // Note: @push.rocks/tapbundle is deprecated - use @git.zone/tstest/tapbundle instead
158
- await ensureDependency(
159
- packageJson,
160
- 'devDep',
161
- 'exclude',
162
- '@push.rocks/tapbundle',
163
- );
164
- await ensureDependency(
165
- packageJson,
166
- 'devDep',
167
- 'latest',
168
- '@git.zone/tstest',
169
- );
170
- await ensureDependency(
171
- packageJson,
172
- 'devDep',
173
- 'latest',
174
- '@git.zone/tsbuild',
175
- );
176
-
177
- // set overrides
178
- const overridesContent = (await plugins.smartfs
179
- .file(plugins.path.join(paths.assetsDir, 'overrides.json'))
180
- .encoding('utf8')
181
- .read()) as string;
182
- const overrides = JSON.parse(overridesContent);
183
- packageJson.pnpm = packageJson.pnpm || {};
184
- packageJson.pnpm.overrides = overrides;
185
-
186
- // exclude
187
- // TODO
188
-
189
- fileArg.setContentsFromString(JSON.stringify(packageJson, null, 2));
190
- }),
191
- plugins.smartgulp.replace(),
192
- ]);
193
- await formatStreamWrapper.run().catch((error) => {
194
- console.log(error);
195
- });
196
- };
@@ -1,66 +0,0 @@
1
- import * as plugins from './mod.plugins.js';
2
- import prettier from 'prettier';
3
- import { Project } from '../classes.project.js';
4
-
5
- import { logger } from '../gitzone.logging.js';
6
-
7
- const prettierDefaultTypeScriptConfig: prettier.Options = {
8
- printWidth: 100,
9
- parser: 'typescript',
10
- singleQuote: true,
11
- };
12
-
13
- const prettierDefaultMarkdownConfig: prettier.Options = {
14
- singleQuote: true,
15
- printWidth: 100,
16
- parser: 'markdown',
17
- };
18
-
19
- const filesToFormat = [
20
- `ts/**/*.ts`,
21
- `test/**/*.ts`,
22
- `readme.md`,
23
- `docs/**/*.md`,
24
- ];
25
-
26
- const choosePrettierConfig = (fileArg: plugins.smartfile.SmartFile) => {
27
- switch (fileArg.parsedPath.ext) {
28
- case '.ts':
29
- return prettierDefaultTypeScriptConfig;
30
- case '.md':
31
- return prettierDefaultMarkdownConfig;
32
- default:
33
- return {};
34
- }
35
- };
36
-
37
- const prettierTypeScriptPipestop = plugins.through2.obj(
38
- async (fileArg: plugins.smartfile.SmartFile, enc, cb) => {
39
- const fileString = fileArg.contentBuffer.toString();
40
- const chosenConfig = choosePrettierConfig(fileArg);
41
- const filePasses = await prettier.check(fileString, chosenConfig);
42
- if (filePasses) {
43
- logger.log('info', `OK! -> ${fileArg.path} passes!`);
44
- cb(null);
45
- } else {
46
- logger.log('info', `${fileArg.path} is being reformated!`);
47
- const formatedFileString = await prettier.format(
48
- fileString,
49
- chosenConfig,
50
- );
51
- fileArg.setContentsFromString(formatedFileString);
52
- cb(null, fileArg);
53
- }
54
- },
55
- );
56
-
57
- export const run = async (projectArg: Project) => {
58
- const formatStreamWrapper = new plugins.smartstream.StreamWrapper([
59
- plugins.smartgulp.src(filesToFormat),
60
- prettierTypeScriptPipestop,
61
- plugins.smartgulp.replace(),
62
- ]);
63
- await formatStreamWrapper.run().catch((error) => {
64
- console.log(error);
65
- });
66
- };
@@ -1,29 +0,0 @@
1
- import * as plugins from './mod.plugins.js';
2
- import * as paths from '../paths.js';
3
-
4
- export const run = async () => {
5
- const readmePath = plugins.path.join(paths.cwd, 'readme.md');
6
- const readmeHintsPath = plugins.path.join(paths.cwd, 'readme.hints.md');
7
-
8
- // Check and initialize readme.md if it doesn't exist
9
- const readmeExists = await plugins.smartfs.file(readmePath).exists();
10
- if (!readmeExists) {
11
- await plugins.smartfs.file(readmePath)
12
- .encoding('utf8')
13
- .write('# Project Readme\n\nThis is the initial readme file.');
14
- console.log('Initialized readme.md');
15
- } else {
16
- console.log('readme.md already exists');
17
- }
18
-
19
- // Check and initialize readme.hints.md if it doesn't exist
20
- const readmeHintsExists = await plugins.smartfs.file(readmeHintsPath).exists();
21
- if (!readmeHintsExists) {
22
- await plugins.smartfs.file(readmeHintsPath)
23
- .encoding('utf8')
24
- .write('# Project Readme Hints\n\nThis is the initial readme hints file.');
25
- console.log('Initialized readme.hints.md');
26
- } else {
27
- console.log('readme.hints.md already exists');
28
- }
29
- };
@@ -1,79 +0,0 @@
1
- import * as plugins from './mod.plugins.js';
2
- import * as paths from '../paths.js';
3
-
4
- import { logger } from '../gitzone.logging.js';
5
- import { Project } from '../classes.project.js';
6
-
7
- /**
8
- * takes care of updating files from templates
9
- */
10
- export const run = async (project: Project) => {
11
- const templateModule = await import('../mod_template/index.js');
12
-
13
- // update vscode
14
- const vscodeTemplate = await templateModule.getTemplate('vscode');
15
- await vscodeTemplate.writeToDisk(paths.cwd);
16
- logger.log('info', `Updated vscode template!`);
17
-
18
- // update gitlab ci and Dockerfile
19
- switch (project.gitzoneConfig.data.projectType) {
20
- case 'npm':
21
- case 'wcc':
22
- if (project.gitzoneConfig.data.npmciOptions.npmAccessLevel === 'public') {
23
- const ciTemplateDefault =
24
- await templateModule.getTemplate('ci_default');
25
- ciTemplateDefault.writeToDisk(paths.cwd);
26
- } else {
27
- const ciTemplateDefault =
28
- await templateModule.getTemplate('ci_default_private');
29
- ciTemplateDefault.writeToDisk(paths.cwd);
30
- }
31
- logger.log('info', 'Updated .gitlabci.yml!');
32
- break;
33
- case 'service':
34
- case 'website':
35
- const ciTemplateDocker = await templateModule.getTemplate('ci_docker');
36
- await ciTemplateDocker.writeToDisk(paths.cwd);
37
- logger.log('info', 'Updated CI/CD config files!');
38
-
39
- // lets care about docker
40
- const dockerTemplate =
41
- await templateModule.getTemplate('dockerfile_service');
42
- dockerTemplate.writeToDisk(paths.cwd);
43
- logger.log('info', 'Updated Dockerfile!');
44
-
45
- // lets care about cli
46
- const cliTemplate = await templateModule.getTemplate('cli');
47
- await cliTemplate.writeToDisk(paths.cwd);
48
- logger.log('info', 'Updated cli.ts.js and cli.js!');
49
- break;
50
- default:
51
- break;
52
- }
53
-
54
- // update html
55
- if (project.gitzoneConfig.data.projectType === 'website') {
56
- const websiteUpdateTemplate =
57
- await templateModule.getTemplate('website_update');
58
- const variables = {
59
- assetbrokerUrl: project.gitzoneConfig.data.module.assetbrokerUrl,
60
- legalUrl: project.gitzoneConfig.data.module.legalUrl,
61
- };
62
- console.log(
63
- 'updating website template with variables\n',
64
- JSON.stringify(variables, null, 2),
65
- );
66
- websiteUpdateTemplate.supplyVariables(variables);
67
- await websiteUpdateTemplate.writeToDisk(paths.cwd);
68
- logger.log('info', `Updated html for website!`);
69
- } else if (project.gitzoneConfig.data.projectType === 'service') {
70
- const websiteUpdateTemplate =
71
- await templateModule.getTemplate('service_update');
72
- await websiteUpdateTemplate.writeToDisk(paths.cwd);
73
- logger.log('info', `Updated html for element template!`);
74
- } else if (project.gitzoneConfig.data.projectType === 'wcc') {
75
- const wccUpdateTemplate = await templateModule.getTemplate('wcc_update');
76
- await wccUpdateTemplate.writeToDisk(paths.cwd);
77
- logger.log('info', `Updated html for wcc template!`);
78
- }
79
- };
@@ -1,31 +0,0 @@
1
- import * as plugins from './mod.plugins.js';
2
- import * as paths from '../paths.js';
3
-
4
- import { logger } from '../gitzone.logging.js';
5
- import { Project } from '../classes.project.js';
6
-
7
- export const run = async (projectArg: Project) => {
8
- // lets care about tsconfig.json
9
- logger.log('info', 'Formatting tsconfig.json...');
10
- const factory = plugins.smartfile.SmartFileFactory.nodeFs();
11
- const tsconfigSmartfile = await factory.fromFilePath(
12
- plugins.path.join(paths.cwd, 'tsconfig.json'),
13
- );
14
- const tsconfigObject = JSON.parse(tsconfigSmartfile.parseContentAsString());
15
- tsconfigObject.compilerOptions = tsconfigObject.compilerOptions || {};
16
- tsconfigObject.compilerOptions.baseUrl = '.';
17
- tsconfigObject.compilerOptions.paths = {};
18
- const tsPublishMod = await import('@git.zone/tspublish');
19
- const tsPublishInstance = new tsPublishMod.TsPublish();
20
- const publishModules = await tsPublishInstance.getModuleSubDirs(paths.cwd);
21
- for (const publishModule of Object.keys(publishModules)) {
22
- const publishConfig = publishModules[publishModule];
23
- tsconfigObject.compilerOptions.paths[`${publishConfig.name}`] = [
24
- `./${publishModule}/index.js`,
25
- ];
26
- }
27
- await tsconfigSmartfile.editContentAsString(async () => {
28
- return JSON.stringify(tsconfigObject, null, 2);
29
- });
30
- await tsconfigSmartfile.write();
31
- };
@@ -1,174 +0,0 @@
1
- import { BaseFormatter } from '../classes.baseformatter.js';
2
- import type { IPlannedChange } from '../interfaces.format.js';
3
- import * as plugins from '../mod.plugins.js';
4
- import { logger, logVerbose } from '../../gitzone.logging.js';
5
-
6
- /**
7
- * Migrates npmextra.json from old namespace keys to new package-scoped keys
8
- */
9
- const migrateNamespaceKeys = (npmextraJson: any): boolean => {
10
- let migrated = false;
11
- const migrations = [
12
- { oldKey: 'gitzone', newKey: '@git.zone/cli' },
13
- { oldKey: 'tsdoc', newKey: '@git.zone/tsdoc' },
14
- { oldKey: 'npmdocker', newKey: '@git.zone/tsdocker' },
15
- { oldKey: 'npmci', newKey: '@ship.zone/szci' },
16
- { oldKey: 'szci', newKey: '@ship.zone/szci' },
17
- ];
18
- for (const { oldKey, newKey } of migrations) {
19
- if (npmextraJson[oldKey]) {
20
- if (!npmextraJson[newKey]) {
21
- // New key doesn't exist - simple rename
22
- npmextraJson[newKey] = npmextraJson[oldKey];
23
- } else {
24
- // New key exists - merge old into new (old values don't overwrite new)
25
- npmextraJson[newKey] = {
26
- ...npmextraJson[oldKey],
27
- ...npmextraJson[newKey],
28
- };
29
- }
30
- delete npmextraJson[oldKey];
31
- migrated = true;
32
- }
33
- }
34
- return migrated;
35
- };
36
-
37
- /**
38
- * Migrates npmAccessLevel from @ship.zone/szci to @git.zone/cli.release.accessLevel
39
- */
40
- const migrateAccessLevel = (npmextraJson: any): boolean => {
41
- const szciConfig = npmextraJson['@ship.zone/szci'];
42
-
43
- if (!szciConfig?.npmAccessLevel) {
44
- return false;
45
- }
46
-
47
- const gitzoneConfig = npmextraJson['@git.zone/cli'] || {};
48
- if (gitzoneConfig?.release?.accessLevel) {
49
- delete szciConfig.npmAccessLevel;
50
- return true;
51
- }
52
-
53
- if (!npmextraJson['@git.zone/cli']) {
54
- npmextraJson['@git.zone/cli'] = {};
55
- }
56
- if (!npmextraJson['@git.zone/cli'].release) {
57
- npmextraJson['@git.zone/cli'].release = {};
58
- }
59
-
60
- npmextraJson['@git.zone/cli'].release.accessLevel = szciConfig.npmAccessLevel;
61
- delete szciConfig.npmAccessLevel;
62
-
63
- return true;
64
- };
65
-
66
- export class NpmextraFormatter extends BaseFormatter {
67
- get name(): string {
68
- return 'npmextra';
69
- }
70
-
71
- async analyze(): Promise<IPlannedChange[]> {
72
- const changes: IPlannedChange[] = [];
73
- const npmextraPath = 'npmextra.json';
74
-
75
- // Check if file exists
76
- const exists = await plugins.smartfs.file(npmextraPath).exists();
77
- if (!exists) {
78
- logVerbose('npmextra.json does not exist, skipping');
79
- return changes;
80
- }
81
-
82
- // Read current content
83
- const currentContent = (await plugins.smartfs
84
- .file(npmextraPath)
85
- .encoding('utf8')
86
- .read()) as string;
87
-
88
- // Parse and compute new content
89
- const npmextraJson = JSON.parse(currentContent);
90
-
91
- // Apply migrations (these are automatic, non-interactive)
92
- migrateNamespaceKeys(npmextraJson);
93
- migrateAccessLevel(npmextraJson);
94
-
95
- // Ensure namespaces exist
96
- if (!npmextraJson['@git.zone/cli']) {
97
- npmextraJson['@git.zone/cli'] = {};
98
- }
99
- if (!npmextraJson['@ship.zone/szci']) {
100
- npmextraJson['@ship.zone/szci'] = {};
101
- }
102
-
103
- const newContent = JSON.stringify(npmextraJson, null, 2);
104
-
105
- // Only add change if content differs
106
- if (newContent !== currentContent) {
107
- changes.push({
108
- type: 'modify',
109
- path: npmextraPath,
110
- module: this.name,
111
- description: 'Migrate and format npmextra.json',
112
- content: newContent,
113
- });
114
- }
115
-
116
- return changes;
117
- }
118
-
119
- async applyChange(change: IPlannedChange): Promise<void> {
120
- if (change.type !== 'modify' || !change.content) return;
121
-
122
- // Parse the content to check for missing required fields
123
- const npmextraJson = JSON.parse(change.content);
124
-
125
- // Check for missing required module information
126
- const expectedRepoInformation: string[] = [
127
- 'projectType',
128
- 'module.githost',
129
- 'module.gitscope',
130
- 'module.gitrepo',
131
- 'module.description',
132
- 'module.npmPackagename',
133
- 'module.license',
134
- ];
135
-
136
- const interactInstance = new plugins.smartinteract.SmartInteract();
137
- for (const expectedRepoInformationItem of expectedRepoInformation) {
138
- if (
139
- !plugins.smartobject.smartGet(
140
- npmextraJson['@git.zone/cli'],
141
- expectedRepoInformationItem,
142
- )
143
- ) {
144
- interactInstance.addQuestions([
145
- {
146
- message: `What is the value of ${expectedRepoInformationItem}`,
147
- name: expectedRepoInformationItem,
148
- type: 'input',
149
- default: 'undefined variable',
150
- },
151
- ]);
152
- }
153
- }
154
-
155
- const answerbucket = await interactInstance.runQueue();
156
- for (const expectedRepoInformationItem of expectedRepoInformation) {
157
- const cliProvidedValue = answerbucket.getAnswerFor(
158
- expectedRepoInformationItem,
159
- );
160
- if (cliProvidedValue) {
161
- plugins.smartobject.smartAdd(
162
- npmextraJson['@git.zone/cli'],
163
- expectedRepoInformationItem,
164
- cliProvidedValue,
165
- );
166
- }
167
- }
168
-
169
- // Write the final content
170
- const finalContent = JSON.stringify(npmextraJson, null, 2);
171
- await this.modifyFile(change.path, finalContent);
172
- logger.log('info', 'Updated npmextra.json');
173
- }
174
- }
File without changes