eggjs / egg-ci

@@ -1,8 +1,8 @@
Loading
1 1
'use strict';
2 2
3 -
const nunjucks = require('nunjucks');
4 3
const path = require('path');
5 4
const fs = require('fs');
5 +
const nunjucks = require('nunjucks');
6 6
7 7
const engine = nunjucks.configure({
8 8
  autoescape: false,
@@ -30,131 +30,43 @@
Loading
30 30
  process.exit(0);
31 31
}
32 32
33 -
const config = Object.assign({
34 -
  type: 'travis, appveyor, github', // default is travis, appveyor and github
35 -
  version: '',
36 -
  npminstall: true,
33 +
const config = {
34 +
  version: '14, 16, 18',
35 +
  os: 'linux, windows, macos',
36 +
  npminstall: false,
37 37
  // auto detect nyc_output/*.json files, please use on travis windows platfrom
38 38
  nyc: false,
39 39
  license: false,
40 -
}, pkg.ci);
41 -
if (!('afterScript' in config)) {
42 -
  const codecovCMD = config.nyc ? 'codecov --disable=gcov -f .nyc_output/*.json' : 'codecov';
43 -
  if (config.npminstall) {
44 -
    config.afterScript = `
45 -
after_script:
46 -
  - npminstall codecov && ${codecovCMD}
47 -
`.trim();
48 -
  } else {
49 -
    config.afterScript = `
50 -
after_script:
51 -
  - npm i codecov && ${codecovCMD}
52 -
`.trim();
53 -
  }
54 -
}
55 -
56 -
config.types = arrayify(config.type);
57 -
config.versions = arrayify(config.version);
58 -
if (config.services) config.services = arrayify(config.services);
59 -
if (config.versions.length === 0) {
60 -
  const installNode = pkg.engines && (pkg.engines['install-node'] ||
61 -
    pkg.engines['install-alinode']);
62 -
  if (!installNode) {
63 -
    // default version is LTS
64 -
    config.versions = [ '8', '10', '12' ];
65 -
  }
66 -
}
67 -
68 -
const defaultOS = {
69 -
  travis: '',
70 -
  'azure-pipelines': 'linux, windows, macos',
71 -
  github: 'linux, windows, macos',
40 +
  command: 'ci',
41 +
  ...pkg.ci,
72 42
};
73 43
74 -
if (pkg.ci && pkg.ci.os) {
75 -
  config.os = Object.assign(defaultOS, pkg.ci.os);
76 -
} else {
77 -
  config.os = defaultOS;
78 -
}
79 -
for (const platfrom in config.os) {
80 -
  config.os[platfrom] = arrayify(config.os[platfrom]);
81 -
}
82 -
if (config.os && config.os.travis && config.os.travis.length === 0) {
83 -
  config.os.travis = null;
84 -
}
85 -
86 -
const originCommand = config.command;
87 -
if (typeof originCommand === 'string') {
88 -
  config.command = {
89 -
    travis: originCommand,
90 -
    appveyor: originCommand,
91 -
    github: originCommand,
92 -
    'azure-pipelines': originCommand,
93 -
  };
94 -
}
95 -
config.command = Object.assign({
96 -
  travis: 'ci',
97 -
  appveyor: 'test',
98 -
  'azure-pipelines': 'ci',
99 -
  github: 'ci',
100 -
}, config.command);
44 +
config.versions = arrayify(config.version);
45 +
// if (config.services) config.services = arrayify(config.services);
101 46
102 -
let ymlName = '';
103 -
let ymlContent = '';
104 -
let ymlName2 = '';
105 -
let ymlContent2 = '';
47 +
const os = arrayify(config.os).map(name => {
48 +
  if (name === 'linux') name = 'ubuntu';
49 +
  return `${name}-latest`;
50 +
});
106 51
107 -
for (const type of config.types) {
108 -
  if (type === 'travis') {
109 -
    ymlContent = engine.renderString(getTpl('travis'), config);
110 -
    ymlName = '.travis.yml';
111 -
  } else if (type === 'appveyor') {
112 -
    ymlContent = engine.renderString(getTpl('appveyor'), config);
113 -
    ymlName = 'appveyor.yml';
114 -
  } else if (type === 'github') {
115 -
    const os = config.os.github.map(name => {
116 -
      if (name === 'linux') name = 'ubuntu';
117 -
      return `${name}-latest`;
118 -
    });
119 -
    ymlContent = getTpl('github.yml')
120 -
      .replace('{{github_node_version}}', config.versions.join(', '))
121 -
      .replace('{{github_os}}', os.join(', '))
122 -
      .replace('{{github_command_ci}}', config.command.github)
123 -
      .replace('{{github_npm_install}}', config.npminstall ? 'npm i -g npminstall && npminstall' : 'npm i');
124 -
    ymlName = '.github/workflows/nodejs.yml';
125 -
    let dir = path.join(root, '.github');
126 -
    if (!fs.existsSync(dir)) fs.mkdirSync(dir);
127 -
    dir = path.join(root, '.github', 'workflows');
128 -
    if (!fs.existsSync(dir)) fs.mkdirSync(dir);
129 -
  } else if (type === 'azure-pipelines') {
130 -
    ymlContent = engine.renderString(getTpl('azure-pipelines.yml'), config);
131 -
    ymlName = 'azure-pipelines.yml';
132 -
    ymlContent2 = engine.renderString(getTpl('azure-pipelines.template.yml'), config);
133 -
    ymlName2 = 'azure-pipelines.template.yml';
134 -
  } else {
135 -
    throw new Error(`${type} type not support`);
136 -
  }
137 -
  const ymlPath = path.join(root, ymlName);
138 -
  fs.writeFileSync(ymlPath, ymlContent);
139 -
  console.log(`[egg-ci] create ${ymlPath} success`);
140 -
  if (ymlName2) {
141 -
    const ymlPath2 = path.join(root, ymlName2);
142 -
    fs.writeFileSync(ymlPath2, ymlContent2);
143 -
    console.log(`[egg-ci] create ${ymlPath2} success`);
144 -
  }
145 -
}
52 +
const ymlContent = getTpl('github.yml')
53 +
  .replace('{{github_node_version}}', config.versions.join(', '))
54 +
  .replace('{{github_os}}', os.join(', '))
55 +
  .replace('{{github_command_ci}}', config.command)
56 +
  .replace('{{github_npm_install}}', config.npminstall ? 'npm i -g npminstall && npminstall' : 'npm i');
57 +
const ymlName = '.github/workflows/nodejs.yml';
58 +
const ymlPath = path.join(root, ymlName);
59 +
fs.mkdirSync(path.dirname(ymlPath), { recursive: true });
60 +
fs.writeFileSync(ymlPath, ymlContent);
61 +
console.log(`[egg-ci] create ${ymlPath} success`);
146 62
147 63
if (config.license) {
148 -
  let data = {
64 +
  const data = {
149 65
    year: '2017',
150 66
    fullname: 'Alibaba Group Holding Limited and other contributors.',
67 +
    ...config.license,
151 68
  };
152 -
  if (typeof config.license === 'object') {
153 -
    data = Object.assign(data, config.license);
154 -
  }
155 -
  if (Number(data.year) < new Date().getFullYear()) {
156 -
    data.year = `${data.year}-present`;
157 -
  }
69 +
  data.year = `${data.year}-present`;
158 70
  const licenseContent = engine.renderString(getTpl('license'), data);
159 71
  const licensePath = path.join(root, 'LICENSE');
160 72
  fs.writeFileSync(licensePath, licenseContent);
Files Coverage
install.js 98.80%
Project Totals (1 files) 98.80%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading