@knapsack/update 4.78.9 → 4.78.10--canary.5706.50eecc2.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.
- package/dist/updates/4.0.0/demos.js +2 -2
- package/dist/updates/4.0.0/demos.js.map +1 -1
- package/package.json +14 -14
- package/.turbo/turbo-build.log +0 -4
- package/.turbo/turbo-lint.log +0 -10
- package/.turbo/turbo-test.log +0 -15
- package/src/cli.ts +0 -149
- package/src/pkg-version-updater.ts +0 -83
- package/src/types.ts +0 -13
- package/src/updates/4.0.0/demos.ts +0 -169
- package/src/updates/4.0.0/index.ts +0 -2
- package/src/updates/4.0.0/markdown.ts +0 -166
- package/src/updates/4.0.0/markdown.utils.ts +0 -40
- package/src/updates/4.0.0/placeholder.ts +0 -14
- package/src/updates/4.28.0-db-to-files.ts +0 -22
- package/src/updates/index.ts +0 -8
- package/src/utils/exec.ts +0 -12
- package/src/utils/oldDb.ts +0 -35
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Just like blocks, demos need to be migrated to the new format with db.yml
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { isDemoWithData, } from '@knapsack/types';
|
|
7
7
|
import { makeShortId } from '@knapsack/utils';
|
|
8
8
|
import { readKsPatternConfigs, writeKsPatternConfigs, } from '@knapsack/ks-file-utils';
|
|
9
9
|
import { readDb, writeDb } from '../../utils/oldDb.js';
|
|
@@ -69,7 +69,7 @@ export const update400_demos = {
|
|
|
69
69
|
});
|
|
70
70
|
// Now update dem slotz (on demos). Rely on referential link to make these changes deep
|
|
71
71
|
Object.values(db.demos.byId).forEach((demo) => {
|
|
72
|
-
if (!
|
|
72
|
+
if (!isDemoWithData(demo))
|
|
73
73
|
return;
|
|
74
74
|
demo.data.slots &&
|
|
75
75
|
Object.values(demo.data.slots).forEach((slots) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"demos.js","sourceRoot":"","sources":["../../../src/updates/4.0.0/demos.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"demos.js","sourceRoot":"","sources":["../../../src/updates/4.0.0/demos.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAIL,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EACL,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEvD,SAAS,sBAAsB,CAC7B,KAAkB;IAElB,OAAO,CACL,KAAK,CAAC,SAAS,KAAK,wBAAwB;QAC5C,kGAAkG;QAClG,KAAK,CAAC,SAAS,KAAK,wBAAwB,CAC7C,CAAC;AACJ,CAAC;AAOD,MAAM,CAAC,MAAM,eAAe,GAAW;IACrC,SAAS,EAAE,CAAC,EAAE,gBAAgB,EAAE,EAAE,EAAE,CAAC,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC;IACtE,KAAK,EAAE,iBAAiB;IACxB,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;QAC5B,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;QACjC,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACvC,oBAAoB,CAAC;gBACnB,OAAO;aACR,CAAC;YACF,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;SACpB,CAAC,CAAC;QAEH,EAAE,CAAC,KAAK,CAAC,IAAI,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;QACpC,EAAE,CAAC,MAAM,CAAC,IAAI,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;QAEtC,MAAM,aAAa,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|
|
6
6
|
"knapsack-update": "./cli.js"
|
|
7
7
|
},
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
"test": "ava"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@knapsack/app": "4.78.
|
|
22
|
-
"@knapsack/creator-utils": "4.78.
|
|
23
|
-
"@knapsack/design-token-utils": "4.78.
|
|
24
|
-
"@knapsack/file-utils": "4.78.
|
|
25
|
-
"@knapsack/ks-file-utils": "4.78.
|
|
26
|
-
"@knapsack/tiptap-utils": "4.78.
|
|
27
|
-
"@knapsack/utils": "4.78.
|
|
21
|
+
"@knapsack/app": "4.78.10--canary.5706.50eecc2.0",
|
|
22
|
+
"@knapsack/creator-utils": "4.78.10--canary.5706.50eecc2.0",
|
|
23
|
+
"@knapsack/design-token-utils": "4.78.10--canary.5706.50eecc2.0",
|
|
24
|
+
"@knapsack/file-utils": "4.78.10--canary.5706.50eecc2.0",
|
|
25
|
+
"@knapsack/ks-file-utils": "4.78.10--canary.5706.50eecc2.0",
|
|
26
|
+
"@knapsack/tiptap-utils": "4.78.10--canary.5706.50eecc2.0",
|
|
27
|
+
"@knapsack/utils": "4.78.10--canary.5706.50eecc2.0",
|
|
28
28
|
"cheerio": "^1.0.0",
|
|
29
29
|
"isomorphic-dompurify": "^1.13.0",
|
|
30
30
|
"marked": "^6.0.0",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"yargs": "^17.7.2"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@knapsack/eslint-config-starter": "4.78.
|
|
36
|
-
"@knapsack/prettier-config": "4.78.
|
|
37
|
-
"@knapsack/test-ava": "4.78.
|
|
38
|
-
"@knapsack/types": "4.78.
|
|
39
|
-
"@knapsack/typescript-config-starter": "4.78.
|
|
35
|
+
"@knapsack/eslint-config-starter": "4.78.10--canary.5706.50eecc2.0",
|
|
36
|
+
"@knapsack/prettier-config": "4.78.10--canary.5706.50eecc2.0",
|
|
37
|
+
"@knapsack/test-ava": "4.78.10--canary.5706.50eecc2.0",
|
|
38
|
+
"@knapsack/types": "4.78.10--canary.5706.50eecc2.0",
|
|
39
|
+
"@knapsack/typescript-config-starter": "4.78.10--canary.5706.50eecc2.0",
|
|
40
40
|
"@types/node": "^20.17.24",
|
|
41
41
|
"@types/prompts": "^2.4.9",
|
|
42
42
|
"@types/yargs": "^17.0.33",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"directory": "apps/client/update",
|
|
54
54
|
"type": "git"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "50eecc28504f145b0ef640b2b05ea735f6101ea1"
|
|
57
57
|
}
|
package/.turbo/turbo-build.log
DELETED
package/.turbo/turbo-lint.log
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @knapsack/update@4.78.8 lint /home/runner/work/app-monorepo/app-monorepo/apps/client/update
|
|
3
|
-
> eslint ./
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/home/runner/work/app-monorepo/app-monorepo/apps/client/update/src/updates/4.0.0/placeholder.ts
|
|
7
|
-
11:21 warning 'config' is defined but never used. Allowed unused args must match /^_/u unused-imports/no-unused-vars
|
|
8
|
-
|
|
9
|
-
✖ 1 problem (0 errors, 1 warning)
|
|
10
|
-
|
package/.turbo/turbo-test.log
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @knapsack/update@4.78.8 test /home/runner/work/app-monorepo/app-monorepo/apps/client/update
|
|
3
|
-
> ava
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
- [todo] update › placeholder
|
|
7
|
-
marked(): mangle parameter is enabled by default, but is deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-mangle, or disable by setting `{mangle: false}`.
|
|
8
|
-
marked(): headerIds and headerPrefix parameters enabled by default, but are deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-gfm-heading-id, or disable by setting `{headerIds: false}`.
|
|
9
|
-
marked(): mangle parameter is enabled by default, but is deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-mangle, or disable by setting `{mangle: false}`.
|
|
10
|
-
marked(): headerIds and headerPrefix parameters enabled by default, but are deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-gfm-heading-id, or disable by setting `{headerIds: false}`.
|
|
11
|
-
✔ updates › 4.0.0 › markdown.utils › should throw on links that wrap images
|
|
12
|
-
─
|
|
13
|
-
|
|
14
|
-
1 test passed
|
|
15
|
-
1 test todo
|
package/src/cli.ts
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { findConfigAndBootstrap } from '@knapsack/app';
|
|
2
|
-
import { timer } from '@knapsack/utils';
|
|
3
|
-
import {
|
|
4
|
-
findUpPkgJson,
|
|
5
|
-
getPackageManager,
|
|
6
|
-
resolvePath,
|
|
7
|
-
} from '@knapsack/file-utils';
|
|
8
|
-
import yargs from 'yargs';
|
|
9
|
-
import { hideBin } from 'yargs/helpers';
|
|
10
|
-
import { EOL } from 'node:os';
|
|
11
|
-
import { dirname } from 'node:path';
|
|
12
|
-
import { fileURLToPath } from 'node:url';
|
|
13
|
-
import { updates } from './updates/index.js';
|
|
14
|
-
import { updatePkgVersions } from './pkg-version-updater.js';
|
|
15
|
-
import { migrateMdBlocks } from './updates/4.0.0/index.js';
|
|
16
|
-
|
|
17
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
18
|
-
|
|
19
|
-
const { run, verbose } = await yargs(hideBin(process.argv))
|
|
20
|
-
.option('run', {
|
|
21
|
-
description: 'Run a specific update',
|
|
22
|
-
choices: ['migrate-md-blocks'] as const,
|
|
23
|
-
})
|
|
24
|
-
.option('verbose', {
|
|
25
|
-
description: 'Show verbose output',
|
|
26
|
-
type: 'boolean',
|
|
27
|
-
default: false,
|
|
28
|
-
})
|
|
29
|
-
.strictOptions().argv;
|
|
30
|
-
|
|
31
|
-
// Informs other @knapsack packages that we are running an update. Search for
|
|
32
|
-
// `KS_UPDATE_CLI_IS_RUNNING` in the monorepo for usages.
|
|
33
|
-
process.env.KS_UPDATE_CLI_IS_RUNNING = 'yes';
|
|
34
|
-
|
|
35
|
-
const pkgManager = getPackageManager();
|
|
36
|
-
let updateCmd = 'npm/yarn/pnpm install';
|
|
37
|
-
if (pkgManager) {
|
|
38
|
-
updateCmd = `${pkgManager} install`;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const {
|
|
42
|
-
pkg: {
|
|
43
|
-
/**
|
|
44
|
-
* This is the version of *this* package, therefore it's the version to which all other `@knapsack/*` packages will be updated.
|
|
45
|
-
*/
|
|
46
|
-
version,
|
|
47
|
-
},
|
|
48
|
-
} = findUpPkgJson(__dirname);
|
|
49
|
-
|
|
50
|
-
const { absolutePath, exists } = await resolvePath({
|
|
51
|
-
path: '@knapsack/app/package.json',
|
|
52
|
-
resolveFromDir: process.cwd(),
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
if (!exists) {
|
|
56
|
-
console.log(
|
|
57
|
-
`Could not find "@knapsack/app" NPM package from this directory. Perhaps install dependencies with "${updateCmd}" first? `,
|
|
58
|
-
);
|
|
59
|
-
process.exit(1);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const {
|
|
63
|
-
pkg: {
|
|
64
|
-
/** This is the version of **their** package */
|
|
65
|
-
version: installedVersion,
|
|
66
|
-
},
|
|
67
|
-
} = findUpPkgJson(absolutePath);
|
|
68
|
-
|
|
69
|
-
const ksBrain = findConfigAndBootstrap();
|
|
70
|
-
const { config } = ksBrain;
|
|
71
|
-
|
|
72
|
-
async function runUpdates() {
|
|
73
|
-
if (!version) {
|
|
74
|
-
throw new Error('No current version found');
|
|
75
|
-
}
|
|
76
|
-
if (!installedVersion) {
|
|
77
|
-
throw new Error('No installed version found');
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const stopAll = timer();
|
|
81
|
-
const times: { title: string; time: string }[] = [];
|
|
82
|
-
for (const update of updates) {
|
|
83
|
-
const shouldRun = await update.shouldRun({ config, installedVersion });
|
|
84
|
-
if (!shouldRun) {
|
|
85
|
-
// skipping this update b/c the `installedVersion` is greater than the update version
|
|
86
|
-
continue; // stops current loop and goes to next in `for..of`
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const stop = timer();
|
|
90
|
-
console.log(`Running update: ${update.title}...`);
|
|
91
|
-
|
|
92
|
-
await update.updater({ config, installedVersion });
|
|
93
|
-
const time = `${stop() / 1000}s`;
|
|
94
|
-
times.push({ title: update.title, time });
|
|
95
|
-
console.log(`${update.title} update complete in ${time}.${EOL}${EOL}`);
|
|
96
|
-
}
|
|
97
|
-
const used = process.memoryUsage().heapUsed / 1024 / 1024;
|
|
98
|
-
const mbUsed = Math.round(used * 100) / 100;
|
|
99
|
-
const timeForAll = `${stopAll() / 1000}s`;
|
|
100
|
-
console.log('---');
|
|
101
|
-
times.forEach(({ title, time }) => {
|
|
102
|
-
console.log(`${title} took ${time}`);
|
|
103
|
-
});
|
|
104
|
-
console.log(
|
|
105
|
-
`All updates complete in ${timeForAll} using ${mbUsed}MB of memory`,
|
|
106
|
-
);
|
|
107
|
-
console.log('---');
|
|
108
|
-
console.log(`Updating to version ${version}...`);
|
|
109
|
-
await updatePkgVersions({ version });
|
|
110
|
-
|
|
111
|
-
console.log(
|
|
112
|
-
`Updated package versions to ${version}. Please run "${updateCmd}" to update your dependencies.`,
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (!run) {
|
|
117
|
-
try {
|
|
118
|
-
await runUpdates();
|
|
119
|
-
} catch (e) {
|
|
120
|
-
if (verbose) {
|
|
121
|
-
console.log(e);
|
|
122
|
-
} else {
|
|
123
|
-
console.log(e.message);
|
|
124
|
-
}
|
|
125
|
-
process.exit(1);
|
|
126
|
-
}
|
|
127
|
-
} else {
|
|
128
|
-
switch (run) {
|
|
129
|
-
case 'migrate-md-blocks': {
|
|
130
|
-
try {
|
|
131
|
-
await migrateMdBlocks({ config });
|
|
132
|
-
console.log('Migration complete');
|
|
133
|
-
} catch (e) {
|
|
134
|
-
if (verbose) {
|
|
135
|
-
console.log(e);
|
|
136
|
-
} else {
|
|
137
|
-
console.log(e.message);
|
|
138
|
-
}
|
|
139
|
-
process.exit(1);
|
|
140
|
-
}
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
default: {
|
|
144
|
-
const _exhaustiveCheck: never = run;
|
|
145
|
-
console.log(`Unknown value for "--run": "${run}"`);
|
|
146
|
-
process.exit(1);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
findGitRoot,
|
|
3
|
-
globby,
|
|
4
|
-
getPackageJson,
|
|
5
|
-
writeFormattedFile,
|
|
6
|
-
type PackageJson,
|
|
7
|
-
} from '@knapsack/file-utils';
|
|
8
|
-
|
|
9
|
-
export async function updatePkgVersions({ version }: { version: string }) {
|
|
10
|
-
function processDeps<Deps extends PackageJson['dependencies']>(
|
|
11
|
-
deps?: Deps,
|
|
12
|
-
): Deps | undefined {
|
|
13
|
-
// if there isn't `devDependencies` or `dependencies`, return it as-is (undefined) so it's not written
|
|
14
|
-
if (!deps) return deps;
|
|
15
|
-
return Object.entries(deps).reduce((acc, [pkg, pkgVersion]) => {
|
|
16
|
-
if (
|
|
17
|
-
// not our pkg, leave it alone
|
|
18
|
-
!pkg.startsWith('@knapsack/') ||
|
|
19
|
-
// if it's a workspace package, leave it alone since that means we're likely
|
|
20
|
-
// testing running in our monorepo
|
|
21
|
-
pkgVersion?.startsWith('workspace:')
|
|
22
|
-
) {
|
|
23
|
-
return {
|
|
24
|
-
...acc,
|
|
25
|
-
[pkg]: pkgVersion,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// we want to avoid `^` or `~` in the version number if it's a canary
|
|
30
|
-
// i.e. we do not want `^4.0.0--canary.2146.8276318.0` but rather `4.0.0--canary.2146.8276318.0`
|
|
31
|
-
if (version.includes('--canary.')) {
|
|
32
|
-
return {
|
|
33
|
-
...acc,
|
|
34
|
-
[pkg]: version,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
if (pkgVersion?.startsWith('^')) {
|
|
38
|
-
return {
|
|
39
|
-
...acc,
|
|
40
|
-
[pkg]: `^${version}`,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
if (pkgVersion?.startsWith('~')) {
|
|
44
|
-
return {
|
|
45
|
-
...acc,
|
|
46
|
-
[pkg]: `~${version}`,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
...acc,
|
|
51
|
-
[pkg]: version,
|
|
52
|
-
};
|
|
53
|
-
}, {} as Deps);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const gitRoot = findGitRoot(process.cwd());
|
|
57
|
-
if (!gitRoot) {
|
|
58
|
-
throw new Error('No git root found');
|
|
59
|
-
}
|
|
60
|
-
const pkgPaths = await globby('**/package.json', {
|
|
61
|
-
// start from CWD, then go up until we find a git root as our base
|
|
62
|
-
cwd: gitRoot,
|
|
63
|
-
// if it's gitignored, this ignores it
|
|
64
|
-
gitignore: true,
|
|
65
|
-
absolute: true,
|
|
66
|
-
ignore: [
|
|
67
|
-
// respecting `.gitignore` should make next line unnecessary, but being careful
|
|
68
|
-
'**/node_modules/**',
|
|
69
|
-
],
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
await Promise.all(
|
|
73
|
-
pkgPaths.map(async (pkgPath) => {
|
|
74
|
-
const pkg = await getPackageJson(pkgPath);
|
|
75
|
-
pkg.dependencies = processDeps(pkg.dependencies);
|
|
76
|
-
pkg.devDependencies = processDeps(pkg.devDependencies);
|
|
77
|
-
await writeFormattedFile({
|
|
78
|
-
path: pkgPath,
|
|
79
|
-
contents: pkg,
|
|
80
|
-
});
|
|
81
|
-
}),
|
|
82
|
-
);
|
|
83
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type KnapsackConfig } from '@knapsack/app';
|
|
2
|
-
|
|
3
|
-
export type UpdateInfo = {
|
|
4
|
-
config: KnapsackConfig;
|
|
5
|
-
/** SemVer */
|
|
6
|
-
installedVersion: string;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export type Update = {
|
|
10
|
-
shouldRun: (updateInfo: UpdateInfo) => boolean | Promise<boolean>;
|
|
11
|
-
title: string;
|
|
12
|
-
updater: (updateInfo: UpdateInfo) => Promise<void>;
|
|
13
|
-
};
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file
|
|
3
|
-
*
|
|
4
|
-
* Just like blocks, demos need to be migrated to the new format with db.yml
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
KnapsackPatternTemplate,
|
|
9
|
-
Demo,
|
|
10
|
-
isDataDemo,
|
|
11
|
-
BlockConfig,
|
|
12
|
-
} from '@knapsack/types';
|
|
13
|
-
import { makeShortId } from '@knapsack/utils';
|
|
14
|
-
import {
|
|
15
|
-
readKsPatternConfigs,
|
|
16
|
-
writeKsPatternConfigs,
|
|
17
|
-
} from '@knapsack/ks-file-utils';
|
|
18
|
-
|
|
19
|
-
import { Update } from '../../types.js';
|
|
20
|
-
import { readDb, writeDb } from '../../utils/oldDb.js';
|
|
21
|
-
|
|
22
|
-
function isBlockPatternTemplate(
|
|
23
|
-
block: BlockConfig,
|
|
24
|
-
): block is BlockConfig<'pattern-template-block'> {
|
|
25
|
-
return (
|
|
26
|
-
block.blockType === 'pattern-template-block' ||
|
|
27
|
-
// @ts-expect-error this update runs before the `blocks` update - which renames "slice" to "block"
|
|
28
|
-
block.blockType === 'pattern-template-slice'
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
type MigrateTemplate = KnapsackPatternTemplate & {
|
|
33
|
-
demosById?: Record<string, Demo>;
|
|
34
|
-
demos?: KnapsackPatternTemplate['demoIds'];
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const update400_demos: Update = {
|
|
38
|
-
shouldRun: ({ installedVersion }) => installedVersion.startsWith('3.'),
|
|
39
|
-
title: 'Demos migration',
|
|
40
|
-
updater: async ({ config }) => {
|
|
41
|
-
const { data: dataDir } = config;
|
|
42
|
-
const [patterns, db] = await Promise.all([
|
|
43
|
-
readKsPatternConfigs({
|
|
44
|
-
dataDir,
|
|
45
|
-
}),
|
|
46
|
-
readDb({ dataDir }),
|
|
47
|
-
]);
|
|
48
|
-
|
|
49
|
-
db.demos.byId = db.demos.byId || {};
|
|
50
|
-
db.blocks.byId = db.blocks.byId || {};
|
|
51
|
-
|
|
52
|
-
const slotsToUpdate: {
|
|
53
|
-
patternId: string;
|
|
54
|
-
templateId: string;
|
|
55
|
-
demoId: string;
|
|
56
|
-
}[] = [];
|
|
57
|
-
|
|
58
|
-
// Remove demosById from templates, but move data to db.demos.byId
|
|
59
|
-
patterns.forEach((pattern) => {
|
|
60
|
-
const patternId = pattern.id;
|
|
61
|
-
|
|
62
|
-
if (!pattern.templates) return;
|
|
63
|
-
|
|
64
|
-
pattern.templates.forEach((template: MigrateTemplate) => {
|
|
65
|
-
const templateId = template.id;
|
|
66
|
-
// check if we already ran
|
|
67
|
-
if (Array.isArray(template.demoIds)) return;
|
|
68
|
-
// if there are no demos, skip
|
|
69
|
-
if (!template.demosById) return;
|
|
70
|
-
|
|
71
|
-
Object.values(template.demosById).forEach((demo) => {
|
|
72
|
-
// Demos named `main` need to be renamed, as well as all their references
|
|
73
|
-
// within slots. This requires an entire re-scan of patternState.
|
|
74
|
-
if (demo.id === 'main' || demo.id === '') {
|
|
75
|
-
const demoId = makeShortId();
|
|
76
|
-
demo.id = demoId;
|
|
77
|
-
slotsToUpdate.push({
|
|
78
|
-
patternId,
|
|
79
|
-
templateId,
|
|
80
|
-
demoId,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Move demo data to db
|
|
85
|
-
db.demos.byId[demo.id] = demo;
|
|
86
|
-
|
|
87
|
-
if (!template.demos) return;
|
|
88
|
-
|
|
89
|
-
const mainIndex = template.demos.indexOf('main');
|
|
90
|
-
// Replace main with the new id
|
|
91
|
-
if (mainIndex !== -1) {
|
|
92
|
-
template.demos.splice(mainIndex, 1, demo.id);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
delete template.demosById;
|
|
96
|
-
|
|
97
|
-
// Rename demos to demoIds
|
|
98
|
-
template.demoIds = template.demos || [];
|
|
99
|
-
delete template.demos;
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// Now update dem slotz (on demos). Rely on referential link to make these changes deep
|
|
104
|
-
Object.values(db.demos.byId).forEach((demo) => {
|
|
105
|
-
if (!isDataDemo(demo)) return;
|
|
106
|
-
|
|
107
|
-
demo.data.slots &&
|
|
108
|
-
Object.values(demo.data.slots).forEach((slots) => {
|
|
109
|
-
slots.forEach((slot) => {
|
|
110
|
-
if (
|
|
111
|
-
typeof slot === 'object' &&
|
|
112
|
-
'demoId' in slot &&
|
|
113
|
-
slot.demoId === 'main'
|
|
114
|
-
) {
|
|
115
|
-
const slotToUpdate = slotsToUpdate.find((badSlot) => {
|
|
116
|
-
return (
|
|
117
|
-
// @ts-expect-error this code is unused anyway since v3 no longer exists
|
|
118
|
-
badSlot.patternId === slot.patternId &&
|
|
119
|
-
// @ts-expect-error this code is unused anyway since v3 no longer exists
|
|
120
|
-
badSlot.templateId === slot.templateId
|
|
121
|
-
);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// If we can't find the slot that corresponds to this one (which
|
|
125
|
-
// has demoId of 'main') then leave 'main' behind, do not update it,
|
|
126
|
-
// and inform the user.
|
|
127
|
-
if (!slotToUpdate) {
|
|
128
|
-
console.warn(`Could not migrate slot: ${JSON.stringify(slot)}`);
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
slot.demoId = slotToUpdate.demoId;
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
// Now update blocks that use pattern-template-slice or pattern-variations
|
|
139
|
-
Object.values(db.blocks.byId).forEach((block) => {
|
|
140
|
-
if (
|
|
141
|
-
(isBlockPatternTemplate(block) ||
|
|
142
|
-
block.blockType === 'pattern-variations') &&
|
|
143
|
-
block.data.demoId === 'main'
|
|
144
|
-
) {
|
|
145
|
-
const blockToUpdate = slotsToUpdate.find((badSlot) => {
|
|
146
|
-
return (
|
|
147
|
-
badSlot.patternId === block.data.patternId &&
|
|
148
|
-
badSlot.templateId === block.data.templateId
|
|
149
|
-
);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
if (blockToUpdate?.demoId) {
|
|
153
|
-
block.data.demoId = blockToUpdate.demoId;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
await Promise.all([
|
|
159
|
-
writeKsPatternConfigs({
|
|
160
|
-
dataDir,
|
|
161
|
-
patterns,
|
|
162
|
-
}),
|
|
163
|
-
writeDb({
|
|
164
|
-
dataDir,
|
|
165
|
-
db,
|
|
166
|
-
}),
|
|
167
|
-
]);
|
|
168
|
-
},
|
|
169
|
-
};
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file
|
|
3
|
-
*
|
|
4
|
-
* Convert markdown blocks to text-editor blocks. This module does not export an
|
|
5
|
-
* `Update` object because it is not a migration. It is a one-time conversion
|
|
6
|
-
* triggered manually.
|
|
7
|
-
*/
|
|
8
|
-
import { BlockConfig } from '@knapsack/types';
|
|
9
|
-
import { makeShortId } from '@knapsack/utils';
|
|
10
|
-
import {
|
|
11
|
-
readKsPatternConfigs,
|
|
12
|
-
writeKsPatternConfigs,
|
|
13
|
-
readKsPagesConfig,
|
|
14
|
-
writeKsPagesConfig,
|
|
15
|
-
} from '@knapsack/ks-file-utils';
|
|
16
|
-
import type { KnapsackConfig } from '@knapsack/app';
|
|
17
|
-
|
|
18
|
-
import { mdToTipTapJson } from './markdown.utils.js';
|
|
19
|
-
import { readDb, writeDb } from '../../utils/oldDb.js';
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* New block sizes for text-editor don't quite line up with old MD block cols
|
|
23
|
-
*/
|
|
24
|
-
const colBlockSize = (
|
|
25
|
-
col: number,
|
|
26
|
-
): Record<'size' | string, 'small' | 'medium' | 'large' | never> => {
|
|
27
|
-
switch (col) {
|
|
28
|
-
case 1:
|
|
29
|
-
return {};
|
|
30
|
-
case 2:
|
|
31
|
-
return { size: 'medium' };
|
|
32
|
-
case 3:
|
|
33
|
-
return { size: 'small' };
|
|
34
|
-
case 4:
|
|
35
|
-
return { size: 'medium' };
|
|
36
|
-
default:
|
|
37
|
-
return {};
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export async function migrateMdBlocks({ config }: { config: KnapsackConfig }) {
|
|
42
|
-
const { data: dataDir } = config;
|
|
43
|
-
const [patterns, pages, db] = await Promise.all([
|
|
44
|
-
readKsPatternConfigs({
|
|
45
|
-
dataDir,
|
|
46
|
-
}),
|
|
47
|
-
readKsPagesConfig({
|
|
48
|
-
dataDir,
|
|
49
|
-
}),
|
|
50
|
-
readDb({ dataDir }),
|
|
51
|
-
]);
|
|
52
|
-
|
|
53
|
-
const blocks = Object.values(db.blocks.byId).flatMap((block) => {
|
|
54
|
-
try {
|
|
55
|
-
if (block.blockType !== 'markdown-block') return [block];
|
|
56
|
-
|
|
57
|
-
// Markdown blocks can be multi column. New text-editor blocks must be
|
|
58
|
-
// created for each column
|
|
59
|
-
const columns = block.data.columns || 1;
|
|
60
|
-
// Convert single markdown blocks, create multiple blocks from multi-column
|
|
61
|
-
const convertedBlocks: BlockConfig<'text-editor'>[] = [];
|
|
62
|
-
// If new blocks are created from multi, insert into proper order within pages/patterns
|
|
63
|
-
const appendNewBlockIds: string[] = [];
|
|
64
|
-
|
|
65
|
-
// Used below where multiple blocks are created from a single md block and
|
|
66
|
-
// need to be connected back to their page/pattern block
|
|
67
|
-
const originalMdBlockId = block.id;
|
|
68
|
-
|
|
69
|
-
// Only runs once for columns === 1, picks up additional columns as new blocks
|
|
70
|
-
for (let i = 0; i < columns; i++) {
|
|
71
|
-
// Only used for new block creation
|
|
72
|
-
const newBlockId = makeShortId();
|
|
73
|
-
|
|
74
|
-
const txtBlock: BlockConfig<'text-editor'> = {
|
|
75
|
-
// First column block uses original id, others use new id
|
|
76
|
-
id: i === 0 ? originalMdBlockId : newBlockId,
|
|
77
|
-
blockType: 'text-editor',
|
|
78
|
-
data: {
|
|
79
|
-
content: mdToTipTapJson(block.data.md?.[i] || ''),
|
|
80
|
-
},
|
|
81
|
-
...colBlockSize(columns),
|
|
82
|
-
};
|
|
83
|
-
// All blocks get added to the db
|
|
84
|
-
convertedBlocks.push(txtBlock);
|
|
85
|
-
// If we're after column 1, then we're creating new blocks
|
|
86
|
-
i > 0 && appendNewBlockIds.push(newBlockId);
|
|
87
|
-
} // end for loop
|
|
88
|
-
|
|
89
|
-
// Bail if no new blocks created
|
|
90
|
-
if (!appendNewBlockIds.length) return convertedBlocks;
|
|
91
|
-
|
|
92
|
-
// Quick side-effect here to update the customPage/pattern blockIds array
|
|
93
|
-
// with the new blockIds. If there are new blocks created, the new
|
|
94
|
-
// blockIds need to be inserted.
|
|
95
|
-
|
|
96
|
-
// 1. Custom pages
|
|
97
|
-
pages.forEach((page) => {
|
|
98
|
-
const blockIdInPageIndex = page.blockIds?.indexOf(originalMdBlockId);
|
|
99
|
-
if (blockIdInPageIndex > -1) {
|
|
100
|
-
// Right after original blockId, splice in the newly created blockIds
|
|
101
|
-
page.blockIds.splice(blockIdInPageIndex + 1, 0, ...appendNewBlockIds);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// 2. Patterns
|
|
106
|
-
patterns.forEach((pattern) => {
|
|
107
|
-
// 2a. Templates
|
|
108
|
-
pattern.templates?.forEach((template) => {
|
|
109
|
-
const blockIdInTemplateIndex =
|
|
110
|
-
template.blockIds.indexOf(originalMdBlockId);
|
|
111
|
-
if (blockIdInTemplateIndex > -1) {
|
|
112
|
-
// Right after original blockId, splice in the newly created blockIds
|
|
113
|
-
template.blockIds.splice(
|
|
114
|
-
blockIdInTemplateIndex + 1,
|
|
115
|
-
0,
|
|
116
|
-
...appendNewBlockIds,
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
// 2b. Subpages
|
|
121
|
-
pattern.subPages?.forEach((subPage) => {
|
|
122
|
-
const blockIdInSubPageIndex =
|
|
123
|
-
subPage.blockIds.indexOf(originalMdBlockId);
|
|
124
|
-
if (blockIdInSubPageIndex > -1) {
|
|
125
|
-
// Right after original blockId, splice in the newly created blockIds
|
|
126
|
-
subPage.blockIds.splice(
|
|
127
|
-
blockIdInSubPageIndex + 1,
|
|
128
|
-
0,
|
|
129
|
-
...appendNewBlockIds,
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
return convertedBlocks;
|
|
136
|
-
} catch (e) {
|
|
137
|
-
console.log(
|
|
138
|
-
`Block ID "${block.id}" was not converted from Markdown block, leaving as-is.`,
|
|
139
|
-
);
|
|
140
|
-
return [block];
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
// Modifying db, pagesState, and patternsState mutates appClientData due to
|
|
145
|
-
// pass by reference
|
|
146
|
-
db.blocks.byId = Object.fromEntries(
|
|
147
|
-
blocks
|
|
148
|
-
.filter((block) => block !== undefined)
|
|
149
|
-
.map((block) => [block.id, block]),
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
await Promise.all([
|
|
153
|
-
writeKsPagesConfig({
|
|
154
|
-
dataDir,
|
|
155
|
-
pages,
|
|
156
|
-
}),
|
|
157
|
-
writeKsPatternConfigs({
|
|
158
|
-
dataDir,
|
|
159
|
-
patterns,
|
|
160
|
-
}),
|
|
161
|
-
writeDb({
|
|
162
|
-
dataDir,
|
|
163
|
-
db,
|
|
164
|
-
}),
|
|
165
|
-
]);
|
|
166
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { flow } from '@knapsack/utils';
|
|
2
|
-
import { convertHtmlToTipTapJson } from '@knapsack/tiptap-utils';
|
|
3
|
-
import { marked } from 'marked';
|
|
4
|
-
import domPurify from 'isomorphic-dompurify';
|
|
5
|
-
import { load } from 'cheerio';
|
|
6
|
-
|
|
7
|
-
// Marked wants to wrap every damn thing in a paragraph tag. We don't want to wrap
|
|
8
|
-
// images (and probably other block things) in a paragraph tag, because tiptap
|
|
9
|
-
// poops the bed on block content within a paragraph tag. No this doesn't work:
|
|
10
|
-
// @link https://github.com/ueberdosis/tiptap/issues/1206#issuecomment-825851955
|
|
11
|
-
// We're going to handle just the case where a string being parsed by Marked starts
|
|
12
|
-
// with "<img" and return it without any <p> tags. Everything else Marked thinks
|
|
13
|
-
// needs a <p> tag gets it.
|
|
14
|
-
marked.Renderer.prototype.paragraph = (text: string) =>
|
|
15
|
-
text.startsWith('<img') ? `${text}\n` : `<p>${text}</p>\n`;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* If this throws, then the block will remain a Markdown block and not be
|
|
19
|
-
* converted to a Text Editor block
|
|
20
|
-
*/
|
|
21
|
-
function assertConvertableBlock(html: string): string {
|
|
22
|
-
const $ = load(html);
|
|
23
|
-
if ($('a img').length > 0) {
|
|
24
|
-
throw new Error(`Markdown contains links that wrap images`);
|
|
25
|
-
}
|
|
26
|
-
if ($('table').length > 0) {
|
|
27
|
-
throw new Error(`Markdown contains tables`);
|
|
28
|
-
}
|
|
29
|
-
return html;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Convert markdown to html to sanitized html to TipTap JSON
|
|
34
|
-
*/
|
|
35
|
-
export const mdToTipTapJson = flow(
|
|
36
|
-
(md: string): string => marked.parse(md),
|
|
37
|
-
assertConvertableBlock,
|
|
38
|
-
domPurify.sanitize,
|
|
39
|
-
convertHtmlToTipTapJson,
|
|
40
|
-
);
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file
|
|
3
|
-
* Placeholder migration for future reference
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { Update } from '../../types.js';
|
|
7
|
-
|
|
8
|
-
export const update400_placeholder: Update = {
|
|
9
|
-
shouldRun: ({ installedVersion }) => installedVersion.startsWith('3.'),
|
|
10
|
-
title: 'Placeholder migration',
|
|
11
|
-
updater: async ({ config }) => {
|
|
12
|
-
console.log('Placeholder migration');
|
|
13
|
-
},
|
|
14
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { writeDb } from '@knapsack/ks-file-utils';
|
|
2
|
-
import { readDb } from '../utils/oldDb.js';
|
|
3
|
-
import { Update } from '../types.js';
|
|
4
|
-
|
|
5
|
-
export const update4_28_DB_to_files: Update = {
|
|
6
|
-
title: 'Migrating demos and blocks from db.yml to individual files',
|
|
7
|
-
async shouldRun({ config: { data: dataDir } }) {
|
|
8
|
-
// if `db.yml` has blocks or demos, then we need to run this update
|
|
9
|
-
const db = await readDb({ dataDir });
|
|
10
|
-
const totalBlocks = Object.keys(db.blocks?.byId || {}).length;
|
|
11
|
-
const totalDemos = Object.keys(db.demos?.byId || {}).length;
|
|
12
|
-
return totalBlocks > 0 || totalDemos > 0;
|
|
13
|
-
},
|
|
14
|
-
updater: async ({ config }) => {
|
|
15
|
-
const { data: dataDir } = config;
|
|
16
|
-
|
|
17
|
-
// Read db the "old" way
|
|
18
|
-
const db = await readDb({ dataDir });
|
|
19
|
-
// Writing the db the "new" way auto-migrates everything
|
|
20
|
-
await writeDb({ dataDir, db });
|
|
21
|
-
},
|
|
22
|
-
};
|
package/src/updates/index.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Update } from '../types.js';
|
|
2
|
-
import { update400_placeholder } from './4.0.0/index.js';
|
|
3
|
-
import { update4_28_DB_to_files } from './4.28.0-db-to-files.js';
|
|
4
|
-
|
|
5
|
-
export const updates = [
|
|
6
|
-
update400_placeholder,
|
|
7
|
-
update4_28_DB_to_files,
|
|
8
|
-
] satisfies Update[];
|
package/src/utils/exec.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { execSync, ExecSyncOptions } from 'node:child_process';
|
|
2
|
-
|
|
3
|
-
export function exec({
|
|
4
|
-
command,
|
|
5
|
-
opts,
|
|
6
|
-
}: {
|
|
7
|
-
command: string;
|
|
8
|
-
opts?: ExecSyncOptions;
|
|
9
|
-
}): string | undefined {
|
|
10
|
-
const rawResult = execSync(command, opts);
|
|
11
|
-
return rawResult.toString('utf8').trim();
|
|
12
|
-
}
|
package/src/utils/oldDb.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file
|
|
3
|
-
*
|
|
4
|
-
* Emulate the >=4.0 | <4.28 way of reading and writing the db, which was a single yaml file
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { ensureDirCached, readYaml, writeYaml } from '@knapsack/file-utils';
|
|
8
|
-
import { KsAppClientData } from '@knapsack/types';
|
|
9
|
-
import { join } from 'node:path';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The pre-4.28.0 way of reading the db, which was a single yaml file
|
|
13
|
-
*/
|
|
14
|
-
export async function readDb({
|
|
15
|
-
dataDir,
|
|
16
|
-
}: {
|
|
17
|
-
dataDir: string;
|
|
18
|
-
}): Promise<KsAppClientData['db']> {
|
|
19
|
-
await ensureDirCached(dataDir);
|
|
20
|
-
return readYaml<KsAppClientData['db']>(join(dataDir, 'db.yml'));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* The pre-4.28.0 way of writing the db, which was a single yaml file
|
|
25
|
-
*/
|
|
26
|
-
export async function writeDb({
|
|
27
|
-
dataDir,
|
|
28
|
-
db,
|
|
29
|
-
}: {
|
|
30
|
-
dataDir: string;
|
|
31
|
-
db: KsAppClientData['db'];
|
|
32
|
-
}) {
|
|
33
|
-
await ensureDirCached(dataDir);
|
|
34
|
-
return writeYaml({ path: join(dataDir, 'db.yml'), contents: db });
|
|
35
|
-
}
|