Skip to content

Commit 1751ca1

Browse files
author
Guillaume Chau
committed
feat(ui): Initial schema and folder API
1 parent 1aee235 commit 1751ca1

16 files changed

+196
-183
lines changed

packages/@vue/cli-ui/src/App.vue

-27
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,5 @@
11
<template>
22
<div id="app">
3-
<div id="nav">
4-
<router-link to="/">Home</router-link> |
5-
<router-link to="/about">About</router-link>
6-
</div>
73
<router-view/>
84
</div>
95
</template>
10-
11-
<style>
12-
#app {
13-
font-family: 'Avenir', Helvetica, Arial, sans-serif;
14-
-webkit-font-smoothing: antialiased;
15-
-moz-osx-font-smoothing: grayscale;
16-
text-align: center;
17-
color: #2c3e50;
18-
}
19-
20-
#nav {
21-
padding: 30px;
22-
}
23-
24-
#nav a {
25-
font-weight: bold;
26-
color: #2c3e50;
27-
}
28-
29-
#nav a.router-link-exact-active {
30-
color: #42b983;
31-
}
32-
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
CWD_CHANGED: 'cwd_changed'
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const channels = require('../channels')
2+
3+
let cwd = process.cwd()
4+
5+
module.exports = {
6+
get: () => cwd,
7+
set: (value, context) => {
8+
cwd = value
9+
context.pubsub.publish(channels.CWD_CHANGED, { cwdChanged: value })
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const path = require('path')
2+
const fs = require('fs')
3+
4+
const cwd = require('./cwd')
5+
6+
function list (base, context) {
7+
return new Promise((resolve, reject) => {
8+
fs.readdir(base, 'utf8', (err, files) => {
9+
if (err) {
10+
reject(err)
11+
} else {
12+
resolve(files.map(
13+
file => ({
14+
path: path.join(base, file),
15+
name: file
16+
})
17+
).filter(
18+
file => fs.statSync(file.path).isDirectory()
19+
))
20+
}
21+
})
22+
})
23+
}
24+
25+
function generateFolder (file) {
26+
return {
27+
name: path.basename(file),
28+
path: file
29+
}
30+
}
31+
32+
function getCurrent (args, context) {
33+
const base = cwd.get()
34+
return generateFolder(base)
35+
}
36+
37+
function open (file, context) {
38+
cwd.set(file, context)
39+
return generateFolder(file)
40+
}
41+
42+
function openParent (file, context) {
43+
const newFile = path.dirname(file)
44+
cwd.set(newFile, context)
45+
return generateFolder(newFile)
46+
}
47+
48+
module.exports = {
49+
getCurrent,
50+
list,
51+
open,
52+
openParent
53+
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
const { db } = require('./utils/db')
2-
const { processUpload } = require('./utils/upload')
32

43
// Context passed to all resolvers (third argument)
54
// eslint-disable-next-line no-unused-vars
65
module.exports = req => {
76
return {
8-
db,
9-
processUpload
7+
db
108
}
119
}
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,25 @@
1-
const shortid = require('shortid')
1+
const channels = require('./channels')
2+
const cwd = require('./connectors/cwd')
3+
const folders = require('./connectors/folders')
24

35
module.exports = {
4-
Counter: {
5-
countStr: counter => `Current count: ${counter.count}`
6+
Folder: {
7+
children: (folder, args, context) => folders.list(folder.path, context)
68
},
79

810
Query: {
9-
hello: (root, { name }) => `Hello ${name || 'World'}!`,
10-
messages: (root, args, { db }) => db.get('messages').value(),
11-
uploads: (root, args, { db }) => db.get('uploads').value()
11+
cwd: () => cwd.get(),
12+
folderCurrent: (root, args, context) => folders.getCurrent(args, context)
1213
},
1314

1415
Mutation: {
15-
messageAdd: (root, { input }, { pubsub, db }) => {
16-
const message = {
17-
id: shortid.generate(),
18-
text: input.text
19-
}
20-
21-
db
22-
.get('messages')
23-
.push(message)
24-
.last()
25-
.write()
26-
27-
pubsub.publish('messages', { messageAdded: message })
28-
29-
return message
30-
},
31-
32-
singleUpload: (root, { file }, { processUpload }) => processUpload(file),
33-
multipleUpload: (root, { files }, { processUpload }) => Promise.all(files.map(processUpload))
16+
folderOpen: (root, { path }, context) => folders.open(path, context),
17+
folderOpenParent: (root, args, context) => folders.openParent(cwd.get(), context)
3418
},
3519

3620
Subscription: {
37-
counter: {
38-
subscribe: (parent, args, { pubsub }) => {
39-
const channel = Math.random().toString(36).substring(2, 15) // random channel name
40-
let count = 0
41-
setInterval(() => pubsub.publish(
42-
channel,
43-
{
44-
// eslint-disable-next-line no-plusplus
45-
counter: { count: count++ }
46-
}
47-
), 2000)
48-
return pubsub.asyncIterator(channel)
49-
}
50-
},
51-
52-
messageAdded: {
53-
subscribe: (parent, args, { pubsub }) => pubsub.asyncIterator('messages')
21+
cwdChanged: {
22+
subscribe: (parent, args, { pubsub }) => pubsub.asyncIterator(channels.CWD_CHANGED)
5423
}
5524
}
5625
}
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,134 @@
11
module.exports = `
2-
# It will increment!
3-
type Counter {
4-
# Number of increments
5-
count: Int!
6-
# Full message for testing
7-
countStr: String
8-
}
92
10-
# A text message send by users
11-
type Message {
3+
type ConsoleLog {
124
id: ID!
13-
# Message content
14-
text: String!
5+
message: String!
6+
label: String
7+
tag: String
8+
type: ConsoleLogType!
159
}
1610
17-
# Input from user to create a message
18-
input MessageInput {
19-
# Message content
20-
text: String!
11+
enum ConsoleLogType {
12+
log
13+
warn
14+
error
15+
info
16+
done
2117
}
2218
23-
scalar Upload
19+
type Folder {
20+
name: String!
21+
path: String!
22+
children: [Folder]
23+
}
2424
25-
type File {
25+
type Project {
2626
id: ID!
27+
name: String!
28+
path: String!
29+
favorite: Int
30+
features: [Feature]
31+
plugins: [Plugin]
32+
}
33+
34+
input ProjectCreateInput {
35+
path: String!
36+
}
37+
38+
input ProjectImportInput {
2739
path: String!
28-
filename: String!
29-
mimetype: String!
30-
encoding: String!
40+
}
41+
42+
type Version {
43+
current: String!
44+
latest: String
45+
}
46+
47+
type GitHubStats {
48+
stars: Int
49+
}
50+
51+
type Plugin {
52+
id: ID!
53+
version: Version!
54+
official: Boolean
55+
installed: Boolean
56+
website: String
57+
description: String
58+
githubStats: GitHubStats
59+
prompts: [Prompt]
60+
}
61+
62+
input PluginSearchInput {
63+
terms: String!
64+
}
65+
66+
type Feature {
67+
id: ID!
68+
label: String!
69+
description: String!
70+
link: String!
71+
enabled: Boolean!
72+
}
73+
74+
enum PromptType {
75+
input
76+
confirm
77+
list
78+
rawlist
79+
expand
80+
checkbox
81+
password
82+
editor
83+
}
84+
85+
type PromptChoice {
86+
value: String!
87+
}
88+
89+
type PromptError {
90+
message: String!
91+
link: String
92+
}
93+
94+
type Prompt {
95+
id: ID!
96+
enabled: Boolean!
97+
type: PromptType!
98+
name: String
99+
message: String
100+
description: String
101+
link: String
102+
choices: [PromptChoice]
103+
currentValue: String
104+
error: PromptError
105+
}
106+
107+
input PromptInput {
108+
id: ID!
109+
value: String!
31110
}
32111
33112
type Query {
34-
# Test query with a parameter
35-
hello(name: String): String!
36-
# List of messages sent by users
37-
messages: [Message]
38-
uploads: [File]
113+
cwd: String!
114+
folderCurrent: Folder
115+
projects: [Project]
116+
projectCurrent: Project
117+
pluginSearch (input: PluginSearchInput!): [Plugin]
39118
}
40119
41120
type Mutation {
42-
# Add a message and publish it on 'messages' subscription channel
43-
messageAdd (input: MessageInput!): Message!
44-
singleUpload (file: Upload!): File!
45-
multipleUpload (files: [Upload!]!): [File!]!
121+
folderOpen (path: String!): Folder
122+
folderOpenParent: Folder
123+
projectCreate (input: ProjectCreateInput!): Project!
124+
projectImport (input: ProjectImportInput!): Project!
125+
projectSetFavorite (id: ID!, favorite: Int!): Project!
126+
pluginAdd (id: ID!): Plugin
127+
promptAnswer (input: PromptInput!): Prompt
46128
}
47129
48130
type Subscription {
49-
# This will update every 2 seconds
50-
counter: Counter!
51-
# When a new message is added
52-
messageAdded: Message!
131+
consoleLogAdded: ConsoleLog!
132+
cwdChanged: String!
53133
}
54134
`

packages/@vue/cli-ui/src/graphql-api/utils/db.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ const db = new Lowdb(new FileSync(resolve(__dirname, '../../../live/db.json')))
99

1010
// Seed an empty DB
1111
db.defaults({
12-
messages: [],
13-
uploads: []
12+
projects: []
1413
}).write()
1514

1615
module.exports = {

0 commit comments

Comments
 (0)