rigjs 2.0.18 → 2.0.19-alpha.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.
@@ -1,9 +1,9 @@
1
- import CICD, {Define} from '@/classes/cicd/CICD';
1
+ import CICD, {Define, FrameworkType} from '@/classes/cicd/CICD';
2
2
  import CICDCmd from '@/classes/cicd/CICDCmd';
3
- import shell, {cat} from 'shelljs';
3
+ import shell from 'shelljs';
4
4
  import path from 'path';
5
5
  import fs from 'fs';
6
- import util from 'util';
6
+ import vueEnv from '../vue-env';
7
7
  const JSON5 = require('json5');
8
8
 
9
9
  const replaceDefine = (target: string, defines?: Define) => {
@@ -17,7 +17,7 @@ const replaceDefine = (target: string, defines?: Define) => {
17
17
  if (defines) {
18
18
  const namePieces = dir.split('.');
19
19
  const fileType = namePieces[namePieces.length - 1];
20
- if (['js', 'ts','html'].indexOf(fileType) >= 0) {
20
+ if (['js', 'ts', 'html'].indexOf(fileType) >= 0) {
21
21
  let file = fs.readFileSync(path.join(target, dir)).toString();
22
22
  const replaceArr = Object.keys(defines);
23
23
  for (let replace of replaceArr) {
@@ -30,37 +30,57 @@ const replaceDefine = (target: string, defines?: Define) => {
30
30
  }
31
31
  }
32
32
  export default async (cmd: any) => {
33
- try{
33
+ try {
34
34
  console.log('start building');
35
35
  //create cicd object
36
36
  const cicd = CICD.createByDefault(cmd);
37
37
  //construct cmd object
38
38
  const cicdCmd = new CICDCmd(cmd, cicd);
39
39
  //build by cicdCmd and cicdConfig
40
- if (cicdCmd.endpoints.length===0){
40
+ if (cicdCmd.endpoints.length === 0) {
41
41
  throw new Error('Must have validate endpoints')
42
42
  }
43
+ //替换build中的可替换变量
43
44
  const regexPublicPath = new RegExp('\\$public_path', 'g');
45
+
44
46
  for (let i = 0; i < cicdCmd.endpoints.length; i++) {
45
47
  const ep = cicdCmd.endpoints[i];
46
-
47
48
  ep.build = ep.build.replace(regexPublicPath, ep.publicPath);
48
49
  try {
49
50
  //替换define中的$public_path
50
- Object.keys(ep.defines).forEach(key=>{
51
+ Object.keys(ep.defines).forEach(key => {
51
52
  ep.defines[key] = ep.defines[key].replace(regexPublicPath, ep.publicPath);
52
53
  })
53
54
  } catch (e) {
54
- console.log('JSON5 error:', ep.defines,e.message);
55
+ console.log('JSON5 error:', ep.defines, e.message);
56
+ }
57
+ let frameworktype: FrameworkType | undefined;
58
+ //判断是否要生成环境变量文件,以及生成环境变量的操作
59
+ if (ep.vue_env){
60
+ frameworktype = FrameworkType.vue;
61
+ }
62
+ if (!ep.extra_env)ep.extra_env = {};
63
+ ep.extra_env['PUBLIC_PATH'] = ep.publicPath;
64
+ ep.extra_env['OUTPUT_DIR'] = path.join(cicd.source.root_path, ep.dir);
65
+
66
+ switch (frameworktype){
67
+ case FrameworkType.vue:{
68
+ vueEnv.useEnv(ep.vue_env!,ep.extra_env);
69
+ }
70
+ break;
71
+ default:
72
+ break;
55
73
  }
56
- console.log('exec build:', ep, ep.build, ep.defines);
57
74
  shell.exec(ep.build);
75
+
76
+ //setup default defines and replace text in built source.
58
77
  if (!ep.defines) ep.defines = {};
59
78
  ep.defines['__DEPLOY_DIR__'] = ep.deployDir;
60
- ep.defines['__PUBLIC_PATH__'] = ep.publicPath;
79
+ ep.defines['__RIG_PUBLIC_PATH__'] = ep.publicPath;
80
+ ep.defines['__RIG_DEPLOY_DIR__'] = ep.publicPath;
61
81
  replaceDefine(path.join(cicd.source.root_path, ep.dir), ep.defines);
62
82
  }
63
- }catch (e) {
83
+ } catch (e) {
64
84
  console.error(e.message);
65
85
  process.exit(1);
66
86
  }
@@ -8,7 +8,9 @@ import util from 'util';
8
8
  export enum CloudType {
9
9
  alicloud = 'alicloud',
10
10
  }
11
-
11
+ export enum FrameworkType {
12
+ vue = 'vue',
13
+ }
12
14
  /**
13
15
  * Bundle source
14
16
  */
@@ -55,8 +57,12 @@ export interface DefineDict{
55
57
 
56
58
  /**
57
59
  * Whole CI/CD config
60
+ * @property tree_schema string fafafa
58
61
  */
59
62
  export interface CICDConfig {
63
+ /**
64
+ * fafafafa
65
+ */
60
66
  tree_schema: string;
61
67
  source: DeploySource;
62
68
  target: DeployTarget | DeployTarget[];
@@ -98,6 +104,7 @@ class CICD {
98
104
  let cicdStr = fs.readFileSync(`${process.cwd()}/cicd.rig.json5`).toString();
99
105
  const paramsStr = cmd.params;
100
106
  const params = qs.parse(paramsStr);
107
+ //替换动态变量
101
108
  Object.keys(params).forEach(key => {
102
109
  const regStr = `\\$\\{${key}\\}`;
103
110
  const regex = new RegExp(regStr, 'g');
@@ -8,6 +8,8 @@ interface EndpointInfo {
8
8
  domain: string;
9
9
  domains: string[];
10
10
  defines: Define;
11
+ vue_env?: string;
12
+ extra_env?:{[env: string]: String};
11
13
  uri_rewrite: {
12
14
  original: string;
13
15
  original_regexp: string;
@@ -28,7 +30,8 @@ class Endpoint {
28
30
  domain: string;
29
31
  domains: string[];
30
32
  deployDir: string = '';
31
-
33
+ vue_env?: string;
34
+ extra_env?:{[env: string]: String};
32
35
  publicPath: string = '';
33
36
  defines: Define;
34
37
  uri_rewrite: {
@@ -56,6 +59,9 @@ class Endpoint {
56
59
  this.domains = info.domains
57
60
  this.defines = info.defines;
58
61
  this.uri_rewrite = info.uri_rewrite;
62
+ this.vue_env = info.vue_env;
63
+ this.extra_env = info.extra_env;
64
+
59
65
  }
60
66
 
61
67
  matchCmd(dirSchemaStrArr: string[], groups: DirGroup[]) {
@@ -1,4 +1,6 @@
1
1
  declare namespace env {
2
2
  function load(): void;
3
+ function useEnv(env:string,extra?:any): void;
4
+
3
5
  }
4
6
  export default env;
@@ -8,13 +8,12 @@ const fs = require('fs');
8
8
  const json5 = require('json5');
9
9
  const print = require("../print");
10
10
 
11
- //加载命令控制器
12
- const load = async (cmd) => {
11
+ const useEnv = (mode,extra)=>{
13
12
  try {
14
- const mode = process.argv[process.argv.length -1];
15
13
  const rigJson5 = json5.parse(fs.readFileSync('env.rig.json5'));
16
- const modeObj = rigJson5[mode];
14
+ let modeObj = rigJson5[mode];
17
15
  if (modeObj) {
16
+ if (extra) modeObj = Object.assign(modeObj, extra);
18
17
  const keysArray = Object.keys(modeObj);
19
18
  let content = "";
20
19
  for (let i = 0; i<keysArray.length; i++) {
@@ -39,7 +38,18 @@ const load = async (cmd) => {
39
38
  process.exit(1)
40
39
  }
41
40
  }
41
+ //加载命令控制器
42
+ const load = async (cmd) => {
43
+ try {
44
+ const mode = process.argv[process.argv.length -1];
45
+ useEnv(mode);
46
+ } catch (e) {
47
+ print.error(e.message);
48
+ process.exit(1)
49
+ }
50
+ }
42
51
 
43
52
  module.exports = {
44
- load
53
+ load,
54
+ useEnv
45
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rigjs",
3
- "version": "2.0.18",
3
+ "version": "2.0.19-alpha.1",
4
4
  "description": "A multi-repos dev tool based on yarn and git.Rig is inspired by cocoapods. Not like those monorepo solutions,rig is a tool for organizing multi-repos.",
5
5
  "keywords": [
6
6
  "modular",