Skip to content

Commit 16b9ed2

Browse files
committed
Update to 1.1.0
1 parent cb4a148 commit 16b9ed2

File tree

11 files changed

+442
-603
lines changed

11 files changed

+442
-603
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
Все основные изменения задокументированы в этом файле.
44

5+
[1.1.0]: https://github.com/digikid/create-project/releases/tag/1.1.0
6+
7+
## [1.1.0] - 2022-01-28
8+
9+
### Добавлено
10+
- Проверка на запуск от имени администратора для корректного сохранения настроек
11+
12+
### Исправлено
13+
- Пользовательский файл конфигурации не сохранялся в ОС Mac / Linux
14+
- Рефакторинг кода, исправление мелких ошибок
15+
516
[1.0.0]: https://github.com/digikid/create-project/releases/tag/1.0.0
617

718
## [1.0.0] - 2022-01-22

bin/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import init from '#lib/init';
44
import configurate from '#lib/configurate';
55
import restore from '#lib/restore';
66

7+
import { dir } from '#lib/utils/path';
78
import { scanDirectory, readFileAsync } from '#lib/utils/fs';
89
import { isValid } from '#lib/utils/json';
910
import { arg } from '#lib/utils/args';
@@ -12,7 +13,7 @@ import { error } from '#lib/utils/log';
1213
(async () => {
1314
const config = {};
1415

15-
const files = scanDirectory('config', {
16+
const files = scanDirectory(dir('config'), {
1617
extensions: ['json']
1718
});
1819

@@ -22,7 +23,7 @@ import { error } from '#lib/utils/log';
2223

2324
const key = name.replace('.json', '');
2425

25-
const data = await readFileAsync(`config/${name}`);
26+
const data = await readFileAsync(dir(`config/${name}`));
2627
const value = isValid(data) ? JSON.parse(data) : {};
2728

2829
config[key] = value;

config/messages.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@
2626
"COPY_BOILERPLATE_ERROR": "При перемещении дополнительных файлов произошла ошибка",
2727
"ENVIRONMENT_ERROR": "Невозможно запустить скрипт в текущем окружении",
2828
"PATH_EXISTS_ERROR": "Папка с таким названием уже существует",
29-
"GIT_COMMAND_NOT_FOUND_ERROR": "Не удалось найти команду, установите git по инструкции:\\nhttps://github.com/git-guides/install-git"
29+
"GIT_COMMAND_NOT_FOUND_ERROR": "Не удалось найти команду, установите git по инструкции:\\nhttps://github.com/git-guides/install-git",
30+
"SUDO_ERROR": "Скрипт может быть запущен только с правами администратора"
3031
}

config/user.json

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
{
2+
"repo": [
3+
{
4+
"name": "name",
5+
"message": "Название проекта:",
6+
"default": "new-project"
7+
},
8+
{
9+
"name": "host",
10+
"type": "list",
11+
"message": "Хостинг для репозитория:",
12+
"default": "gitlab",
13+
"choices": [
14+
{
15+
"name": "GitHub",
16+
"value": "github",
17+
"short": "GitHub"
18+
},
19+
{
20+
"name": "GitLab",
21+
"value": "gitlab",
22+
"short": "GitLab"
23+
},
24+
{
25+
"name": "BitBucket",
26+
"value": "bitbucket",
27+
"short": "BitBucket"
28+
}
29+
]
30+
},
31+
{
32+
"name": "owner",
33+
"message": "Учетная запись на хостинге:",
34+
"default": "Relevant-agency"
35+
},
36+
{
37+
"name": "author",
38+
"message": "Имя автора (латиницей):",
39+
"default": "Alexander Dovlatov"
40+
}
41+
],
42+
"contacts": [
43+
{
44+
"name": "continue",
45+
"type": "confirm",
46+
"message": "Указать контактные данные?",
47+
"default": true
48+
},
49+
{
50+
"name": "name",
51+
"message": "Ваше имя (кириллицей):",
52+
"default": "Александр Довлатов"
53+
},
54+
{
55+
"name": "telegram",
56+
"message": "Аккаунт в телеграме:",
57+
"default": "digikid"
58+
},
59+
{
60+
"name": "job",
61+
"message": "Должность:",
62+
"default": "Frontend-разработчик"
63+
}
64+
],
65+
"info": [
66+
{
67+
"name": "continue",
68+
"type": "confirm",
69+
"message": "Указать информацию о проекте?",
70+
"default": true
71+
},
72+
{
73+
"name": "title",
74+
"message": "Заголовок проекта:",
75+
"default": ""
76+
},
77+
{
78+
"name": "description",
79+
"message": "Описание проекта:",
80+
"default": ""
81+
},
82+
{
83+
"name": "copyright",
84+
"message": "Копирайт:",
85+
"default": "Интернет-агентство «Relevant»"
86+
}
87+
],
88+
"vendor": [
89+
{
90+
"name": "continue",
91+
"type": "confirm",
92+
"message": "Установить дополнительные плагины?",
93+
"default": true
94+
},
95+
{
96+
"name": "dependencies",
97+
"type": "checkbox",
98+
"message": "Выберите плагины из списка:",
99+
"default": [
100+
"*"
101+
],
102+
"choices": [
103+
{
104+
"name": "Выбрать все",
105+
"value": "*",
106+
"short": "Все"
107+
},
108+
{
109+
"name": "Animate.css (CSS анимации)",
110+
"value": "animate",
111+
"short": "Animate.css"
112+
},
113+
{
114+
"name": "Air Datepicker (Выбор даты)",
115+
"value": "datepicker",
116+
"short": "Air Datepicker"
117+
},
118+
{
119+
"name": "Bootstrap (UI компоненты)",
120+
"value": "bootstrap",
121+
"short": "Bootstrap"
122+
},
123+
{
124+
"name": "Fancybox (Модальные окна)",
125+
"value": "fancybox",
126+
"short": "Fancybox"
127+
},
128+
{
129+
"name": "jQuery.mask (Валидация телефоннных номеров)",
130+
"value": "mask",
131+
"short": "jQuery.mask"
132+
},
133+
{
134+
"name": "Lozad (Ленивая загрузка изображений)",
135+
"value": "lozad",
136+
"short": "Lozad"
137+
},
138+
{
139+
"name": "Simplebar (Кроссплатформенный скроллбар)",
140+
"value": "simplebar",
141+
"short": "Simplebar"
142+
},
143+
{
144+
"name": "Swiper (Карусель)",
145+
"value": "swiper",
146+
"short": "Swiper"
147+
},
148+
{
149+
"name": "Tippy (Всплывающие подсказки)",
150+
"value": "tippy",
151+
"short": "Tippy"
152+
}
153+
]
154+
}
155+
],
156+
"params": [
157+
{
158+
"name": "es6",
159+
"type": "confirm",
160+
"message": "Включить импорт ES6 модулей?",
161+
"default": true
162+
}
163+
],
164+
"files": [
165+
{
166+
"name": "boilerplate",
167+
"type": "confirm",
168+
"message": "Подготовить структуру проекта?",
169+
"default": true
170+
}
171+
]
172+
}

lib/configurate.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import inquirer from 'inquirer';
22

3-
import { writeFileAsync } from '#lib/utils/fs';
3+
import { checkSudo } from 'check-sudo';
4+
5+
import { args, keys } from '#lib/utils/args';
46
import { dir } from '#lib/utils/path';
7+
import { writeFileAsync } from '#lib/utils/fs';
58
import { print, error } from '#lib/utils/log';
69

710
export default async config => {
@@ -11,6 +14,14 @@ export default async config => {
1114
print('CONFIGURATE_TEXT');
1215

1316
try {
17+
const isSudo = await checkSudo();
18+
19+
if (!isSudo) {
20+
print('SUDO_ERROR');
21+
22+
process.exit(1);
23+
};
24+
1425
const options = JSON.parse(JSON.stringify(prompts));
1526

1627
for (let [id, questions] of Object.entries(prompts)) {
@@ -61,7 +72,7 @@ export default async config => {
6172
};
6273
};
6374

64-
await writeFileAsync('config/user.json', JSON.stringify(options, null, 2));
75+
await writeFileAsync(dir('config/user.json'), JSON.stringify(options, null, 2));
6576

6677
print('CONFIGURATE_SUCCESS');
6778
} catch(e) {

lib/init.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import path from 'path';
12
import chalk from 'chalk';
23
import inquirer from 'inquirer';
34

@@ -6,12 +7,13 @@ import installDeps from '#lib/tasks/installDeps';
67
import addConfig from '#lib/tasks/addConfig';
78
import copyBoilerplate from '#lib/tasks/copyBoilerplate';
89

10+
import { cwd } from '#lib/utils/path';
911
import { isExistsAsync } from '#lib/utils/fs';
1012
import { keys, arg } from '#lib/utils/args';
1113
import { print, error } from '#lib/utils/log';
1214

1315
const checkDirectoryExists = async path => {
14-
if (path && await isExistsAsync(`../${path}`)) {
16+
if (path && await isExistsAsync(cwd(path))) {
1517
print('PATH_EXISTS_ERROR');
1618

1719
process.exit(1);

lib/restore.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import inquirer from 'inquirer';
22

3+
import { checkSudo } from 'check-sudo';
4+
5+
import { dir } from '#lib/utils/path';
36
import { removeFileAsync } from '#lib/utils/fs';
47
import { print, error } from '#lib/utils/log';
58

@@ -8,6 +11,14 @@ export default async config => {
811
print('RESTORE_TEXT');
912

1013
try {
14+
const isSudo = await checkSudo();
15+
16+
if (!isSudo) {
17+
print('SUDO_ERROR');
18+
19+
process.exit(1);
20+
};
21+
1122
const answer = await inquirer.prompt({
1223
name: 'continue',
1324
type: 'confirm',
@@ -16,7 +27,7 @@ export default async config => {
1627
});
1728

1829
if (answer.continue) {
19-
await removeFileAsync('config/user.json');
30+
await removeFileAsync(dir('config/user.json'));
2031

2132
print('RESTORE_SUCCESS');
2233
} else {

lib/utils/fs.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ import replace from 'replace-in-file';
55

66
import { access, unlink, writeFile, readFile } from 'fs/promises';
77

8-
import { dir } from '#lib/utils/path';
9-
108
export const isExistsAsync = async path => {
119
try {
12-
const e = await access(dir(path));
10+
const e = await access(path);
1311

1412
return !e;
1513
} catch(e) {
@@ -27,7 +25,7 @@ export const replaceAsync = async (options) => {
2725

2826
export const readFileAsync = async (path, encoding = 'utf-8') => {
2927
try {
30-
const data = await readFile(dir(path), encoding);
28+
const data = await readFile(path, encoding);
3129

3230
return data;
3331
} catch(e) {
@@ -37,7 +35,7 @@ export const readFileAsync = async (path, encoding = 'utf-8') => {
3735

3836
export const writeFileAsync = async (path, data) => {
3937
try {
40-
await writeFile(dir(path), data);
38+
await writeFile(path, data);
4139
} catch(e) {
4240
return false;
4341
};
@@ -47,7 +45,7 @@ export const writeFileAsync = async (path, data) => {
4745

4846
export const removeFileAsync = async path => {
4947
try {
50-
await unlink(dir(path));
48+
await unlink(path);
5149
} catch(e) {
5250
return false;
5351
};
@@ -81,7 +79,7 @@ export const mergeDirsAsync = (source, dest) => {
8179

8280
export const scanDirectory = (path, options = {}) => {
8381
try {
84-
const result = dree.scan(dir(path), options);
82+
const result = dree.scan(path, options);
8583

8684
const tree = (result && ('children' in result)) ? result.children : [];
8785

lib/utils/path.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import path from 'path';
2+
23
import { fileURLToPath } from 'url';
34

45
export const __dirname = path.dirname(fileURLToPath(import.meta.url));
56

6-
export const dir = (child = '') => child ? path.join(__dirname, `../../${child}`) : __dirname;
7+
export const dir = (child = '') => child ? path.join(__dirname, `../../${child}`) : __dirname;
8+
9+
export const cwd = (child = '') => child ? path.join(process.cwd(), child) : process.cwd();

0 commit comments

Comments
 (0)