@akinon/projectzero 1.13.0 → 1.14.0
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 +12 -12
- package/CHANGELOG.md +4 -0
- package/README.md +17 -17
- package/commands/add-language.ts +111 -111
- package/commands/commerce-url.ts +33 -33
- package/commands/create.ts +235 -235
- package/commands/default-language.ts +70 -70
- package/commands/index.ts +15 -15
- package/commands/plugins.ts +98 -98
- package/commands/remove-language.ts +91 -91
- package/dist/index.js +0 -0
- package/index.ts +15 -15
- package/package.json +1 -1
- package/tsconfig.json +103 -103
- package/utils.ts +9 -9
package/commands/create.ts
CHANGED
|
@@ -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
|
+
};
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
|
|
6
|
-
const argv = require("yargs").argv;
|
|
7
|
-
|
|
8
|
-
export default () => {
|
|
9
|
-
const i18nDocumentUpdate = (lng: string) => {
|
|
10
|
-
/* next-i18next.config.js */
|
|
11
|
-
const workingDir = path.resolve(process.cwd());
|
|
12
|
-
const i18nPath = path.resolve(workingDir, "next-i18next.config.js");
|
|
13
|
-
|
|
14
|
-
if (!fs.existsSync(i18nPath)) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const i18nData = fs.readFileSync(i18nPath, {
|
|
19
|
-
encoding: "utf8",
|
|
20
|
-
flag: "r",
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const regExpLiteral = "locales:(.+)+";
|
|
24
|
-
|
|
25
|
-
const result = i18nData.match(regExpLiteral);
|
|
26
|
-
|
|
27
|
-
if (result[1].search(lng) < 0) {
|
|
28
|
-
throw new Error(`${lng.toUpperCase()} not available`);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
let updatedData = i18nData.replace(
|
|
32
|
-
/defaultLocale: '.*'/,
|
|
33
|
-
`defaultLocale: '${lng}'`
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
updatedData = updatedData.replace(
|
|
37
|
-
/fallbackLng: '.*'/,
|
|
38
|
-
`fallbackLng: '${lng}'`
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
fs.writeFileSync(i18nPath, updatedData);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const init = () => {
|
|
45
|
-
if (!argv.defaultLanguage) return;
|
|
46
|
-
let lng = argv.defaultLanguage;
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
i18nDocumentUpdate(lng);
|
|
50
|
-
console.log(
|
|
51
|
-
"\x1b[32m%s\x1b[0m",
|
|
52
|
-
`\n✓ Set as the default language option ${lng.toUpperCase()}.\n`
|
|
53
|
-
);
|
|
54
|
-
console.log("\x1b[33m%s\x1b[0m", "Project Zero - Akinon\n");
|
|
55
|
-
} catch (err) {
|
|
56
|
-
const typedError = err as Error;
|
|
57
|
-
|
|
58
|
-
console.log(
|
|
59
|
-
"\n\x1b[31m%s\x1b[0m",
|
|
60
|
-
`${
|
|
61
|
-
typedError.message
|
|
62
|
-
? typedError.message + "\n"
|
|
63
|
-
: "Something went wrong.\n"
|
|
64
|
-
}`
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
init();
|
|
70
|
-
};
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
const argv = require("yargs").argv;
|
|
7
|
+
|
|
8
|
+
export default () => {
|
|
9
|
+
const i18nDocumentUpdate = (lng: string) => {
|
|
10
|
+
/* next-i18next.config.js */
|
|
11
|
+
const workingDir = path.resolve(process.cwd());
|
|
12
|
+
const i18nPath = path.resolve(workingDir, "next-i18next.config.js");
|
|
13
|
+
|
|
14
|
+
if (!fs.existsSync(i18nPath)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const i18nData = fs.readFileSync(i18nPath, {
|
|
19
|
+
encoding: "utf8",
|
|
20
|
+
flag: "r",
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const regExpLiteral = "locales:(.+)+";
|
|
24
|
+
|
|
25
|
+
const result = i18nData.match(regExpLiteral);
|
|
26
|
+
|
|
27
|
+
if (result[1].search(lng) < 0) {
|
|
28
|
+
throw new Error(`${lng.toUpperCase()} not available`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let updatedData = i18nData.replace(
|
|
32
|
+
/defaultLocale: '.*'/,
|
|
33
|
+
`defaultLocale: '${lng}'`
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
updatedData = updatedData.replace(
|
|
37
|
+
/fallbackLng: '.*'/,
|
|
38
|
+
`fallbackLng: '${lng}'`
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
fs.writeFileSync(i18nPath, updatedData);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const init = () => {
|
|
45
|
+
if (!argv.defaultLanguage) return;
|
|
46
|
+
let lng = argv.defaultLanguage;
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
i18nDocumentUpdate(lng);
|
|
50
|
+
console.log(
|
|
51
|
+
"\x1b[32m%s\x1b[0m",
|
|
52
|
+
`\n✓ Set as the default language option ${lng.toUpperCase()}.\n`
|
|
53
|
+
);
|
|
54
|
+
console.log("\x1b[33m%s\x1b[0m", "Project Zero - Akinon\n");
|
|
55
|
+
} catch (err) {
|
|
56
|
+
const typedError = err as Error;
|
|
57
|
+
|
|
58
|
+
console.log(
|
|
59
|
+
"\n\x1b[31m%s\x1b[0m",
|
|
60
|
+
`${
|
|
61
|
+
typedError.message
|
|
62
|
+
? typedError.message + "\n"
|
|
63
|
+
: "Something went wrong.\n"
|
|
64
|
+
}`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
init();
|
|
70
|
+
};
|
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
|
+
};
|