forked from ionic-team/ionic-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocalize.ts
More file actions
64 lines (53 loc) · 1.42 KB
/
Copy pathlocalize.ts
File metadata and controls
64 lines (53 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import {
existsSync,
mkdirSync,
readFileSync,
writeFileSync
} from 'fs';
import inquirer from 'inquirer';
import { FRAMEWORK_LOCALIZED } from './config';
const envFile = '.env';
let env = readFileSync(envFile).toString('utf8');
async function run() {
env = removeEntry(env, 'FRAMEWORK_LOCALIZED');
env = removeEntry(env, 'FRAMEWORK_DIR');
// console.log(process.env.FRAMEWORK_LOCALIZED);
if (FRAMEWORK_LOCALIZED) {
await delocalize();
} else {
await localize();
}
}
async function delocalize() {
console.log('Framework alread localized, delocalizing...');
await writeFileSync(envFile, env);
console.log('Complete...');
}
async function localize() {
const answers = await inquirer.prompt([
// {
// type: 'list',
// name: 'section',
// message: 'What section do you want to localize',
// choices: ['framework', 'cli', 'components', 'native', 'storage']
// },
{
type: 'input',
name: 'path',
message: 'Relative or absolute path to existing project: '
},
]);
if (!existsSync(envFile)) {
mkdirSync(envFile);
}
env += '\rFRAMEWORK_LOCALIZED=true';
env += `\rFRAMEWORK_DIR=${answers.path}`;
writeFileSync(envFile, env);
console.log(`\`npm run docgen framework\` will now use ${answers.path}`);
}
function removeEntry(file, str) {
return file.split('\n').filter(line => {
return line.indexOf(str) === -1;
}).join('\n');
}
run();