@dittowords/cli 2.5.0 → 2.5.1
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/lib/add-project.js +27 -6
- package/lib/init/project.js +35 -11
- package/lib/remove-project.js +19 -4
- package/lib/utils/getSelectedProjects.js +10 -1
- package/package.json +1 -1
package/lib/add-project.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
const { collectAndSaveProject } = require("./init/project");
|
|
2
2
|
const projectsToText = require("./utils/projectsToText");
|
|
3
|
-
const
|
|
3
|
+
const {
|
|
4
|
+
getSelectedProjects,
|
|
5
|
+
getIsUsingComponents,
|
|
6
|
+
} = require("./utils/getSelectedProjects");
|
|
7
|
+
const output = require("./output");
|
|
4
8
|
|
|
5
9
|
function quit(exitCode = 2) {
|
|
6
10
|
console.log("Project selection was not updated.");
|
|
@@ -10,13 +14,30 @@ function quit(exitCode = 2) {
|
|
|
10
14
|
|
|
11
15
|
const addProject = async () => {
|
|
12
16
|
const projects = getSelectedProjects();
|
|
17
|
+
const usingComponents = getIsUsingComponents();
|
|
13
18
|
|
|
14
19
|
try {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
if (usingComponents) {
|
|
21
|
+
if (projects.length) {
|
|
22
|
+
console.log(
|
|
23
|
+
`\nYou're currently set up to sync text from the ${output.info(
|
|
24
|
+
"Component Library"
|
|
25
|
+
)} and from the following projects: ${projectsToText(projects)}`
|
|
26
|
+
);
|
|
27
|
+
} else {
|
|
28
|
+
console.log(
|
|
29
|
+
`\nYou're currently only set up to sync text from the ${output.info(
|
|
30
|
+
"Component Library"
|
|
31
|
+
)}`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
} else if (projects.length) {
|
|
35
|
+
console.log(
|
|
36
|
+
`\nYou're currently set up to sync text from the following projects: ${projectsToText(
|
|
37
|
+
projects
|
|
38
|
+
)}`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
20
41
|
await collectAndSaveProject(false);
|
|
21
42
|
} catch (error) {
|
|
22
43
|
console.log(
|
package/lib/init/project.js
CHANGED
|
@@ -5,7 +5,10 @@ const config = require("../config");
|
|
|
5
5
|
const consts = require("../consts");
|
|
6
6
|
const output = require("../output");
|
|
7
7
|
const { collectAndSaveToken } = require("../init/token");
|
|
8
|
-
const
|
|
8
|
+
const {
|
|
9
|
+
getSelectedProjects,
|
|
10
|
+
getIsUsingComponents,
|
|
11
|
+
} = require("../utils/getSelectedProjects");
|
|
9
12
|
const promptForProject = require("../utils/promptForProject");
|
|
10
13
|
|
|
11
14
|
function quit(exitCode = 2) {
|
|
@@ -15,10 +18,10 @@ function quit(exitCode = 2) {
|
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
function saveProject(file, name, id) {
|
|
18
|
-
// old functionality included "
|
|
21
|
+
// old functionality included "components" in the `projects`
|
|
19
22
|
// array, but we want to always treat the component library as a separate
|
|
20
23
|
// entity and use the new notation of a top-level `components` key
|
|
21
|
-
if (id === "
|
|
24
|
+
if (id === "components") {
|
|
22
25
|
config.writeData(file, { components: true });
|
|
23
26
|
return;
|
|
24
27
|
}
|
|
@@ -39,7 +42,11 @@ async function askForAnotherToken() {
|
|
|
39
42
|
await collectAndSaveToken(message);
|
|
40
43
|
}
|
|
41
44
|
|
|
42
|
-
async function listProjects(
|
|
45
|
+
async function listProjects(
|
|
46
|
+
token,
|
|
47
|
+
projectsAlreadySelected,
|
|
48
|
+
componentsSelected
|
|
49
|
+
) {
|
|
43
50
|
const spinner = ora("Fetching projects in your workspace...");
|
|
44
51
|
spinner.start();
|
|
45
52
|
|
|
@@ -58,9 +65,13 @@ async function listProjects(token, projectsAlreadySelected) {
|
|
|
58
65
|
|
|
59
66
|
spinner.stop();
|
|
60
67
|
|
|
61
|
-
return projects.data.filter(
|
|
62
|
-
|
|
63
|
-
|
|
68
|
+
return projects.data.filter(({ id }) => {
|
|
69
|
+
if (id === "ditto_component_library") {
|
|
70
|
+
return !componentsSelected;
|
|
71
|
+
} else {
|
|
72
|
+
return !projectsAlreadySelected.some((project) => project.id === id);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
64
75
|
}
|
|
65
76
|
|
|
66
77
|
async function collectProject(token, initialize) {
|
|
@@ -74,19 +85,32 @@ async function collectProject(token, initialize) {
|
|
|
74
85
|
}
|
|
75
86
|
|
|
76
87
|
const projectsAlreadySelected = getSelectedProjects();
|
|
77
|
-
const
|
|
88
|
+
const usingComponents = getIsUsingComponents();
|
|
89
|
+
const projects = await listProjects(
|
|
90
|
+
token,
|
|
91
|
+
projectsAlreadySelected,
|
|
92
|
+
usingComponents
|
|
93
|
+
);
|
|
78
94
|
|
|
79
95
|
if (!(projects && projects.length)) {
|
|
80
96
|
console.log("You're currently syncing all projects in your workspace.");
|
|
81
|
-
console.log(
|
|
97
|
+
console.log(
|
|
98
|
+
output.warnText(
|
|
99
|
+
"Not seeing a project that you were expecting? Verify that developer mode is enabled on that project. More info: https://www.dittowords.com/docs/ditto-developer-mode"
|
|
100
|
+
)
|
|
101
|
+
);
|
|
82
102
|
return null;
|
|
83
103
|
}
|
|
84
104
|
|
|
105
|
+
const nonInitPrompt = usingComponents
|
|
106
|
+
? "Add a project"
|
|
107
|
+
: "Add a project or library";
|
|
108
|
+
|
|
85
109
|
return promptForProject({
|
|
86
110
|
projects,
|
|
87
111
|
message: initialize
|
|
88
|
-
? "Choose the project you'd like to sync text from"
|
|
89
|
-
:
|
|
112
|
+
? "Choose the project or library you'd like to sync text from"
|
|
113
|
+
: nonInitPrompt,
|
|
90
114
|
});
|
|
91
115
|
}
|
|
92
116
|
|
package/lib/remove-project.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
const config = require("./config");
|
|
2
2
|
const consts = require("./consts");
|
|
3
3
|
const output = require("./output");
|
|
4
|
-
const
|
|
4
|
+
const {
|
|
5
|
+
getSelectedProjects,
|
|
6
|
+
getIsUsingComponents,
|
|
7
|
+
} = require("./utils/getSelectedProjects");
|
|
5
8
|
const promptForProject = require("./utils/promptForProject");
|
|
6
9
|
|
|
7
10
|
async function removeProject() {
|
|
8
11
|
const projects = getSelectedProjects();
|
|
9
|
-
|
|
12
|
+
const isUsingComponents = getIsUsingComponents();
|
|
13
|
+
if (!projects.length && !isUsingComponents) {
|
|
10
14
|
console.log(
|
|
11
15
|
"\n" +
|
|
12
16
|
"No projects found in your workspace.\n" +
|
|
@@ -15,13 +19,24 @@ async function removeProject() {
|
|
|
15
19
|
return;
|
|
16
20
|
}
|
|
17
21
|
|
|
22
|
+
const allProjects = isUsingComponents
|
|
23
|
+
? [
|
|
24
|
+
{ id: "ditto_component_library", name: "Ditto Component Library" },
|
|
25
|
+
...projects,
|
|
26
|
+
]
|
|
27
|
+
: projects;
|
|
28
|
+
|
|
18
29
|
const projectToRemove = await promptForProject({
|
|
19
|
-
projects,
|
|
20
|
-
message:
|
|
30
|
+
projects: allProjects,
|
|
31
|
+
message: isUsingComponents
|
|
32
|
+
? "Select a project or library to remove"
|
|
33
|
+
: "Select a project to remove",
|
|
21
34
|
});
|
|
22
35
|
if (!projectToRemove) return;
|
|
23
36
|
|
|
24
37
|
config.writeData(consts.PROJECT_CONFIG_FILE, {
|
|
38
|
+
components:
|
|
39
|
+
isUsingComponents && projectToRemove.id !== "ditto_component_library",
|
|
25
40
|
projects: projects.filter(({ id }) => id !== projectToRemove.id),
|
|
26
41
|
});
|
|
27
42
|
|
|
@@ -32,4 +32,13 @@ function getSelectedProjects(configFile = PROJECT_CONFIG_FILE) {
|
|
|
32
32
|
return contentJson.projects.filter(({ name, id }) => name && id);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
const getIsUsingComponents = (configFile = PROJECT_CONFIG_FILE) => {
|
|
36
|
+
if (!fs.existsSync(configFile)) return [];
|
|
37
|
+
|
|
38
|
+
const contentYaml = fs.readFileSync(configFile, "utf8");
|
|
39
|
+
const contentJson = yamlToJson(contentYaml);
|
|
40
|
+
|
|
41
|
+
return contentJson && contentJson.components;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
module.exports = { getSelectedProjects, getIsUsingComponents };
|