Skip to content

Commit f40a62f

Browse files
committed
Project update. [p][robotic]
1 parent d91bec8 commit f40a62f

File tree

7 files changed

+216
-290
lines changed

7 files changed

+216
-290
lines changed

dev/.files/bin/includes/utilities.mjs

+10-49
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
/* eslint-env es2021, node */
99

1010
import _ from 'lodash';
11-
import deeps from 'deeps';
1211

1312
import os from 'node:os';
1413
import fs from 'node:fs';
@@ -61,27 +60,6 @@ const npmjsConfigVersion = '1.0.2'; // Bump when config changes in routines belo
6160

6261
const c10nLogo = path.resolve(__dirname, '../../assets/brands/c10n/logo.png');
6362

64-
$obj.mc.addOperation('$default', (current, defaults) => {
65-
const paths = Object.keys(defaults);
66-
67-
for (const path of paths) {
68-
if (undefined === deeps.get(current, path, '.')) {
69-
deeps.set(current, path, defaults[path], true, '.');
70-
}
71-
}
72-
return paths.length > 0;
73-
});
74-
$obj.mc.addOperation('$ꓺdefault', (current, defaults) => {
75-
const paths = Object.keys(defaults);
76-
77-
for (const path of paths) {
78-
if (undefined === deeps.get(current, path, 'ꓺ')) {
79-
deeps.set(current, path, defaults[path], true, 'ꓺ');
80-
}
81-
}
82-
return paths.length > 0;
83-
});
84-
8563
/**
8664
* Utilities.
8765
*/
@@ -182,53 +160,36 @@ export default class u {
182160
}
183161
}
184162

185-
static async updatePkg(propsOrPath, value = undefined, delimiter = '.') {
163+
static async updatePkg(propsOrPath = {}, value = undefined, delimiter = '.') {
186164
const pkg = await u.pkg(); // Parses current `./package.json` file.
187165

188166
if (typeof propsOrPath === 'string') {
189167
const path = propsOrPath; // String path.
190-
deeps.set(pkg, path, value, true, delimiter);
168+
$obj.mc.u.set(pkg, path, value, false, delimiter);
191169
//
192170
} else if (_.isPlainObject(propsOrPath)) {
193171
const props = propsOrPath; // Object props.
194172
$obj.mc.patch(pkg, props); // Potentially declarative ops.
195173
} else {
196174
throw new Error('u.updatePkg: Invalid arguments.');
197175
}
198-
await fsp.writeFile(pkgFile, JSON.stringify(pkg, null, 4));
199-
await u.prettifyPkg(); // Sorts and runs prettier.
200-
}
201-
202-
static async prettifyPkg() {
203-
const pkg = {}; // Sorted `./package.json`; i.e., using insertion order.
204-
const curPkg = await u.pkg(); // Parses current `./package.json` file.
205-
206176
const updatesFile = path.resolve(projDir, './dev/.files/bin/updater/data/package.json/updates.json');
207-
const sortOrderFile = path.resolve(projDir, './dev/.files/bin/updater/data/package.json/sort-order.json');
208-
209177
const updates = JSON.parse((await fsp.readFile(updatesFile)).toString());
210-
const sortOrder = JSON.parse((await fsp.readFile(sortOrderFile)).toString());
211178

212179
if (!_.isPlainObject(updates)) {
213-
throw new Error('u.prettifyPkg: Unable to parse `' + updatesFile + '`.');
214-
}
215-
if (!Array.isArray(sortOrder)) {
216-
throw new Error('u.prettifyPkg: Unable to parse `' + sortOrderFile + '`.');
180+
throw new Error('u.updatePkg: Unable to parse `' + updatesFile + '`.');
217181
}
218182
if (await u.isPkgRepo('clevercanyon/skeleton-dev-deps')) {
219183
if (updates.$ꓺdefault?.['devDependenciesꓺ@clevercanyon/skeleton-dev-deps']) {
220184
delete updates.$ꓺdefault['devDependenciesꓺ@clevercanyon/skeleton-dev-deps'];
221185
}
186+
if (Array.isArray(updates.$ꓺunset)) {
187+
updates.$ꓺunset.push('devDependenciesꓺ@clevercanyon/skeleton-dev-deps');
188+
} else {
189+
updates.$ꓺunset = ['devDependenciesꓺ@clevercanyon/skeleton-dev-deps'];
190+
}
222191
}
223-
$obj.mc.patch(curPkg, updates); // Potentially declarative ops.
224-
225-
for (const path of sortOrder) {
226-
const value = deeps.get(curPkg, path, 'ꓺ');
227-
if (undefined !== value) deeps.set(pkg, path, value, true, 'ꓺ');
228-
}
229-
for (const [path, value] of Object.entries(deeps.flatten(curPkg, 'ꓺ'))) {
230-
if (undefined === deeps.get(pkg, path, 'ꓺ')) deeps.set(pkg, path, value, true, 'ꓺ');
231-
}
192+
$obj.mc.patch(pkg, updates); // Potentially declarative ops.
232193
const pkgPrettierCfg = { ...(await prettier.resolveConfig(pkgFile)), parser: 'json' };
233194
await fsp.writeFile(pkgFile, prettier.format(JSON.stringify(pkg, null, 4), pkgPrettierCfg));
234195
}
@@ -1092,7 +1053,7 @@ export default class u {
10921053

10931054
static async npmUpdate() {
10941055
await u.spawn('npm', ['update', '--save'], { stdio: 'inherit' });
1095-
await u.prettifyPkg(); // To our standards.
1056+
await u.updatePkg(); // To our standards.
10961057
}
10971058

10981059
static async npmPublish(opts = { dryRun: false }) {

dev/.files/bin/updater/data/package.json/sort-order.json

-57
This file was deleted.

dev/.files/bin/updater/data/package.json/updates.json

+60-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"configꓺc10nꓺ&ꓺgithubꓺenvsVersion": "",
6060
"configꓺc10nꓺ&ꓺnpmjsꓺconfigVersions": ""
6161
},
62-
"$set": {
62+
"$ꓺset": {
6363
"funding": "https://github.com/sponsors/clevercanyon",
6464
"workspaces": [],
6565

@@ -70,5 +70,63 @@
7070
"npm": "^8.19.3 || ^9.2.0"
7171
}
7272
},
73-
"$unset": ["typings", "scripts"]
73+
"$ꓺunset": ["typings", "scripts"],
74+
75+
"$ꓺpropSortOrder": [
76+
"private",
77+
"publishConfigꓺaccess",
78+
79+
"version",
80+
"license",
81+
"name",
82+
"description",
83+
"repository",
84+
"homepage",
85+
"bugs",
86+
"funding",
87+
"keywords",
88+
89+
"author",
90+
"contributors",
91+
92+
"type",
93+
"files",
94+
"bin",
95+
"imports",
96+
"exports",
97+
"sideEffects",
98+
"module",
99+
"main",
100+
"browser",
101+
"unpkg",
102+
"types",
103+
"typesVersions",
104+
105+
"dependencies",
106+
"peerDependencies",
107+
"peerDependenciesMeta",
108+
"optionalDependencies",
109+
"bundleDependencies",
110+
"devDependencies",
111+
112+
"overrides",
113+
"workspaces",
114+
115+
"cpu",
116+
"os",
117+
"enginesꓺnode",
118+
"enginesꓺnpm",
119+
120+
"configꓺc10nꓺ&ꓺdotfilesꓺlock",
121+
122+
"configꓺc10nꓺ&ꓺbuildꓺappType",
123+
"configꓺc10nꓺ&ꓺbuildꓺtargetEnv",
124+
125+
"configꓺc10nꓺ&ꓺgithubꓺteams",
126+
"configꓺc10nꓺ&ꓺgithubꓺlabels",
127+
"configꓺc10nꓺ&ꓺgithubꓺconfigVersion",
128+
"configꓺc10nꓺ&ꓺgithubꓺenvsVersion",
129+
130+
"configꓺc10nꓺ&ꓺnpmjsꓺconfigVersions"
131+
]
74132
}

dev/.files/bin/updater/index.mjs

+5-41
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { dirname } from 'desm';
1515
import fsp from 'node:fs/promises';
1616

1717
import chalk from 'chalk';
18-
import deeps from 'deeps';
1918
import prettier from 'prettier';
2019

2120
import { $str, $obj } from '@clevercanyon/utilities';
@@ -24,27 +23,6 @@ import { $cmd } from '@clevercanyon/utilities.node';
2423

2524
const { log } = console; // Shorter reference.
2625

27-
$obj.mc.addOperation('$default', (current, defaults) => {
28-
const paths = Object.keys(defaults);
29-
30-
for (const path of paths) {
31-
if (undefined === deeps.get(current, path, '.')) {
32-
deeps.set(current, path, defaults[path], true, '.');
33-
}
34-
}
35-
return paths.length > 0;
36-
});
37-
$obj.mc.addOperation('$ꓺdefault', (current, defaults) => {
38-
const paths = Object.keys(defaults);
39-
40-
for (const path of paths) {
41-
if (undefined === deeps.get(current, path, 'ꓺ')) {
42-
deeps.set(current, path, defaults[path], true, 'ꓺ');
43-
}
44-
}
45-
return paths.length > 0;
46-
});
47-
4826
export default async ({ projDir }) => {
4927
/**
5028
* Initializes vars.
@@ -196,7 +174,6 @@ export default async ({ projDir }) => {
196174
}
197175
let json = JSON.parse((await fsp.readFile(path.resolve(projDir, relPath))).toString());
198176
const jsonUpdatesFile = path.resolve(skeletonDir, './dev/.files/bin/updater/data', relPath, './updates.json');
199-
const jsonSortOrderFile = path.resolve(skeletonDir, './dev/.files/bin/updater/data', relPath, './sort-order.json');
200177

201178
if (!_.isPlainObject(json)) {
202179
throw new Error('updater: Unable to parse `' + relPath + '`.');
@@ -211,29 +188,16 @@ export default async ({ projDir }) => {
211188
if (jsonUpdates.$ꓺdefault?.['devDependenciesꓺ@clevercanyon/skeleton-dev-deps']) {
212189
delete jsonUpdates.$ꓺdefault['devDependenciesꓺ@clevercanyon/skeleton-dev-deps'];
213190
}
191+
if (Array.isArray(jsonUpdates.$ꓺunset)) {
192+
jsonUpdates.$ꓺunset.push('devDependenciesꓺ@clevercanyon/skeleton-dev-deps');
193+
} else {
194+
jsonUpdates.$ꓺunset = ['devDependenciesꓺ@clevercanyon/skeleton-dev-deps'];
195+
}
214196
}
215197
$obj.mc.patch(json, jsonUpdates); // Potentially declarative ops.
216198
const prettierCfg = { ...(await prettier.resolveConfig(path.resolve(projDir, relPath))), parser: 'json' };
217199
await fsp.writeFile(path.resolve(projDir, relPath), prettier.format(JSON.stringify(json, null, 4), prettierCfg));
218200
}
219-
if (fs.existsSync(jsonSortOrderFile)) {
220-
const origJSON = _.cloneDeep(json); // Deep clone.
221-
json = {}; // Sorted JSON file; i.e., using insertion order.
222-
const jsonSortOrder = JSON.parse((await fsp.readFile(jsonSortOrderFile)).toString());
223-
224-
if (!Array.isArray(jsonSortOrder)) {
225-
throw new Error('updater: Unable to parse `' + jsonSortOrderFile + '`.');
226-
}
227-
for (const path of jsonSortOrder) {
228-
const value = deeps.get(origJSON, path, 'ꓺ');
229-
if (undefined !== value) deeps.set(json, path, value, true, 'ꓺ');
230-
}
231-
for (const [path, value] of Object.entries(deeps.flatten(origJSON, 'ꓺ'))) {
232-
if (undefined === deeps.get(json, path, 'ꓺ')) deeps.set(json, path, value, true, 'ꓺ');
233-
}
234-
const prettierCfg = { ...(await prettier.resolveConfig(path.resolve(projDir, relPath))), parser: 'json' };
235-
await fsp.writeFile(path.resolve(projDir, relPath), prettier.format(JSON.stringify(json, null, 4), prettierCfg));
236-
}
237201
}
238202

239203
/**

dev/.files/madrun/includes/events.mjs

+10-10
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ export default {
6868
homepage: 'https://github.com/' + $url.encode(parentDirOwner) + '/' + $url.encode(dirBasename) + '#readme',
6969
bugs: 'https://github.com/' + $url.encode(parentDirOwner) + '/' + $url.encode(dirBasename) + '/issues',
7070

71-
$unset: /* Effectively resets these to default values. */ [
71+
$ꓺunset: /* Effectively resets these to default values. */ [
7272
'private', //
73-
'publishConfig.access',
73+
'publishConfigꓺaccess',
7474

7575
'version',
7676
'license',
@@ -81,16 +81,16 @@ export default {
8181
'author',
8282
'contributors',
8383

84-
'config.c10n.&.github.teams',
85-
'config.c10n.&.github.labels',
86-
'config.c10n.&.github.configVersion',
87-
'config.c10n.&.github.envsVersion',
84+
'configꓺc10nꓺ&ꓺgithubꓺteams',
85+
'configꓺc10nꓺ&ꓺgithubꓺlabels',
86+
'configꓺc10nꓺ&ꓺgithubꓺconfigVersion',
87+
'configꓺc10nꓺ&ꓺgithubꓺenvsVersion',
8888

89-
'config.c10n.&.npmjs.teams',
90-
'config.c10n.&.npmjs.configVersions',
89+
'configꓺc10nꓺ&ꓺnpmjsꓺteams',
90+
'configꓺc10nꓺ&ꓺnpmjsꓺconfigVersions',
9191
],
92-
...(args.pkg ? { $set: { private: false } } : {}),
93-
...(args.pkg && args.public ? { $set: { 'publishConfig.access': 'public' } } : {}),
92+
...(args.pkg ? { $ꓺset: { private: false } } : {}),
93+
...(args.pkg && args.public ? { $ꓺset: { publishConfigꓺaccess: 'public' } } : {}),
9494
});
9595

9696
/**

0 commit comments

Comments
 (0)