@akinon/projectzero 1.10.0 → 1.12.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/CHANGELOG.md +4 -0
- package/commands/create.ts +25 -34
- package/commands/plugins.ts +4 -0
- package/dist/commands/create.js +16 -17
- package/dist/commands/plugins.js +4 -0
- package/package.json +6 -4
package/CHANGELOG.md
CHANGED
package/commands/create.ts
CHANGED
|
@@ -2,11 +2,13 @@ import path from 'path';
|
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import * as readline from 'readline';
|
|
4
4
|
import { slugify } from '../utils';
|
|
5
|
-
import
|
|
5
|
+
import temp from 'temp';
|
|
6
6
|
|
|
7
7
|
const exec = require('child_process').exec;
|
|
8
8
|
const loadingSpinner = require('loading-spinner');
|
|
9
9
|
|
|
10
|
+
temp.track();
|
|
11
|
+
|
|
10
12
|
interface Question {
|
|
11
13
|
text: string;
|
|
12
14
|
optional: boolean;
|
|
@@ -19,7 +21,7 @@ interface Answers {
|
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
const repositorySlug = 'projectzeropwa';
|
|
22
|
-
const
|
|
24
|
+
const tempDirPath = temp.mkdirSync('pz-temp');
|
|
23
25
|
const workingDir = path.resolve(process.cwd());
|
|
24
26
|
const rl = readline.createInterface({
|
|
25
27
|
input: process.stdin,
|
|
@@ -82,10 +84,8 @@ const getAnswers = () => {
|
|
|
82
84
|
|
|
83
85
|
const cloneRepository = () =>
|
|
84
86
|
new Promise<{ error?: Error }>((resolve) => {
|
|
85
|
-
execSync(`mkdir ${tempDirName}`);
|
|
86
|
-
|
|
87
87
|
exec(
|
|
88
|
-
`cd ${
|
|
88
|
+
`cd ${tempDirPath} && git clone git@bitbucket.org:akinonteam/${repositorySlug}.git`,
|
|
89
89
|
function (err: any, stdout: any, stderr: any) {
|
|
90
90
|
if (err != null) {
|
|
91
91
|
resolve({ error: new Error(err) });
|
|
@@ -100,8 +100,8 @@ const cloneRepository = () =>
|
|
|
100
100
|
|
|
101
101
|
const updatePackageJson = (brandName: string) => {
|
|
102
102
|
const packageJsonPath = path.resolve(
|
|
103
|
-
|
|
104
|
-
`./${
|
|
103
|
+
tempDirPath,
|
|
104
|
+
`./${repositorySlug}/package.json`
|
|
105
105
|
);
|
|
106
106
|
|
|
107
107
|
const packageJsonData = fs.readFileSync(packageJsonPath, {
|
|
@@ -117,8 +117,8 @@ const updatePackageJson = (brandName: string) => {
|
|
|
117
117
|
|
|
118
118
|
const updateAkinonJson = (brandName: string, projectDescription: string) => {
|
|
119
119
|
const akinonJsonPath = path.resolve(
|
|
120
|
-
|
|
121
|
-
`./${
|
|
120
|
+
tempDirPath,
|
|
121
|
+
`./${repositorySlug}/akinon.json`
|
|
122
122
|
);
|
|
123
123
|
|
|
124
124
|
const akinonJsonData = fs.readFileSync(akinonJsonPath, {
|
|
@@ -142,10 +142,7 @@ const updateAkinonJson = (brandName: string, projectDescription: string) => {
|
|
|
142
142
|
};
|
|
143
143
|
|
|
144
144
|
const copyEnv = (commerceUrl: string) => {
|
|
145
|
-
const repositoryPath = path.resolve(
|
|
146
|
-
workingDir,
|
|
147
|
-
`./${tempDirName}/${repositorySlug}`
|
|
148
|
-
);
|
|
145
|
+
const repositoryPath = path.resolve(tempDirPath, `./${repositorySlug}`);
|
|
149
146
|
|
|
150
147
|
const envExamplePath = path.resolve(repositoryPath, `./.env.example`);
|
|
151
148
|
const envPath = path.resolve(repositoryPath, `./.env`);
|
|
@@ -170,8 +167,8 @@ const copyEnv = (commerceUrl: string) => {
|
|
|
170
167
|
|
|
171
168
|
const updatePlugins = () => {
|
|
172
169
|
const pluginsPath = path.resolve(
|
|
173
|
-
|
|
174
|
-
`./${
|
|
170
|
+
tempDirPath,
|
|
171
|
+
`./${repositorySlug}/src/plugins.js`
|
|
175
172
|
);
|
|
176
173
|
|
|
177
174
|
fs.writeFileSync(pluginsPath, 'module.exports = [];');
|
|
@@ -196,31 +193,28 @@ export default async () => {
|
|
|
196
193
|
|
|
197
194
|
const answers = await getAnswers();
|
|
198
195
|
|
|
196
|
+
const brandName =
|
|
197
|
+
answers.brandName === '.'
|
|
198
|
+
? path.basename(process.cwd())
|
|
199
|
+
: answers.brandName;
|
|
200
|
+
|
|
199
201
|
loadingSpinner.start();
|
|
200
202
|
|
|
201
203
|
await cloneRepository();
|
|
202
|
-
updatePackageJson(
|
|
203
|
-
updateAkinonJson(
|
|
204
|
+
updatePackageJson(brandName);
|
|
205
|
+
updateAkinonJson(brandName, answers.projectDescription);
|
|
204
206
|
copyEnv(answers.commerceUrl);
|
|
205
207
|
updatePlugins();
|
|
206
208
|
|
|
207
209
|
const slugifiedBrandName = slugify(answers.brandName);
|
|
208
210
|
|
|
209
|
-
fs.rmSync(
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
force: true
|
|
214
|
-
}
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
fs.renameSync(
|
|
218
|
-
path.resolve(workingDir, `./${tempDirName}/${repositorySlug}`),
|
|
219
|
-
path.resolve(workingDir, `./${tempDirName}/${slugifiedBrandName}`)
|
|
220
|
-
);
|
|
211
|
+
fs.rmSync(path.resolve(tempDirPath, `./${repositorySlug}/.git`), {
|
|
212
|
+
recursive: true,
|
|
213
|
+
force: true
|
|
214
|
+
});
|
|
221
215
|
|
|
222
216
|
fs.cpSync(
|
|
223
|
-
path.resolve(
|
|
217
|
+
path.resolve(tempDirPath, `./${repositorySlug}`),
|
|
224
218
|
path.resolve(workingDir, `./${slugifiedBrandName}`),
|
|
225
219
|
{
|
|
226
220
|
recursive: true,
|
|
@@ -228,10 +222,7 @@ export default async () => {
|
|
|
228
222
|
}
|
|
229
223
|
);
|
|
230
224
|
|
|
231
|
-
|
|
232
|
-
recursive: true,
|
|
233
|
-
force: true
|
|
234
|
-
});
|
|
225
|
+
temp.cleanupSync();
|
|
235
226
|
|
|
236
227
|
loadingSpinner.stop();
|
|
237
228
|
|
package/commands/plugins.ts
CHANGED
package/dist/commands/create.js
CHANGED
|
@@ -39,11 +39,12 @@ const path_1 = __importDefault(require("path"));
|
|
|
39
39
|
const fs = __importStar(require("fs"));
|
|
40
40
|
const readline = __importStar(require("readline"));
|
|
41
41
|
const utils_1 = require("../utils");
|
|
42
|
-
const
|
|
42
|
+
const temp_1 = __importDefault(require("temp"));
|
|
43
43
|
const exec = require('child_process').exec;
|
|
44
44
|
const loadingSpinner = require('loading-spinner');
|
|
45
|
+
temp_1.default.track();
|
|
45
46
|
const repositorySlug = 'projectzeropwa';
|
|
46
|
-
const
|
|
47
|
+
const tempDirPath = temp_1.default.mkdirSync('pz-temp');
|
|
47
48
|
const workingDir = path_1.default.resolve(process.cwd());
|
|
48
49
|
const rl = readline.createInterface({
|
|
49
50
|
input: process.stdin,
|
|
@@ -97,8 +98,7 @@ const getAnswers = () => {
|
|
|
97
98
|
});
|
|
98
99
|
};
|
|
99
100
|
const cloneRepository = () => new Promise((resolve) => {
|
|
100
|
-
(
|
|
101
|
-
exec(`cd ${tempDirName} && git clone git@bitbucket.org:akinonteam/${repositorySlug}.git`, function (err, stdout, stderr) {
|
|
101
|
+
exec(`cd ${tempDirPath} && git clone git@bitbucket.org:akinonteam/${repositorySlug}.git`, function (err, stdout, stderr) {
|
|
102
102
|
if (err != null) {
|
|
103
103
|
resolve({ error: new Error(err) });
|
|
104
104
|
}
|
|
@@ -111,7 +111,7 @@ const cloneRepository = () => new Promise((resolve) => {
|
|
|
111
111
|
});
|
|
112
112
|
});
|
|
113
113
|
const updatePackageJson = (brandName) => {
|
|
114
|
-
const packageJsonPath = path_1.default.resolve(
|
|
114
|
+
const packageJsonPath = path_1.default.resolve(tempDirPath, `./${repositorySlug}/package.json`);
|
|
115
115
|
const packageJsonData = fs.readFileSync(packageJsonPath, {
|
|
116
116
|
encoding: 'utf8',
|
|
117
117
|
flag: 'r'
|
|
@@ -119,7 +119,7 @@ const updatePackageJson = (brandName) => {
|
|
|
119
119
|
fs.writeFileSync(packageJsonPath, packageJsonData.replace(/"name": ".*"/, `"name": "${(0, utils_1.slugify)(brandName)}"`));
|
|
120
120
|
};
|
|
121
121
|
const updateAkinonJson = (brandName, projectDescription) => {
|
|
122
|
-
const akinonJsonPath = path_1.default.resolve(
|
|
122
|
+
const akinonJsonPath = path_1.default.resolve(tempDirPath, `./${repositorySlug}/akinon.json`);
|
|
123
123
|
const akinonJsonData = fs.readFileSync(akinonJsonPath, {
|
|
124
124
|
encoding: 'utf8',
|
|
125
125
|
flag: 'r'
|
|
@@ -131,7 +131,7 @@ const updateAkinonJson = (brandName, projectDescription) => {
|
|
|
131
131
|
fs.writeFileSync(akinonJsonPath, updatedData);
|
|
132
132
|
};
|
|
133
133
|
const copyEnv = (commerceUrl) => {
|
|
134
|
-
const repositoryPath = path_1.default.resolve(
|
|
134
|
+
const repositoryPath = path_1.default.resolve(tempDirPath, `./${repositorySlug}`);
|
|
135
135
|
const envExamplePath = path_1.default.resolve(repositoryPath, `./.env.example`);
|
|
136
136
|
const envPath = path_1.default.resolve(repositoryPath, `./.env`);
|
|
137
137
|
const envData = fs.readFileSync(envExamplePath, {
|
|
@@ -144,7 +144,7 @@ const copyEnv = (commerceUrl) => {
|
|
|
144
144
|
fs.copyFileSync(envExamplePath, envPath);
|
|
145
145
|
};
|
|
146
146
|
const updatePlugins = () => {
|
|
147
|
-
const pluginsPath = path_1.default.resolve(
|
|
147
|
+
const pluginsPath = path_1.default.resolve(tempDirPath, `./${repositorySlug}/src/plugins.js`);
|
|
148
148
|
fs.writeFileSync(pluginsPath, 'module.exports = [];');
|
|
149
149
|
};
|
|
150
150
|
exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -155,26 +155,25 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
155
155
|
process.exit(1);
|
|
156
156
|
}
|
|
157
157
|
const answers = yield getAnswers();
|
|
158
|
+
const brandName = answers.brandName === '.'
|
|
159
|
+
? path_1.default.basename(process.cwd())
|
|
160
|
+
: answers.brandName;
|
|
158
161
|
loadingSpinner.start();
|
|
159
162
|
yield cloneRepository();
|
|
160
|
-
updatePackageJson(
|
|
161
|
-
updateAkinonJson(
|
|
163
|
+
updatePackageJson(brandName);
|
|
164
|
+
updateAkinonJson(brandName, answers.projectDescription);
|
|
162
165
|
copyEnv(answers.commerceUrl);
|
|
163
166
|
updatePlugins();
|
|
164
167
|
const slugifiedBrandName = (0, utils_1.slugify)(answers.brandName);
|
|
165
|
-
fs.rmSync(path_1.default.resolve(
|
|
168
|
+
fs.rmSync(path_1.default.resolve(tempDirPath, `./${repositorySlug}/.git`), {
|
|
166
169
|
recursive: true,
|
|
167
170
|
force: true
|
|
168
171
|
});
|
|
169
|
-
fs.
|
|
170
|
-
fs.cpSync(path_1.default.resolve(workingDir, `./${tempDirName}/${slugifiedBrandName}`), path_1.default.resolve(workingDir, `./${slugifiedBrandName}`), {
|
|
171
|
-
recursive: true,
|
|
172
|
-
force: true
|
|
173
|
-
});
|
|
174
|
-
fs.rmSync(path_1.default.resolve(workingDir, `./${tempDirName}/`), {
|
|
172
|
+
fs.cpSync(path_1.default.resolve(tempDirPath, `./${repositorySlug}`), path_1.default.resolve(workingDir, `./${slugifiedBrandName}`), {
|
|
175
173
|
recursive: true,
|
|
176
174
|
force: true
|
|
177
175
|
});
|
|
176
|
+
temp_1.default.cleanupSync();
|
|
178
177
|
loadingSpinner.stop();
|
|
179
178
|
console.log('\x1b[32m%s\x1b[0m', `\n ✓ ${answers.brandName} project is ready.\n`);
|
|
180
179
|
console.log('\x1b[33m%s\x1b[0m', 'Project Zero - Akinon\n');
|
package/dist/commands/plugins.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akinon/projectzero",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "CLI tool to manage your Project Zero Next project",
|
|
6
6
|
"bin": {
|
|
@@ -14,11 +14,13 @@
|
|
|
14
14
|
"author": "",
|
|
15
15
|
"license": "ISC",
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@types/node": "^18.8.0"
|
|
17
|
+
"@types/node": "^18.8.0",
|
|
18
|
+
"@types/temp": "0.9.4"
|
|
18
19
|
},
|
|
19
20
|
"dependencies": {
|
|
20
21
|
"loading-spinner": "^1.2.1",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
22
|
+
"prompt-checkbox": "2.2.0",
|
|
23
|
+
"temp": "0.9.4",
|
|
24
|
+
"yargs": "^17.6.0"
|
|
23
25
|
}
|
|
24
26
|
}
|