@slicemachine/init 1.1.16-dev-ct-slice-delete.2 → 1.1.16-dev-alpha.4
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/.depcheckrc +3 -1
- package/build/index.js +2896 -16
- package/build/index.js.map +1 -1
- package/jest.config.js +0 -1
- package/package.json +8 -12
- package/src/index.ts +6 -1
- package/src/steps/detect-framework.ts +12 -8
- package/src/steps/install-required-dependencies.ts +22 -6
- package/src/utils/index.ts +1 -0
- package/src/utils/versionCheck.ts +9 -0
- package/babel.config.js +0 -7
package/jest.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slicemachine/init",
|
|
3
|
-
"version": "1.1.16-dev-
|
|
3
|
+
"version": "1.1.16-dev-alpha.4",
|
|
4
4
|
"description": "The easiest way to add Slice Machine to your project",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
"prepublishOnly": "npm run test && npm run build",
|
|
17
17
|
"test": "jest",
|
|
18
18
|
"tsc": "tsc --project tsconfig.json --noEmit",
|
|
19
|
-
"
|
|
19
|
+
"watch": "tsc --project tsconfig.json --noEmit --watch"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@hapi/hapi": "^20.2.0",
|
|
23
|
-
"@prismicio/types-internal": "^
|
|
24
|
-
"@slicemachine/client": "1.1.16-dev-
|
|
25
|
-
"@slicemachine/core": "1.1.16-dev-
|
|
23
|
+
"@prismicio/types-internal": "^1.5.3",
|
|
24
|
+
"@slicemachine/client": "1.1.16-dev-alpha.4",
|
|
25
|
+
"@slicemachine/core": "1.1.16-dev-alpha.4",
|
|
26
26
|
"adm-zip": "^0.5.9",
|
|
27
27
|
"analytics-node": "^6.0.0",
|
|
28
28
|
"axios": "^0.24.0",
|
|
@@ -37,9 +37,6 @@
|
|
|
37
37
|
"uuid": "^8.3.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@babel/core": "^7.15.8",
|
|
41
|
-
"@babel/preset-env": "^7.15.8",
|
|
42
|
-
"@babel/preset-typescript": "^7.15.0",
|
|
43
40
|
"@rollup/plugin-replace": "^3.0.1",
|
|
44
41
|
"@types/adm-zip": "^0.4.34",
|
|
45
42
|
"@types/analytics-node": "^3.1.7",
|
|
@@ -52,7 +49,6 @@
|
|
|
52
49
|
"@types/uuid": "^8.3.4",
|
|
53
50
|
"@typescript-eslint/eslint-plugin": "^5.10.0",
|
|
54
51
|
"@typescript-eslint/parser": "^5.10.0",
|
|
55
|
-
"babel-jest": "^27.0.2",
|
|
56
52
|
"better-npm-audit": "^3.4.0",
|
|
57
53
|
"depcheck": "^1.4.3",
|
|
58
54
|
"eslint": "^7.32.0",
|
|
@@ -60,16 +56,16 @@
|
|
|
60
56
|
"eslint-import-resolver-typescript": "^2.4.0",
|
|
61
57
|
"eslint-plugin-import": "^2.24.0",
|
|
62
58
|
"eslint-plugin-jest": "^24.4.0",
|
|
63
|
-
"jest": "^
|
|
59
|
+
"jest": "^29.3.1",
|
|
64
60
|
"mock-fs": "^5.1.2",
|
|
65
61
|
"nock": "^13.1.3",
|
|
66
62
|
"siroc": "^0.16.0",
|
|
67
63
|
"stdout-stderr": "^0.1.13",
|
|
68
|
-
"ts-jest": "^
|
|
64
|
+
"ts-jest": "^29.0.3",
|
|
69
65
|
"typescript": "^4.4.3"
|
|
70
66
|
},
|
|
71
67
|
"engines": {
|
|
72
68
|
"node": ">=14"
|
|
73
69
|
},
|
|
74
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "bea0fb6520e9200e0614e9fe062005561227b4f7"
|
|
75
71
|
}
|
package/src/index.ts
CHANGED
|
@@ -95,7 +95,12 @@ async function init() {
|
|
|
95
95
|
);
|
|
96
96
|
|
|
97
97
|
// Install the required dependencies in the project.
|
|
98
|
-
await installRequiredDependencies(
|
|
98
|
+
await installRequiredDependencies(
|
|
99
|
+
cwd,
|
|
100
|
+
frameworkResult.value,
|
|
101
|
+
wasStarter,
|
|
102
|
+
frameworkResult.version
|
|
103
|
+
);
|
|
99
104
|
|
|
100
105
|
setVersion(cwd);
|
|
101
106
|
|
|
@@ -7,6 +7,7 @@ import Tracker from "../utils/tracker";
|
|
|
7
7
|
export type FrameworkResult = {
|
|
8
8
|
value: Models.Frameworks;
|
|
9
9
|
manuallyAdded: boolean;
|
|
10
|
+
version?: string;
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
export async function promptForFramework(): Promise<FrameworkResult> {
|
|
@@ -31,6 +32,7 @@ export async function promptForFramework(): Promise<FrameworkResult> {
|
|
|
31
32
|
return {
|
|
32
33
|
value: res.framework,
|
|
33
34
|
manuallyAdded: true,
|
|
35
|
+
version: undefined,
|
|
34
36
|
};
|
|
35
37
|
});
|
|
36
38
|
}
|
|
@@ -47,21 +49,22 @@ export async function detectFramework(cwd: string): Promise<FrameworkResult> {
|
|
|
47
49
|
spinner.start();
|
|
48
50
|
|
|
49
51
|
try {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
const { framework, version } =
|
|
53
|
+
NodeUtils.Framework.defineFrameworkWithVersion({
|
|
54
|
+
cwd,
|
|
55
|
+
supportedFrameworks: Object.values(Models.Frameworks),
|
|
56
|
+
});
|
|
54
57
|
|
|
55
58
|
spinner.stop();
|
|
56
59
|
|
|
57
|
-
if (!
|
|
60
|
+
if (!framework || framework === Models.Frameworks.vanillajs) {
|
|
58
61
|
logs.writeError("Framework not detected");
|
|
59
62
|
return await promptForFramework();
|
|
60
63
|
}
|
|
61
64
|
|
|
62
|
-
const nameToPrint = NodeUtils.Framework.fancyName(
|
|
65
|
+
const nameToPrint = NodeUtils.Framework.fancyName(framework);
|
|
63
66
|
|
|
64
|
-
if (!NodeUtils.Framework.isFrameworkSupported(
|
|
67
|
+
if (!NodeUtils.Framework.isFrameworkSupported(framework)) {
|
|
65
68
|
logs.writeError(`${nameToPrint} is currently not supported`);
|
|
66
69
|
console.log(failMessage);
|
|
67
70
|
process.exit(1);
|
|
@@ -70,8 +73,9 @@ export async function detectFramework(cwd: string): Promise<FrameworkResult> {
|
|
|
70
73
|
logs.writeCheck(`${nameToPrint} detected`);
|
|
71
74
|
|
|
72
75
|
return {
|
|
73
|
-
value:
|
|
76
|
+
value: framework,
|
|
74
77
|
manuallyAdded: false,
|
|
78
|
+
version,
|
|
75
79
|
};
|
|
76
80
|
} catch (error) {
|
|
77
81
|
spinner.fail("package.json not found");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { execCommand, logs } from "../utils";
|
|
2
|
+
import { checkVersion, execCommand, logs } from "../utils";
|
|
3
3
|
import { CONSTS, Models } from "@slicemachine/core";
|
|
4
4
|
import * as NodeUtils from "@slicemachine/core/build/node-utils";
|
|
5
5
|
|
|
@@ -7,6 +7,7 @@ const {
|
|
|
7
7
|
PRISMIC_CLIENT,
|
|
8
8
|
PRISMIC_DOM_PACKAGE_NAME,
|
|
9
9
|
PRISMIC_REACT_PACKAGE_NAME,
|
|
10
|
+
PRISMIC_NEXT,
|
|
10
11
|
SM_PACKAGE_NAME,
|
|
11
12
|
NUXT_PRISMIC,
|
|
12
13
|
PRISMIC_VUE,
|
|
@@ -16,12 +17,25 @@ const {
|
|
|
16
17
|
PRISMIC_TYPES,
|
|
17
18
|
} = CONSTS;
|
|
18
19
|
|
|
19
|
-
function
|
|
20
|
+
export function nextDeps(version?: string): string {
|
|
21
|
+
if (checkVersion(">=13.0.0", version)) {
|
|
22
|
+
return PRISMIC_NEXT;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function depsForFramework(
|
|
29
|
+
framework: Models.Frameworks,
|
|
30
|
+
version?: string
|
|
31
|
+
): string {
|
|
20
32
|
switch (framework) {
|
|
21
33
|
case Models.Frameworks.react:
|
|
22
34
|
return `${PRISMIC_REACT_PACKAGE_NAME} ${PRISMIC_CLIENT} ${PRISMIC_HELPERS}`;
|
|
23
35
|
case Models.Frameworks.next:
|
|
24
|
-
return `${PRISMIC_REACT_PACKAGE_NAME} ${
|
|
36
|
+
return `${PRISMIC_REACT_PACKAGE_NAME} ${nextDeps(
|
|
37
|
+
version
|
|
38
|
+
)} ${PRISMIC_CLIENT} ${SLICE_SIMULATOR_REACT} ${PRISMIC_HELPERS}`;
|
|
25
39
|
case Models.Frameworks.svelte:
|
|
26
40
|
return `${PRISMIC_DOM_PACKAGE_NAME} ${PRISMIC_CLIENT}`;
|
|
27
41
|
case Models.Frameworks.nuxt:
|
|
@@ -35,6 +49,7 @@ function depsForFramework(framework: Models.Frameworks): string {
|
|
|
35
49
|
|
|
36
50
|
async function addAndInstallDeps(
|
|
37
51
|
framework: Models.Frameworks,
|
|
52
|
+
version?: string,
|
|
38
53
|
useYarn = false
|
|
39
54
|
): Promise<string> {
|
|
40
55
|
const installDevDependencyCommand = useYarn
|
|
@@ -46,7 +61,7 @@ async function addAndInstallDeps(
|
|
|
46
61
|
`${installDevDependencyCommand} ${SM_PACKAGE_NAME} ${PRISMIC_TYPES}`
|
|
47
62
|
);
|
|
48
63
|
|
|
49
|
-
const deps = depsForFramework(framework);
|
|
64
|
+
const deps = depsForFramework(framework, version);
|
|
50
65
|
if (deps) await execCommand(`${installDependencyCommand} ${deps}`);
|
|
51
66
|
|
|
52
67
|
return stderr;
|
|
@@ -61,7 +76,8 @@ async function installDeps(useYarn = false): Promise<string> {
|
|
|
61
76
|
export async function installRequiredDependencies(
|
|
62
77
|
cwd: string,
|
|
63
78
|
framework: Models.Frameworks,
|
|
64
|
-
skipDependencies: boolean
|
|
79
|
+
skipDependencies: boolean,
|
|
80
|
+
version?: string
|
|
65
81
|
): Promise<void> {
|
|
66
82
|
const yarnLock = NodeUtils.Files.exists(NodeUtils.YarnLockPath(cwd));
|
|
67
83
|
|
|
@@ -70,7 +86,7 @@ export async function installRequiredDependencies(
|
|
|
70
86
|
|
|
71
87
|
const stderr = await (skipDependencies
|
|
72
88
|
? installDeps(yarnLock)
|
|
73
|
-
: addAndInstallDeps(framework, yarnLock));
|
|
89
|
+
: addAndInstallDeps(framework, version, yarnLock));
|
|
74
90
|
|
|
75
91
|
const pathToPkg = path.join(
|
|
76
92
|
NodeUtils.PackagePaths(cwd).value(),
|
package/src/utils/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * as logs from "./logs";
|
|
|
5
5
|
export { Auth } from "./auth";
|
|
6
6
|
export * from "./client";
|
|
7
7
|
export * from "./fs";
|
|
8
|
+
export * from "./versionCheck";
|
|
8
9
|
|
|
9
10
|
export function findArgument(args: string[], name: string): string | undefined {
|
|
10
11
|
const flagIndex: number = args.indexOf(`--${name}`);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import semver from "semver";
|
|
2
|
+
|
|
3
|
+
export function checkVersion(threshold: string, version?: string): boolean {
|
|
4
|
+
if (!version) return false;
|
|
5
|
+
const parsedVersion = semver.coerce(version);
|
|
6
|
+
if (parsedVersion === null) return false;
|
|
7
|
+
|
|
8
|
+
return semver.satisfies(parsedVersion, threshold);
|
|
9
|
+
}
|