@pikku/cli 0.9.11 → 0.9.12
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/CHANGELOG.md +6 -0
- package/dist/src/utils.js +16 -5
- package/package.json +1 -1
- package/src/utils.ts +16 -5
package/CHANGELOG.md
CHANGED
package/dist/src/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { relative, dirname, resolve } from 'path';
|
|
2
|
-
import { mkdir, writeFile } from 'fs/promises';
|
|
2
|
+
import { mkdir, readFile, writeFile } from 'fs/promises';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
5
|
import { readFileSync } from 'fs';
|
|
@@ -165,10 +165,21 @@ export const writeFileInDir = async (logger, path, content, { ignoreModifyCommen
|
|
|
165
165
|
else {
|
|
166
166
|
content = `${ignoreModifyComment ? '' : DO_NOT_MODIFY_COMMENT}${content}`;
|
|
167
167
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
168
|
+
// Try to read existing file content
|
|
169
|
+
let existingContent;
|
|
170
|
+
try {
|
|
171
|
+
existingContent = await readFile(path, 'utf-8');
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
// File doesn't exist, so we need to write it
|
|
175
|
+
}
|
|
176
|
+
// Only write if content has changed or file doesn't exist
|
|
177
|
+
if (existingContent !== content) {
|
|
178
|
+
await mkdir(dirname(path), { recursive: true });
|
|
179
|
+
await writeFile(path, content, 'utf-8');
|
|
180
|
+
if (logWrite) {
|
|
181
|
+
logger.success(`✓ File written to ${path}`);
|
|
182
|
+
}
|
|
172
183
|
}
|
|
173
184
|
};
|
|
174
185
|
export const logCommandInfoAndTime = async (logger, commandStart, commandEnd, [skipCondition, skipMessage = 'none found'], callback) => {
|
package/package.json
CHANGED
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { relative, dirname, resolve } from 'path'
|
|
2
2
|
import { PathToNameAndType, InspectorState, TypesMap } from '@pikku/inspector'
|
|
3
|
-
import { mkdir, writeFile } from 'fs/promises'
|
|
3
|
+
import { mkdir, readFile, writeFile } from 'fs/promises'
|
|
4
4
|
import chalk from 'chalk'
|
|
5
5
|
import { fileURLToPath } from 'url'
|
|
6
6
|
import { readFileSync } from 'fs'
|
|
@@ -301,11 +301,22 @@ export const writeFileInDir = async (
|
|
|
301
301
|
content = `${ignoreModifyComment ? '' : DO_NOT_MODIFY_COMMENT}${content}`
|
|
302
302
|
}
|
|
303
303
|
|
|
304
|
-
|
|
305
|
-
|
|
304
|
+
// Try to read existing file content
|
|
305
|
+
let existingContent: string | undefined
|
|
306
|
+
try {
|
|
307
|
+
existingContent = await readFile(path, 'utf-8')
|
|
308
|
+
} catch (error) {
|
|
309
|
+
// File doesn't exist, so we need to write it
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Only write if content has changed or file doesn't exist
|
|
313
|
+
if (existingContent !== content) {
|
|
314
|
+
await mkdir(dirname(path), { recursive: true })
|
|
315
|
+
await writeFile(path, content, 'utf-8')
|
|
306
316
|
|
|
307
|
-
|
|
308
|
-
|
|
317
|
+
if (logWrite) {
|
|
318
|
+
logger.success(`✓ File written to ${path}`)
|
|
319
|
+
}
|
|
309
320
|
}
|
|
310
321
|
}
|
|
311
322
|
|