@akinon/projectzero 1.14.0 → 1.14.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/.prettierrc CHANGED
@@ -1,12 +1,12 @@
1
- {
2
- "bracketSameLine": false,
3
- "tabWidth": 2,
4
- "singleQuote": true,
5
- "bracketSpacing": true,
6
- "semi": true,
7
- "useTabs": false,
8
- "arrowParens": "always",
9
- "endOfLine": "lf",
10
- "proseWrap": "never",
11
- "trailingComma": "none"
12
- }
1
+ {
2
+ "bracketSameLine": false,
3
+ "tabWidth": 2,
4
+ "singleQuote": true,
5
+ "bracketSpacing": true,
6
+ "semi": true,
7
+ "useTabs": false,
8
+ "arrowParens": "always",
9
+ "endOfLine": "lf",
10
+ "proseWrap": "never",
11
+ "trailingComma": "none"
12
+ }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @akinon/projectzero
2
2
 
3
+ ## 1.14.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Change EOL
8
+
3
9
  ## 1.14.0
4
10
 
5
11
  ## 1.13.1
@@ -1,33 +1,33 @@
1
- import * as fs from 'fs';
2
- import path from 'path';
3
-
4
- const yargs = require('yargs/yargs');
5
- const { hideBin } = require('yargs/helpers');
6
- const args = yargs(hideBin(process.argv)).argv;
7
-
8
- export default () => {
9
- const workingDir = path.resolve(process.cwd());
10
- const settingsPath = path.resolve(workingDir, './src/settings.js');
11
-
12
- if (!fs.existsSync(settingsPath)) {
13
- return;
14
- }
15
-
16
- const settingsData = fs.readFileSync(settingsPath, {
17
- encoding: 'utf8',
18
- flag: 'r'
19
- });
20
-
21
- fs.writeFileSync(
22
- settingsPath,
23
- settingsData.replace(
24
- /commerceUrl: '.*'/,
25
- `commerceUrl: '${args.commerceUrl}'`
26
- )
27
- );
28
-
29
- console.log(
30
- '\x1b[32m%s\x1b[0m',
31
- `\n ✓ Commerce URL is set to ${args.commerceUrl}.\n\n`
32
- );
33
- };
1
+ import * as fs from 'fs';
2
+ import path from 'path';
3
+
4
+ const yargs = require('yargs/yargs');
5
+ const { hideBin } = require('yargs/helpers');
6
+ const args = yargs(hideBin(process.argv)).argv;
7
+
8
+ export default () => {
9
+ const workingDir = path.resolve(process.cwd());
10
+ const settingsPath = path.resolve(workingDir, './src/settings.js');
11
+
12
+ if (!fs.existsSync(settingsPath)) {
13
+ return;
14
+ }
15
+
16
+ const settingsData = fs.readFileSync(settingsPath, {
17
+ encoding: 'utf8',
18
+ flag: 'r'
19
+ });
20
+
21
+ fs.writeFileSync(
22
+ settingsPath,
23
+ settingsData.replace(
24
+ /commerceUrl: '.*'/,
25
+ `commerceUrl: '${args.commerceUrl}'`
26
+ )
27
+ );
28
+
29
+ console.log(
30
+ '\x1b[32m%s\x1b[0m',
31
+ `\n ✓ Commerce URL is set to ${args.commerceUrl}.\n\n`
32
+ );
33
+ };
@@ -1,235 +1,235 @@
1
- import path from 'path';
2
- import * as fs from 'fs';
3
- import * as readline from 'readline';
4
- import { slugify } from '../utils';
5
- import temp from 'temp';
6
-
7
- const exec = require('child_process').exec;
8
- const loadingSpinner = require('loading-spinner');
9
-
10
- temp.track();
11
-
12
- interface Question {
13
- text: string;
14
- optional: boolean;
15
- answerKey: string;
16
- hint?: string;
17
- }
18
-
19
- interface Answers {
20
- [key: string]: string;
21
- }
22
-
23
- const repositorySlug = 'projectzeropwa';
24
- const tempDirPath = temp.mkdirSync('pz-temp');
25
- const workingDir = path.resolve(process.cwd());
26
- const rl = readline.createInterface({
27
- input: process.stdin,
28
- output: process.stdout
29
- });
30
-
31
- const ANSWERS: Answers = {};
32
-
33
- const QUESTIONS: Array<Question> = [
34
- {
35
- text: 'Brand name',
36
- optional: false,
37
- answerKey: 'brandName',
38
- hint: 'eg. Project Zero'
39
- },
40
- {
41
- text: 'Project description',
42
- optional: true,
43
- answerKey: 'projectDescription'
44
- },
45
- {
46
- text: 'Commerce URL (SERVICE_BACKEND_URL)',
47
- optional: true,
48
- answerKey: 'commerceUrl',
49
- hint: 'Can be changed later'
50
- }
51
- ];
52
-
53
- const getAnswers = () => {
54
- return new Promise<Answers>((resolve) => {
55
- const question = QUESTIONS[Object.keys(ANSWERS).length];
56
-
57
- if (!question) {
58
- rl.close();
59
- resolve(ANSWERS);
60
- return;
61
- }
62
-
63
- let questionText = question.text;
64
-
65
- if (question.hint) {
66
- questionText += ` (${question.hint})`;
67
- }
68
-
69
- if (question.optional) {
70
- questionText += ` (optional)`;
71
- }
72
-
73
- rl.question(`${questionText}: `, (answer: string) => {
74
- if (!question.optional && !answer.length) {
75
- console.log('\x1b[31m%s\x1b[0m', `* This field is required\n`);
76
- resolve(getAnswers());
77
- } else {
78
- ANSWERS[question.answerKey] = answer;
79
- resolve(getAnswers());
80
- }
81
- });
82
- });
83
- };
84
-
85
- const cloneRepository = () =>
86
- new Promise<{ error?: Error }>((resolve) => {
87
- exec(
88
- `cd ${tempDirPath} && git clone git@bitbucket.org:akinonteam/${repositorySlug}.git`,
89
- function (err: any, stdout: any, stderr: any) {
90
- if (err != null) {
91
- resolve({ error: new Error(err) });
92
- } else if (typeof stderr != 'string') {
93
- resolve({ error: new Error(stderr) });
94
- } else {
95
- resolve({});
96
- }
97
- }
98
- );
99
- });
100
-
101
- const updatePackageJson = (brandName: string) => {
102
- const packageJsonPath = path.resolve(
103
- tempDirPath,
104
- `./${repositorySlug}/package.json`
105
- );
106
-
107
- const packageJsonData = fs.readFileSync(packageJsonPath, {
108
- encoding: 'utf8',
109
- flag: 'r'
110
- });
111
-
112
- fs.writeFileSync(
113
- packageJsonPath,
114
- packageJsonData.replace(/"name": ".*"/, `"name": "${slugify(brandName)}"`)
115
- );
116
- };
117
-
118
- const updateAkinonJson = (brandName: string, projectDescription: string) => {
119
- const akinonJsonPath = path.resolve(
120
- tempDirPath,
121
- `./${repositorySlug}/akinon.json`
122
- );
123
-
124
- const akinonJsonData = fs.readFileSync(akinonJsonPath, {
125
- encoding: 'utf8',
126
- flag: 'r'
127
- });
128
-
129
- let updatedData = akinonJsonData.replace(
130
- /"name": ".*"/,
131
- `"name": "${brandName}"`
132
- );
133
-
134
- if (projectDescription) {
135
- updatedData = updatedData.replace(
136
- /"description": ".*"/,
137
- `"description": "${projectDescription}"`
138
- );
139
- }
140
-
141
- fs.writeFileSync(akinonJsonPath, updatedData);
142
- };
143
-
144
- const copyEnv = (commerceUrl: string) => {
145
- const repositoryPath = path.resolve(tempDirPath, `./${repositorySlug}`);
146
-
147
- const envExamplePath = path.resolve(repositoryPath, `./.env.example`);
148
- const envPath = path.resolve(repositoryPath, `./.env`);
149
-
150
- const envData = fs.readFileSync(envExamplePath, {
151
- encoding: 'utf8',
152
- flag: 'r'
153
- });
154
-
155
- if (commerceUrl) {
156
- fs.writeFileSync(
157
- envExamplePath,
158
- envData.replace(
159
- /SERVICE_BACKEND_URL=.*/,
160
- `SERVICE_BACKEND_URL=${commerceUrl}`
161
- )
162
- );
163
- }
164
-
165
- fs.copyFileSync(envExamplePath, envPath);
166
- };
167
-
168
- const updatePlugins = () => {
169
- const pluginsPath = path.resolve(
170
- tempDirPath,
171
- `./${repositorySlug}/src/plugins.js`
172
- );
173
-
174
- fs.writeFileSync(pluginsPath, 'module.exports = [];');
175
- };
176
-
177
- export default async () => {
178
- const minNodeVersion = 18;
179
- const currentNodeVersion = parseInt(
180
- process.version.replace('v', '').split('.')[0]
181
- );
182
-
183
- if (currentNodeVersion < minNodeVersion) {
184
- console.log(
185
- '\x1b[31m%s\x1b[0m',
186
- `Node version must be ${minNodeVersion} or higher.\n`.concat(
187
- `Current version is ${currentNodeVersion}. Please update your Node version.`
188
- )
189
- );
190
-
191
- process.exit(1);
192
- }
193
-
194
- const answers = await getAnswers();
195
-
196
- const brandName =
197
- answers.brandName === '.'
198
- ? path.basename(process.cwd())
199
- : answers.brandName;
200
-
201
- loadingSpinner.start();
202
-
203
- await cloneRepository();
204
- updatePackageJson(brandName);
205
- updateAkinonJson(brandName, answers.projectDescription);
206
- copyEnv(answers.commerceUrl);
207
- updatePlugins();
208
-
209
- const slugifiedBrandName = slugify(answers.brandName);
210
-
211
- fs.rmSync(path.resolve(tempDirPath, `./${repositorySlug}/.git`), {
212
- recursive: true,
213
- force: true
214
- });
215
-
216
- fs.cpSync(
217
- path.resolve(tempDirPath, `./${repositorySlug}`),
218
- path.resolve(workingDir, `./${slugifiedBrandName}`),
219
- {
220
- recursive: true,
221
- force: true
222
- }
223
- );
224
-
225
- temp.cleanupSync();
226
-
227
- loadingSpinner.stop();
228
-
229
- console.log(
230
- '\x1b[32m%s\x1b[0m',
231
- `\n ✓ ${answers.brandName} project is ready.\n`
232
- );
233
-
234
- console.log('\x1b[33m%s\x1b[0m', 'Project Zero - Akinon\n');
235
- };
1
+ import path from 'path';
2
+ import * as fs from 'fs';
3
+ import * as readline from 'readline';
4
+ import { slugify } from '../utils';
5
+ import temp from 'temp';
6
+
7
+ const exec = require('child_process').exec;
8
+ const loadingSpinner = require('loading-spinner');
9
+
10
+ temp.track();
11
+
12
+ interface Question {
13
+ text: string;
14
+ optional: boolean;
15
+ answerKey: string;
16
+ hint?: string;
17
+ }
18
+
19
+ interface Answers {
20
+ [key: string]: string;
21
+ }
22
+
23
+ const repositorySlug = 'projectzeropwa';
24
+ const tempDirPath = temp.mkdirSync('pz-temp');
25
+ const workingDir = path.resolve(process.cwd());
26
+ const rl = readline.createInterface({
27
+ input: process.stdin,
28
+ output: process.stdout
29
+ });
30
+
31
+ const ANSWERS: Answers = {};
32
+
33
+ const QUESTIONS: Array<Question> = [
34
+ {
35
+ text: 'Brand name',
36
+ optional: false,
37
+ answerKey: 'brandName',
38
+ hint: 'eg. Project Zero'
39
+ },
40
+ {
41
+ text: 'Project description',
42
+ optional: true,
43
+ answerKey: 'projectDescription'
44
+ },
45
+ {
46
+ text: 'Commerce URL (SERVICE_BACKEND_URL)',
47
+ optional: true,
48
+ answerKey: 'commerceUrl',
49
+ hint: 'Can be changed later'
50
+ }
51
+ ];
52
+
53
+ const getAnswers = () => {
54
+ return new Promise<Answers>((resolve) => {
55
+ const question = QUESTIONS[Object.keys(ANSWERS).length];
56
+
57
+ if (!question) {
58
+ rl.close();
59
+ resolve(ANSWERS);
60
+ return;
61
+ }
62
+
63
+ let questionText = question.text;
64
+
65
+ if (question.hint) {
66
+ questionText += ` (${question.hint})`;
67
+ }
68
+
69
+ if (question.optional) {
70
+ questionText += ` (optional)`;
71
+ }
72
+
73
+ rl.question(`${questionText}: `, (answer: string) => {
74
+ if (!question.optional && !answer.length) {
75
+ console.log('\x1b[31m%s\x1b[0m', `* This field is required\n`);
76
+ resolve(getAnswers());
77
+ } else {
78
+ ANSWERS[question.answerKey] = answer;
79
+ resolve(getAnswers());
80
+ }
81
+ });
82
+ });
83
+ };
84
+
85
+ const cloneRepository = () =>
86
+ new Promise<{ error?: Error }>((resolve) => {
87
+ exec(
88
+ `cd ${tempDirPath} && git clone git@bitbucket.org:akinonteam/${repositorySlug}.git`,
89
+ function (err: any, stdout: any, stderr: any) {
90
+ if (err != null) {
91
+ resolve({ error: new Error(err) });
92
+ } else if (typeof stderr != 'string') {
93
+ resolve({ error: new Error(stderr) });
94
+ } else {
95
+ resolve({});
96
+ }
97
+ }
98
+ );
99
+ });
100
+
101
+ const updatePackageJson = (brandName: string) => {
102
+ const packageJsonPath = path.resolve(
103
+ tempDirPath,
104
+ `./${repositorySlug}/package.json`
105
+ );
106
+
107
+ const packageJsonData = fs.readFileSync(packageJsonPath, {
108
+ encoding: 'utf8',
109
+ flag: 'r'
110
+ });
111
+
112
+ fs.writeFileSync(
113
+ packageJsonPath,
114
+ packageJsonData.replace(/"name": ".*"/, `"name": "${slugify(brandName)}"`)
115
+ );
116
+ };
117
+
118
+ const updateAkinonJson = (brandName: string, projectDescription: string) => {
119
+ const akinonJsonPath = path.resolve(
120
+ tempDirPath,
121
+ `./${repositorySlug}/akinon.json`
122
+ );
123
+
124
+ const akinonJsonData = fs.readFileSync(akinonJsonPath, {
125
+ encoding: 'utf8',
126
+ flag: 'r'
127
+ });
128
+
129
+ let updatedData = akinonJsonData.replace(
130
+ /"name": ".*"/,
131
+ `"name": "${brandName}"`
132
+ );
133
+
134
+ if (projectDescription) {
135
+ updatedData = updatedData.replace(
136
+ /"description": ".*"/,
137
+ `"description": "${projectDescription}"`
138
+ );
139
+ }
140
+
141
+ fs.writeFileSync(akinonJsonPath, updatedData);
142
+ };
143
+
144
+ const copyEnv = (commerceUrl: string) => {
145
+ const repositoryPath = path.resolve(tempDirPath, `./${repositorySlug}`);
146
+
147
+ const envExamplePath = path.resolve(repositoryPath, `./.env.example`);
148
+ const envPath = path.resolve(repositoryPath, `./.env`);
149
+
150
+ const envData = fs.readFileSync(envExamplePath, {
151
+ encoding: 'utf8',
152
+ flag: 'r'
153
+ });
154
+
155
+ if (commerceUrl) {
156
+ fs.writeFileSync(
157
+ envExamplePath,
158
+ envData.replace(
159
+ /SERVICE_BACKEND_URL=.*/,
160
+ `SERVICE_BACKEND_URL=${commerceUrl}`
161
+ )
162
+ );
163
+ }
164
+
165
+ fs.copyFileSync(envExamplePath, envPath);
166
+ };
167
+
168
+ const updatePlugins = () => {
169
+ const pluginsPath = path.resolve(
170
+ tempDirPath,
171
+ `./${repositorySlug}/src/plugins.js`
172
+ );
173
+
174
+ fs.writeFileSync(pluginsPath, 'module.exports = [];');
175
+ };
176
+
177
+ export default async () => {
178
+ const minNodeVersion = 18;
179
+ const currentNodeVersion = parseInt(
180
+ process.version.replace('v', '').split('.')[0]
181
+ );
182
+
183
+ if (currentNodeVersion < minNodeVersion) {
184
+ console.log(
185
+ '\x1b[31m%s\x1b[0m',
186
+ `Node version must be ${minNodeVersion} or higher.\n`.concat(
187
+ `Current version is ${currentNodeVersion}. Please update your Node version.`
188
+ )
189
+ );
190
+
191
+ process.exit(1);
192
+ }
193
+
194
+ const answers = await getAnswers();
195
+
196
+ const brandName =
197
+ answers.brandName === '.'
198
+ ? path.basename(process.cwd())
199
+ : answers.brandName;
200
+
201
+ loadingSpinner.start();
202
+
203
+ await cloneRepository();
204
+ updatePackageJson(brandName);
205
+ updateAkinonJson(brandName, answers.projectDescription);
206
+ copyEnv(answers.commerceUrl);
207
+ updatePlugins();
208
+
209
+ const slugifiedBrandName = slugify(answers.brandName);
210
+
211
+ fs.rmSync(path.resolve(tempDirPath, `./${repositorySlug}/.git`), {
212
+ recursive: true,
213
+ force: true
214
+ });
215
+
216
+ fs.cpSync(
217
+ path.resolve(tempDirPath, `./${repositorySlug}`),
218
+ path.resolve(workingDir, `./${slugifiedBrandName}`),
219
+ {
220
+ recursive: true,
221
+ force: true
222
+ }
223
+ );
224
+
225
+ temp.cleanupSync();
226
+
227
+ loadingSpinner.stop();
228
+
229
+ console.log(
230
+ '\x1b[32m%s\x1b[0m',
231
+ `\n ✓ ${answers.brandName} project is ready.\n`
232
+ );
233
+
234
+ console.log('\x1b[33m%s\x1b[0m', 'Project Zero - Akinon\n');
235
+ };
package/commands/index.ts CHANGED
@@ -1,15 +1,15 @@
1
- import commerceUrl from './commerce-url';
2
- import create from './create';
3
- import addLanguage from './add-language';
4
- import removeLanguage from './remove-language';
5
- import defaultLanguage from './default-language';
6
- import plugins from './plugins';
7
-
8
- export default {
9
- commerceUrl,
10
- create,
11
- addLanguage,
12
- removeLanguage,
13
- defaultLanguage,
14
- plugins
15
- };
1
+ import commerceUrl from './commerce-url';
2
+ import create from './create';
3
+ import addLanguage from './add-language';
4
+ import removeLanguage from './remove-language';
5
+ import defaultLanguage from './default-language';
6
+ import plugins from './plugins';
7
+
8
+ export default {
9
+ commerceUrl,
10
+ create,
11
+ addLanguage,
12
+ removeLanguage,
13
+ defaultLanguage,
14
+ plugins
15
+ };
@@ -1,98 +1,98 @@
1
- import * as fs from 'fs';
2
- import path from 'path';
3
- import { execSync } from 'child_process';
4
-
5
- const Prompt = require('prompt-checkbox');
6
-
7
- const rootDir = path.resolve(process.cwd());
8
- const pluginsFilePath = path.resolve(rootDir, './src/plugins.js');
9
-
10
- let installedPlugins: Array<string> = [];
11
-
12
- try {
13
- installedPlugins = require(path.resolve(rootDir, './src/plugins.js'));
14
- } catch (error) {}
15
-
16
- const definedPlugins = [
17
- {
18
- name: 'Basket Gift Pack',
19
- value: 'pz-basket-gift-pack'
20
- },
21
- {
22
- name: 'Click & Collect',
23
- value: 'pz-click-collect'
24
- },
25
- {
26
- name: 'Checkout Gift Pack',
27
- value: 'pz-checkout-gift-pack'
28
- },
29
- {
30
- name: 'One Click Checkout',
31
- value: 'pz-one-click-checkout'
32
- },
33
- {
34
- name: 'Garanti Pay',
35
- value: 'pz-gpay'
36
- },
37
- {
38
- name: 'Pay On Delivery',
39
- value: 'pz-pay-on-delivery'
40
- },
41
- {
42
- name: 'Otp',
43
- value: 'pz-otp'
44
- },
45
- {
46
- name: 'BKM Express',
47
- value: 'pz-bkm'
48
- }
49
- ];
50
-
51
- export default async () => {
52
- const prompt = new Prompt({
53
- name: 'plugins',
54
- message: 'Please check/uncheck plugins to install/uninstall.',
55
- type: 'checkbox',
56
- default: installedPlugins.map((p) =>
57
- definedPlugins.findIndex((dp) => dp.value === p)
58
- ),
59
- choices: definedPlugins.map((p, index) => `${index + 1}) ${p.name}`)
60
- });
61
-
62
- prompt.ask(async (answers: Array<string>) => {
63
- const formattedAnswers = answers.map((answer) =>
64
- answer.replace(/\d\)\s/, '')
65
- );
66
-
67
- const values = formattedAnswers.map(
68
- (answer) => definedPlugins.find((p) => p.name === answer)?.value
69
- );
70
-
71
- if (formattedAnswers.length) {
72
- console.log(`\nInstalling ${formattedAnswers.join(', ')}.`);
73
- } else {
74
- console.log(`\nUninstalling all plugins.`);
75
- }
76
-
77
- console.log(`\nPlease wait...`);
78
-
79
- fs.writeFileSync(
80
- pluginsFilePath,
81
- `module.exports = ${JSON.stringify(values)};\n`,
82
- {
83
- encoding: 'utf-8'
84
- }
85
- );
86
-
87
- execSync('yarn install', { stdio: 'pipe' });
88
-
89
- console.log(
90
- '\x1b[32m%s\x1b[0m',
91
- `\n ✓ ${
92
- formattedAnswers.length
93
- ? 'Installed selected plugins'
94
- : 'Uninstalled all plugins'
95
- }.\n`
96
- );
97
- });
98
- };
1
+ import * as fs from 'fs';
2
+ import path from 'path';
3
+ import { execSync } from 'child_process';
4
+
5
+ const Prompt = require('prompt-checkbox');
6
+
7
+ const rootDir = path.resolve(process.cwd());
8
+ const pluginsFilePath = path.resolve(rootDir, './src/plugins.js');
9
+
10
+ let installedPlugins: Array<string> = [];
11
+
12
+ try {
13
+ installedPlugins = require(path.resolve(rootDir, './src/plugins.js'));
14
+ } catch (error) {}
15
+
16
+ const definedPlugins = [
17
+ {
18
+ name: 'Basket Gift Pack',
19
+ value: 'pz-basket-gift-pack'
20
+ },
21
+ {
22
+ name: 'Click & Collect',
23
+ value: 'pz-click-collect'
24
+ },
25
+ {
26
+ name: 'Checkout Gift Pack',
27
+ value: 'pz-checkout-gift-pack'
28
+ },
29
+ {
30
+ name: 'One Click Checkout',
31
+ value: 'pz-one-click-checkout'
32
+ },
33
+ {
34
+ name: 'Garanti Pay',
35
+ value: 'pz-gpay'
36
+ },
37
+ {
38
+ name: 'Pay On Delivery',
39
+ value: 'pz-pay-on-delivery'
40
+ },
41
+ {
42
+ name: 'Otp',
43
+ value: 'pz-otp'
44
+ },
45
+ {
46
+ name: 'BKM Express',
47
+ value: 'pz-bkm'
48
+ }
49
+ ];
50
+
51
+ export default async () => {
52
+ const prompt = new Prompt({
53
+ name: 'plugins',
54
+ message: 'Please check/uncheck plugins to install/uninstall.',
55
+ type: 'checkbox',
56
+ default: installedPlugins.map((p) =>
57
+ definedPlugins.findIndex((dp) => dp.value === p)
58
+ ),
59
+ choices: definedPlugins.map((p, index) => `${index + 1}) ${p.name}`)
60
+ });
61
+
62
+ prompt.ask(async (answers: Array<string>) => {
63
+ const formattedAnswers = answers.map((answer) =>
64
+ answer.replace(/\d\)\s/, '')
65
+ );
66
+
67
+ const values = formattedAnswers.map(
68
+ (answer) => definedPlugins.find((p) => p.name === answer)?.value
69
+ );
70
+
71
+ if (formattedAnswers.length) {
72
+ console.log(`\nInstalling ${formattedAnswers.join(', ')}.`);
73
+ } else {
74
+ console.log(`\nUninstalling all plugins.`);
75
+ }
76
+
77
+ console.log(`\nPlease wait...`);
78
+
79
+ fs.writeFileSync(
80
+ pluginsFilePath,
81
+ `module.exports = ${JSON.stringify(values)};\n`,
82
+ {
83
+ encoding: 'utf-8'
84
+ }
85
+ );
86
+
87
+ execSync('yarn install', { stdio: 'pipe' });
88
+
89
+ console.log(
90
+ '\x1b[32m%s\x1b[0m',
91
+ `\n ✓ ${
92
+ formattedAnswers.length
93
+ ? 'Installed selected plugins'
94
+ : 'Uninstalled all plugins'
95
+ }.\n`
96
+ );
97
+ });
98
+ };
@@ -1,75 +1,75 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const fs = require("fs");
5
- const path = require("path");
6
- const argv = require("yargs").argv;
7
- exports.default = () => {
8
- /**
9
- * @param {string} src The path to the thing to copy.
10
- * @param {string} dest The path to the new copy.
11
- * @param {string} lng Get Language
12
- */
13
- const addLanguage = (src, dest, lng) => {
14
- const exists = fs.existsSync(src);
15
- const stats = exists && fs.statSync(src);
16
- const isDirectory = exists && stats.isDirectory();
17
- if (isDirectory) {
18
- fs.mkdirSync(dest);
19
- fs.readdirSync(src).forEach((childItemName) => {
20
- addLanguage(path.join(src, childItemName), path.join(dest, childItemName), lng);
21
- });
22
- console.log("\x1b[32m%s\x1b[0m", `\n✓ Added language option ${lng.toUpperCase()}.\nDon't forget to translate '${lng.toUpperCase()}' translation files inside 'public/locales/${lng.toUpperCase()}'\n`);
23
- console.log("\x1b[33m%s\x1b[0m", "Project Zero - Akinon\n");
24
- }
25
- else {
26
- fs.copyFileSync(src, dest);
27
- }
28
- };
29
- const i18nDocumentUpdate = (lng) => {
30
- /* next-i18next.config.js */
31
- const workingDir = path.resolve(process.cwd());
32
- const i18nPath = path.resolve(workingDir, "next-i18next.config.js");
33
- if (!fs.existsSync(i18nPath)) {
34
- return;
35
- }
36
- const i18nData = fs.readFileSync(i18nPath, {
37
- encoding: "utf8",
38
- flag: "r",
39
- });
40
- fs.writeFileSync(i18nPath, i18nData.replace(/locales: '*.'/, `locales: ['${lng}', '`));
41
- /* settings.js */
42
- const settingsPath = path.resolve(workingDir, "src/settings.js");
43
- if (!fs.existsSync(settingsPath)) {
44
- return;
45
- }
46
- const settingsData = fs.readFileSync(settingsPath, {
47
- encoding: "utf8",
48
- flag: "r",
49
- });
50
- const data = `{ label: '${lng.toUpperCase()}', value: '${lng.toLowerCase()}', apiValue: '${argv.addLanguage}' }`;
51
- const changes = "languages: [";
52
- fs.writeFileSync(settingsPath, settingsData.replace(changes, `languages: [\n\t\t${data},`));
53
- };
54
- const init = () => {
55
- if (!argv.addLanguage)
56
- return;
57
- let lng = argv.addLanguage;
58
- lng = lng.split("-")[0];
59
- const dest = `public/locales/${lng}`;
60
- const exists = fs.existsSync(dest);
61
- try {
62
- if (exists)
63
- throw new Error(`${lng.toUpperCase()} has already been added`);
64
- addLanguage("public/locales/en", `public/locales/${lng}`, lng);
65
- i18nDocumentUpdate(lng);
66
- }
67
- catch (err) {
68
- const typedError = err;
69
- console.log("\n\x1b[31m%s\x1b[0m", `${typedError.message
70
- ? typedError.message + "\n"
71
- : "Something went wrong.\n"}`);
72
- }
73
- };
74
- init();
75
- };
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ const argv = require("yargs").argv;
7
+ exports.default = () => {
8
+ /**
9
+ * @param {string} src The path to the thing to copy.
10
+ * @param {string} dest The path to the new copy.
11
+ * @param {string} lng Get Language
12
+ */
13
+ const addLanguage = (src, dest, lng) => {
14
+ const exists = fs.existsSync(src);
15
+ const stats = exists && fs.statSync(src);
16
+ const isDirectory = exists && stats.isDirectory();
17
+ if (isDirectory) {
18
+ fs.mkdirSync(dest);
19
+ fs.readdirSync(src).forEach((childItemName) => {
20
+ addLanguage(path.join(src, childItemName), path.join(dest, childItemName), lng);
21
+ });
22
+ console.log("\x1b[32m%s\x1b[0m", `\n✓ Added language option ${lng.toUpperCase()}.\nDon't forget to translate '${lng.toUpperCase()}' translation files inside 'public/locales/${lng.toUpperCase()}'\n`);
23
+ console.log("\x1b[33m%s\x1b[0m", "Project Zero - Akinon\n");
24
+ }
25
+ else {
26
+ fs.copyFileSync(src, dest);
27
+ }
28
+ };
29
+ const i18nDocumentUpdate = (lng) => {
30
+ /* next-i18next.config.js */
31
+ const workingDir = path.resolve(process.cwd());
32
+ const i18nPath = path.resolve(workingDir, "next-i18next.config.js");
33
+ if (!fs.existsSync(i18nPath)) {
34
+ return;
35
+ }
36
+ const i18nData = fs.readFileSync(i18nPath, {
37
+ encoding: "utf8",
38
+ flag: "r",
39
+ });
40
+ fs.writeFileSync(i18nPath, i18nData.replace(/locales: '*.'/, `locales: ['${lng}', '`));
41
+ /* settings.js */
42
+ const settingsPath = path.resolve(workingDir, "src/settings.js");
43
+ if (!fs.existsSync(settingsPath)) {
44
+ return;
45
+ }
46
+ const settingsData = fs.readFileSync(settingsPath, {
47
+ encoding: "utf8",
48
+ flag: "r",
49
+ });
50
+ const data = `{ label: '${lng.toUpperCase()}', value: '${lng.toLowerCase()}', apiValue: '${argv.addLanguage}' }`;
51
+ const changes = "languages: [";
52
+ fs.writeFileSync(settingsPath, settingsData.replace(changes, `languages: [\n\t\t${data},`));
53
+ };
54
+ const init = () => {
55
+ if (!argv.addLanguage)
56
+ return;
57
+ let lng = argv.addLanguage;
58
+ lng = lng.split("-")[0];
59
+ const dest = `public/locales/${lng}`;
60
+ const exists = fs.existsSync(dest);
61
+ try {
62
+ if (exists)
63
+ throw new Error(`${lng.toUpperCase()} has already been added`);
64
+ addLanguage("public/locales/en", `public/locales/${lng}`, lng);
65
+ i18nDocumentUpdate(lng);
66
+ }
67
+ catch (err) {
68
+ const typedError = err;
69
+ console.log("\n\x1b[31m%s\x1b[0m", `${typedError.message
70
+ ? typedError.message + "\n"
71
+ : "Something went wrong.\n"}`);
72
+ }
73
+ };
74
+ init();
75
+ };
@@ -1,45 +1,45 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const fs = require("fs");
5
- const path = require("path");
6
- const argv = require("yargs").argv;
7
- exports.default = () => {
8
- const i18nDocumentUpdate = (lng) => {
9
- /* next-i18next.config.js */
10
- const workingDir = path.resolve(process.cwd());
11
- const i18nPath = path.resolve(workingDir, "next-i18next.config.js");
12
- if (!fs.existsSync(i18nPath)) {
13
- return;
14
- }
15
- const i18nData = fs.readFileSync(i18nPath, {
16
- encoding: "utf8",
17
- flag: "r",
18
- });
19
- const regExpLiteral = "locales:(.+)+";
20
- const result = i18nData.match(regExpLiteral);
21
- if (result[1].search(lng) < 0) {
22
- throw new Error(`${lng.toUpperCase()} not available`);
23
- }
24
- let updatedData = i18nData.replace(/defaultLocale: '.*'/, `defaultLocale: '${lng}'`);
25
- updatedData = updatedData.replace(/fallbackLng: '.*'/, `fallbackLng: '${lng}'`);
26
- fs.writeFileSync(i18nPath, updatedData);
27
- };
28
- const init = () => {
29
- if (!argv.defaultLanguage)
30
- return;
31
- let lng = argv.defaultLanguage;
32
- try {
33
- i18nDocumentUpdate(lng);
34
- console.log("\x1b[32m%s\x1b[0m", `\n✓ Set as the default language option ${lng.toUpperCase()}.\n`);
35
- console.log("\x1b[33m%s\x1b[0m", "Project Zero - Akinon\n");
36
- }
37
- catch (err) {
38
- const typedError = err;
39
- console.log("\n\x1b[31m%s\x1b[0m", `${typedError.message
40
- ? typedError.message + "\n"
41
- : "Something went wrong.\n"}`);
42
- }
43
- };
44
- init();
45
- };
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ const argv = require("yargs").argv;
7
+ exports.default = () => {
8
+ const i18nDocumentUpdate = (lng) => {
9
+ /* next-i18next.config.js */
10
+ const workingDir = path.resolve(process.cwd());
11
+ const i18nPath = path.resolve(workingDir, "next-i18next.config.js");
12
+ if (!fs.existsSync(i18nPath)) {
13
+ return;
14
+ }
15
+ const i18nData = fs.readFileSync(i18nPath, {
16
+ encoding: "utf8",
17
+ flag: "r",
18
+ });
19
+ const regExpLiteral = "locales:(.+)+";
20
+ const result = i18nData.match(regExpLiteral);
21
+ if (result[1].search(lng) < 0) {
22
+ throw new Error(`${lng.toUpperCase()} not available`);
23
+ }
24
+ let updatedData = i18nData.replace(/defaultLocale: '.*'/, `defaultLocale: '${lng}'`);
25
+ updatedData = updatedData.replace(/fallbackLng: '.*'/, `fallbackLng: '${lng}'`);
26
+ fs.writeFileSync(i18nPath, updatedData);
27
+ };
28
+ const init = () => {
29
+ if (!argv.defaultLanguage)
30
+ return;
31
+ let lng = argv.defaultLanguage;
32
+ try {
33
+ i18nDocumentUpdate(lng);
34
+ console.log("\x1b[32m%s\x1b[0m", `\n✓ Set as the default language option ${lng.toUpperCase()}.\n`);
35
+ console.log("\x1b[33m%s\x1b[0m", "Project Zero - Akinon\n");
36
+ }
37
+ catch (err) {
38
+ const typedError = err;
39
+ console.log("\n\x1b[31m%s\x1b[0m", `${typedError.message
40
+ ? typedError.message + "\n"
41
+ : "Something went wrong.\n"}`);
42
+ }
43
+ };
44
+ init();
45
+ };
@@ -1,65 +1,65 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const fs = require("fs");
5
- const path = require("path");
6
- const argv = require("yargs").argv;
7
- exports.default = () => {
8
- /**
9
- * @param {string} lng Get Language
10
- */
11
- const removeLanguage = (lng) => {
12
- const workingDir = path.resolve(process.cwd());
13
- try {
14
- fs.rm(`public/locales/${lng}`, { recursive: true }, (err) => {
15
- if (err) {
16
- console.error(err);
17
- return;
18
- }
19
- });
20
- }
21
- catch (error) {
22
- console.log("error", error);
23
- }
24
- /* settings.js */
25
- const settingsPath = path.resolve(workingDir, "src/settings.js");
26
- if (!fs.existsSync(settingsPath)) {
27
- return;
28
- }
29
- const settingsData = fs.readFileSync(settingsPath, {
30
- encoding: "utf8",
31
- flag: "r",
32
- });
33
- const data = `{ label: '${lng.toUpperCase()}', value: '${lng.toLowerCase()}', apiValue: '${lng.toLowerCase()}-${lng.toLowerCase()}' },`;
34
- let updatedData = settingsData.replace(data.toString(), "");
35
- updatedData = updatedData.replace(/^\s*$(?:\r\n?|\n)/gm, "");
36
- fs.writeFileSync(settingsPath, updatedData);
37
- /* next-i18next.config.js */
38
- const i18nPath = path.resolve(workingDir, "next-i18next.config.js");
39
- if (!fs.existsSync(i18nPath)) {
40
- return;
41
- }
42
- const i18nData = fs.readFileSync(i18nPath, {
43
- encoding: "utf8",
44
- flag: "r",
45
- });
46
- fs.writeFileSync(i18nPath, i18nData.replace(`'${lng}',\u0020`, ""));
47
- console.log("\x1b[32m%s\x1b[0m", `\n✓ Remove language option ${lng.toUpperCase()}.\n`);
48
- console.log("\x1b[33m%s\x1b[0m", "Project Zero - Akinon\n");
49
- };
50
- const init = () => {
51
- if (!argv.removeLanguage)
52
- return;
53
- let lng = argv.removeLanguage;
54
- try {
55
- removeLanguage(lng);
56
- }
57
- catch (err) {
58
- const typedError = err;
59
- console.log("\n\x1b[31m%s\x1b[0m", `${typedError.message
60
- ? typedError.message + "\n"
61
- : "Something went wrong.\n"}`);
62
- }
63
- };
64
- init();
65
- };
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ const argv = require("yargs").argv;
7
+ exports.default = () => {
8
+ /**
9
+ * @param {string} lng Get Language
10
+ */
11
+ const removeLanguage = (lng) => {
12
+ const workingDir = path.resolve(process.cwd());
13
+ try {
14
+ fs.rm(`public/locales/${lng}`, { recursive: true }, (err) => {
15
+ if (err) {
16
+ console.error(err);
17
+ return;
18
+ }
19
+ });
20
+ }
21
+ catch (error) {
22
+ console.log("error", error);
23
+ }
24
+ /* settings.js */
25
+ const settingsPath = path.resolve(workingDir, "src/settings.js");
26
+ if (!fs.existsSync(settingsPath)) {
27
+ return;
28
+ }
29
+ const settingsData = fs.readFileSync(settingsPath, {
30
+ encoding: "utf8",
31
+ flag: "r",
32
+ });
33
+ const data = `{ label: '${lng.toUpperCase()}', value: '${lng.toLowerCase()}', apiValue: '${lng.toLowerCase()}-${lng.toLowerCase()}' },`;
34
+ let updatedData = settingsData.replace(data.toString(), "");
35
+ updatedData = updatedData.replace(/^\s*$(?:\r\n?|\n)/gm, "");
36
+ fs.writeFileSync(settingsPath, updatedData);
37
+ /* next-i18next.config.js */
38
+ const i18nPath = path.resolve(workingDir, "next-i18next.config.js");
39
+ if (!fs.existsSync(i18nPath)) {
40
+ return;
41
+ }
42
+ const i18nData = fs.readFileSync(i18nPath, {
43
+ encoding: "utf8",
44
+ flag: "r",
45
+ });
46
+ fs.writeFileSync(i18nPath, i18nData.replace(`'${lng}',\u0020`, ""));
47
+ console.log("\x1b[32m%s\x1b[0m", `\n✓ Remove language option ${lng.toUpperCase()}.\n`);
48
+ console.log("\x1b[33m%s\x1b[0m", "Project Zero - Akinon\n");
49
+ };
50
+ const init = () => {
51
+ if (!argv.removeLanguage)
52
+ return;
53
+ let lng = argv.removeLanguage;
54
+ try {
55
+ removeLanguage(lng);
56
+ }
57
+ catch (err) {
58
+ const typedError = err;
59
+ console.log("\n\x1b[31m%s\x1b[0m", `${typedError.message
60
+ ? typedError.message + "\n"
61
+ : "Something went wrong.\n"}`);
62
+ }
63
+ };
64
+ init();
65
+ };
package/dist/utils.js CHANGED
@@ -1,12 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.slugify = void 0;
4
- const slugify = (text) => {
5
- text = text.replace(/^[A-Z]/g, (letter) => letter.toLowerCase());
6
- text = text.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
7
- return text
8
- .toLowerCase()
9
- .replace(/[\s_]+/g, "-")
10
- .replace(/[^a-z0-9-_]/g, "");
11
- };
12
- exports.slugify = slugify;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.slugify = void 0;
4
+ const slugify = (text) => {
5
+ text = text.replace(/^[A-Z]/g, (letter) => letter.toLowerCase());
6
+ text = text.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
7
+ return text
8
+ .toLowerCase()
9
+ .replace(/[\s_]+/g, "-")
10
+ .replace(/[^a-z0-9-_]/g, "");
11
+ };
12
+ exports.slugify = slugify;
package/index.ts CHANGED
@@ -1,15 +1,15 @@
1
- #! /usr/bin/env node
2
-
3
- import commands from './commands';
4
-
5
- const yargs = require('yargs/yargs');
6
- const { hideBin } = require('yargs/helpers');
7
- const args = yargs(hideBin(process.argv)).argv;
8
-
9
- (() => {
10
- Object.keys(args)
11
- .filter((arg) => (commands as any)[arg])
12
- .forEach((arg) => {
13
- (commands as any)[arg]();
14
- });
15
- })();
1
+ #! /usr/bin/env node
2
+
3
+ import commands from './commands';
4
+
5
+ const yargs = require('yargs/yargs');
6
+ const { hideBin } = require('yargs/helpers');
7
+ const args = yargs(hideBin(process.argv)).argv;
8
+
9
+ (() => {
10
+ Object.keys(args)
11
+ .filter((arg) => (commands as any)[arg])
12
+ .forEach((arg) => {
13
+ (commands as any)[arg]();
14
+ });
15
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/projectzero",
3
- "version": "1.14.0",
3
+ "version": "1.14.1",
4
4
  "private": false,
5
5
  "description": "CLI tool to manage your Project Zero Next project",
6
6
  "bin": {