You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

764 lines
19 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. /*******************************
  2. Set-up
  3. *******************************/
  4. var
  5. fs = require('fs'),
  6. path = require('path'),
  7. defaults = require('../defaults'),
  8. release = require('./release'),
  9. requireDotFile = require('require-dot-file')
  10. ;
  11. /*******************************
  12. When to Ask
  13. *******************************/
  14. /* Preconditions for install questions */
  15. var when = {
  16. // path
  17. changeRoot: function(questions) {
  18. return (questions.useRoot === undefined || questions.useRoot == 'no');
  19. },
  20. // permissions
  21. changePermissions: function(question) {
  22. return (questions.usePermission == true);
  23. },
  24. // install
  25. hasConfig: function() {
  26. return requireDotFile('semantic.json');
  27. },
  28. allowOverwrite: function(questions) {
  29. return (questions.overwrite === undefined || questions.overwrite == 'yes');
  30. },
  31. notAuto: function(questions) {
  32. return (questions.install !== 'auto' && (questions.overwrite === undefined || questions.overwrite == 'yes'));
  33. },
  34. custom: function(questions) {
  35. return (questions.install === 'custom' && (questions.overwrite === undefined || questions.overwrite == 'yes'));
  36. },
  37. express: function(questions) {
  38. return (questions.install === 'express' && (questions.overwrite === undefined || questions.overwrite == 'yes'));
  39. },
  40. // customize
  41. customize: function(questions) {
  42. return (questions.customize === true);
  43. },
  44. primaryColor: function(questions) {
  45. return (questions.primaryColor);
  46. },
  47. secondaryColor: function(questions) {
  48. return (questions.secondaryColor);
  49. }
  50. };
  51. /*******************************
  52. Response Filters
  53. *******************************/
  54. /* Filters to user input from install questions */
  55. var filter = {
  56. removeTrailingSlash: function(path) {
  57. return path.replace(/(\/$|\\$)+/mg, '');
  58. }
  59. };
  60. /*******************************
  61. Configuration
  62. *******************************/
  63. module.exports = {
  64. // check whether install is setup
  65. isSetup: function() {
  66. return when.hasConfig();
  67. },
  68. // checks if files are in a PM directory
  69. getPackageManager: function(directory) {
  70. var
  71. // returns last matching result (avoid sub-module detection)
  72. walk = function(directory) {
  73. var
  74. pathArray = directory.split('/'),
  75. folder = pathArray[pathArray.length - 2],
  76. nextDirectory = path.normalize(directory + '/../')
  77. ;
  78. if( folder == 'bower_components') {
  79. return {
  80. name: 'Bower',
  81. root: nextDirectory
  82. };
  83. }
  84. else if(folder == 'node_modules') {
  85. return {
  86. name: 'NPM',
  87. root: nextDirectory
  88. };
  89. }
  90. else if(folder == 'composer') {
  91. return {
  92. name: 'Composer',
  93. root: nextDirectory
  94. };
  95. }
  96. if(path.resolve(directory) == '/') {
  97. return false;
  98. }
  99. // recurse downward
  100. return walk(nextDirectory);
  101. }
  102. ;
  103. // start walk from current directory if none specified
  104. directory = directory || (__dirname + '/');
  105. return walk(directory);
  106. },
  107. // checks if files is PMed submodule
  108. isSubModule: function(directory) {
  109. var
  110. moduleFolders = 0,
  111. walk = function(directory) {
  112. var
  113. pathArray = directory.split('/'),
  114. folder = pathArray[pathArray.length - 2],
  115. nextDirectory = path.normalize(directory + '/../')
  116. ;
  117. if( folder == 'bower_components') {
  118. moduleFolders++;
  119. }
  120. else if(folder == 'node_modules') {
  121. moduleFolders++;
  122. }
  123. else if(folder == 'composer') {
  124. moduleFolders++;
  125. }
  126. if(path.resolve(directory) == '/') {
  127. return (moduleFolders > 1);
  128. }
  129. // recurse downward
  130. return walk(nextDirectory);
  131. }
  132. ;
  133. // start walk from current directory if none specified
  134. directory = directory || (__dirname + '/');
  135. return walk(directory);
  136. },
  137. createJSON: function(answers) {
  138. var
  139. json = {
  140. paths: {
  141. source: {},
  142. output: {}
  143. }
  144. }
  145. ;
  146. // add components
  147. if(answers.components) {
  148. json.components = answers.components;
  149. }
  150. // add rtl choice
  151. if(answers.rtl) {
  152. json.rtl = answers.rtl;
  153. }
  154. // add permissions
  155. if(answers.permission) {
  156. json.permission = answers.permission;
  157. }
  158. // add path to semantic
  159. if(answers.semanticRoot) {
  160. json.base = path.normalize(answers.semanticRoot);
  161. }
  162. // record version number to avoid re-installing on same version
  163. json.version = release.version;
  164. // add dist folder paths
  165. if(answers.dist) {
  166. answers.dist = path.normalize(answers.dist);
  167. json.paths.output = {
  168. packaged : path.normalize(answers.dist + '/'),
  169. uncompressed : path.normalize(answers.dist + '/components/'),
  170. compressed : path.normalize(answers.dist + '/components/'),
  171. themes : path.normalize(answers.dist + '/themes/')
  172. };
  173. }
  174. // add site path
  175. if(answers.site) {
  176. json.paths.source.site = path.normalize(answers.site + '/');
  177. }
  178. if(answers.packaged) {
  179. json.paths.output.packaged = path.normalize(answers.packaged + '/');
  180. }
  181. if(answers.compressed) {
  182. json.paths.output.compressed = path.normalize(answers.compressed + '/');
  183. }
  184. if(answers.uncompressed) {
  185. json.paths.output.uncompressed = path.normalize(answers.uncompressed + '/');
  186. }
  187. return json;
  188. },
  189. // files cleaned up after install
  190. setupFiles: [
  191. './src/theme.config.example',
  192. './semantic.json.example',
  193. './src/_site'
  194. ],
  195. regExp: {
  196. // used to match siteFolder variable in theme.less
  197. siteVariable: /@siteFolder .*\'(.*)/mg
  198. },
  199. // source paths (relative to tasks/install.js )
  200. source: {
  201. config : './semantic.json.example',
  202. definitions : './src/definitions',
  203. gulpFile : './gulpfile.js',
  204. modules : './node_modules/',
  205. site : './src/_site',
  206. tasks : './tasks',
  207. themeConfig : './src/theme.config.example',
  208. themeImport : './src/theme.less',
  209. themes : './src/themes',
  210. userGulpFile : './tasks/config/npm/gulpfile.js'
  211. },
  212. // expected final filenames
  213. files: {
  214. config : 'semantic.json',
  215. site : 'src/site',
  216. themeConfig : 'src/theme.config'
  217. },
  218. // folder paths to files relative to root
  219. folders: {
  220. config : './',
  221. definitions : 'src/definitions/',
  222. modules : 'node_modules/',
  223. site : 'src/site/',
  224. tasks : 'tasks/',
  225. themeConfig : 'src/',
  226. themeImport : 'src/',
  227. themes : 'src/themes/'
  228. },
  229. // questions asked during install
  230. questions: {
  231. root: [
  232. {
  233. type : 'list',
  234. name : 'useRoot',
  235. message :
  236. ' \n' +
  237. ' {packageMessage} \n' +
  238. ' \n' +
  239. ' Is this your project folder?\n' +
  240. ' \033[92m{root}\033[0m \n' +
  241. ' \n ' +
  242. '\n',
  243. choices: [
  244. {
  245. name : 'Yes',
  246. value : 'yes'
  247. },
  248. {
  249. name : 'No, let me specify',
  250. value : 'no'
  251. }
  252. ]
  253. },
  254. {
  255. type : 'input',
  256. name : 'customRoot',
  257. message : 'Please enter the absolute path to your project root',
  258. default : './',
  259. when : when.changeRoot
  260. },
  261. {
  262. type : 'input',
  263. name : 'semanticRoot',
  264. message : 'Where should we put Semantic UI inside your project?',
  265. default : 'semantic/'
  266. }
  267. ],
  268. setup: [
  269. {
  270. type: 'list',
  271. name: 'overwrite',
  272. message: 'It looks like you have a semantic.json file already.',
  273. when: when.hasConfig,
  274. choices: [
  275. {
  276. name: 'Yes, extend my current settings.',
  277. value: 'yes'
  278. },
  279. {
  280. name: 'Skip install',
  281. value: 'no'
  282. }
  283. ]
  284. },
  285. {
  286. type: 'list',
  287. name: 'install',
  288. message: 'Set-up Semantic UI',
  289. when: when.allowOverwrite,
  290. choices: [
  291. {
  292. name: 'Automatic (Use defaults locations and all components)',
  293. value: 'auto'
  294. },
  295. {
  296. name: 'Express (Set components and output folder)',
  297. value: 'express'
  298. },
  299. {
  300. name: 'Custom (Customize all src/dist values)',
  301. value: 'custom'
  302. }
  303. ]
  304. },
  305. {
  306. type: 'checkbox',
  307. name: 'components',
  308. message: 'What components should we include in the package?',
  309. // duplicated manually from tasks/defaults.js with additional property
  310. choices: [
  311. { name: "reset", checked: true },
  312. { name: "site", checked: true },
  313. { name: "button", checked: true },
  314. { name: "divider", checked: true },
  315. { name: "flag", checked: true },
  316. { name: "header", checked: true },
  317. { name: "icon", checked: true },
  318. { name: "image", checked: true },
  319. { name: "input", checked: true },
  320. { name: "label", checked: true },
  321. { name: "list", checked: true },
  322. { name: "loader", checked: true },
  323. { name: "rail", checked: true },
  324. { name: "reveal", checked: true },
  325. { name: "segment", checked: true },
  326. { name: "step", checked: true },
  327. { name: "breadcrumb", checked: true },
  328. { name: "form", checked: true },
  329. { name: "grid", checked: true },
  330. { name: "menu", checked: true },
  331. { name: "message", checked: true },
  332. { name: "table", checked: true },
  333. { name: "ad", checked: true },
  334. { name: "card", checked: true },
  335. { name: "comment", checked: true },
  336. { name: "feed", checked: true },
  337. { name: "item", checked: true },
  338. { name: "statistic", checked: true },
  339. { name: "accordion", checked: true },
  340. { name: "checkbox", checked: true },
  341. { name: "dimmer", checked: true },
  342. { name: "dropdown", checked: true },
  343. { name: "modal", checked: true },
  344. { name: "nag", checked: true },
  345. { name: "popup", checked: true },
  346. { name: "progress", checked: true },
  347. { name: "rating", checked: true },
  348. { name: "search", checked: true },
  349. { name: "shape", checked: true },
  350. { name: "sidebar", checked: true },
  351. { name: "sticky", checked: true },
  352. { name: "tab", checked: true },
  353. { name: "transition", checked: true },
  354. { name: "video", checked: true },
  355. { name: "api", checked: true },
  356. { name: "form", checked: true },
  357. { name: "state", checked: true },
  358. { name: "visibility", checked: true }
  359. ],
  360. when: when.notAuto
  361. },
  362. {
  363. type: 'list',
  364. name: 'changePermisions',
  365. message: 'Should we set permissions on outputted files?',
  366. choices: [
  367. {
  368. name: 'No',
  369. value: false
  370. },
  371. {
  372. name: 'Yes',
  373. value: true
  374. },
  375. ]
  376. },
  377. {
  378. type: 'input',
  379. name: 'permission',
  380. message: 'What octal file permission should outputted files receive?',
  381. default: defaults.permission,
  382. when: when.setPermission
  383. },
  384. {
  385. type: 'list',
  386. name: 'rtl',
  387. message: 'Do you use a RTL (Right-To-Left) language?',
  388. when: when.notAuto,
  389. choices: [
  390. {
  391. name: 'No',
  392. value: false
  393. },
  394. {
  395. name: 'Yes',
  396. value: true
  397. },
  398. ]
  399. },
  400. {
  401. type: 'input',
  402. name: 'dist',
  403. message: 'Where should we output Semantic UI?',
  404. default: defaults.paths.output.packaged,
  405. filter: filter.removeTrailingSlash,
  406. when: when.express
  407. },
  408. {
  409. type: 'input',
  410. name: 'site',
  411. message: 'Where should we put your site folder?',
  412. default: defaults.paths.source.site,
  413. filter: filter.removeTrailingSlash,
  414. when: when.custom
  415. },
  416. {
  417. type: 'input',
  418. name: 'packaged',
  419. message: 'Where should we output a packaged version?',
  420. default: defaults.paths.output.packaged,
  421. filter: filter.removeTrailingSlash,
  422. when: when.custom
  423. },
  424. {
  425. type: 'input',
  426. name: 'compressed',
  427. message: 'Where should we output compressed components?',
  428. default: defaults.paths.output.compressed,
  429. filter: filter.removeTrailingSlash,
  430. when: when.custom
  431. },
  432. {
  433. type: 'input',
  434. name: 'uncompressed',
  435. message: 'Where should we output uncompressed components?',
  436. default: defaults.paths.output.uncompressed,
  437. filter: filter.removeTrailingSlash,
  438. when: when.custom
  439. }
  440. ],
  441. cleanup: [
  442. {
  443. type: 'list',
  444. name: 'cleanup',
  445. message: 'Should we remove set-up files?',
  446. choices: [
  447. {
  448. name: 'Yes (re-install will require redownloading semantic).',
  449. value: 'yes'
  450. },
  451. {
  452. name: 'No Thanks',
  453. value: 'no'
  454. }
  455. ]
  456. },
  457. {
  458. type: 'list',
  459. name: 'build',
  460. message: 'Do you want to build Semantic now?',
  461. choices: [
  462. {
  463. name: 'Yes',
  464. value: 'yes'
  465. },
  466. {
  467. name: 'No',
  468. value: 'no'
  469. }
  470. ]
  471. },
  472. ],
  473. site: [
  474. {
  475. type: 'list',
  476. name: 'customize',
  477. message: 'You have not yet customized your site, can we help you do that?',
  478. choices: [
  479. {
  480. name: 'Yes, ask me a few questions',
  481. value: true
  482. },
  483. {
  484. name: 'No I\'ll do it myself',
  485. value: false
  486. }
  487. ]
  488. },
  489. {
  490. type: 'list',
  491. name: 'headerFont',
  492. message: 'Select your header font',
  493. choices: [
  494. {
  495. name: 'Helvetica Neue, Arial, sans-serif',
  496. value: 'Helvetica Neue, Arial, sans-serif;'
  497. },
  498. {
  499. name: 'Lato (Google Fonts)',
  500. value: 'Lato'
  501. },
  502. {
  503. name: 'Open Sans (Google Fonts)',
  504. value: 'Open Sans'
  505. },
  506. {
  507. name: 'Source Sans Pro (Google Fonts)',
  508. value: 'Source Sans Pro'
  509. },
  510. {
  511. name: 'Droid (Google Fonts)',
  512. value: 'Droid'
  513. },
  514. {
  515. name: 'I\'ll choose on my own',
  516. value: false
  517. }
  518. ],
  519. when: when.customize
  520. },
  521. {
  522. type: 'list',
  523. name: 'pageFont',
  524. message: 'Select your page font',
  525. choices: [
  526. {
  527. name: 'Helvetica Neue, Arial, sans-serif',
  528. value: 'Helvetica Neue, Arial, sans-serif;'
  529. },
  530. {
  531. name: 'Lato (Import from Google Fonts)',
  532. value: 'Lato'
  533. },
  534. {
  535. name: 'Open Sans (Import from Google Fonts)',
  536. value: 'Open Sans'
  537. },
  538. {
  539. name: 'Source Sans Pro (Import from Google Fonts)',
  540. value: 'Source Sans Pro'
  541. },
  542. {
  543. name: 'Droid (Google Fonts)',
  544. value: 'Droid'
  545. },
  546. {
  547. name: 'I\'ll choose on my own',
  548. value: false
  549. }
  550. ],
  551. when: when.customize
  552. },
  553. {
  554. type: 'list',
  555. name: 'fontSize',
  556. message: 'Select your base font size',
  557. default: '14px',
  558. choices: [
  559. {
  560. name: '12px',
  561. },
  562. {
  563. name: '13px',
  564. },
  565. {
  566. name: '14px (Recommended)',
  567. value: '14px'
  568. },
  569. {
  570. name: '15px',
  571. },
  572. {
  573. name: '16px',
  574. },
  575. {
  576. name: 'I\'ll choose on my own',
  577. value: false
  578. }
  579. ],
  580. when: when.customize
  581. },
  582. {
  583. type: 'list',
  584. name: 'primaryColor',
  585. message: 'Select the closest name for your primary brand color',
  586. default: '14px',
  587. choices: [
  588. {
  589. name: 'Blue'
  590. },
  591. {
  592. name: 'Green'
  593. },
  594. {
  595. name: 'Orange'
  596. },
  597. {
  598. name: 'Pink'
  599. },
  600. {
  601. name: 'Purple'
  602. },
  603. {
  604. name: 'Red'
  605. },
  606. {
  607. name: 'Teal'
  608. },
  609. {
  610. name: 'Yellow'
  611. },
  612. {
  613. name: 'Black'
  614. },
  615. {
  616. name: 'None really fit',
  617. value: 'custom'
  618. },
  619. {
  620. name: 'I\'ll choose on my own',
  621. value: false
  622. }
  623. ],
  624. when: when.customize
  625. },
  626. {
  627. type: 'input',
  628. name: 'PrimaryHex',
  629. message: 'Enter a hexcode for your primary brand color',
  630. when: when.primaryColor
  631. },
  632. {
  633. type: 'list',
  634. name: 'secondaryColor',
  635. message: 'Select the closest name for your secondary brand color',
  636. default: '14px',
  637. choices: [
  638. {
  639. name: 'Blue'
  640. },
  641. {
  642. name: 'Green'
  643. },
  644. {
  645. name: 'Orange'
  646. },
  647. {
  648. name: 'Pink'
  649. },
  650. {
  651. name: 'Purple'
  652. },
  653. {
  654. name: 'Red'
  655. },
  656. {
  657. name: 'Teal'
  658. },
  659. {
  660. name: 'Yellow'
  661. },
  662. {
  663. name: 'Black'
  664. },
  665. {
  666. name: 'None really fit',
  667. value: 'custom'
  668. },
  669. {
  670. name: 'I\'ll choose on my own',
  671. value: false
  672. }
  673. ],
  674. when: when.customize
  675. },
  676. {
  677. type: 'input',
  678. name: 'secondaryHex',
  679. message: 'Enter a hexcode for your secondary brand color',
  680. when: when.secondaryColor
  681. }
  682. ]
  683. },
  684. settings: {
  685. /* Rename Files */
  686. rename: {
  687. json : { extname : '.json' },
  688. },
  689. /* Copy Install Folders */
  690. wrench: {
  691. // copy during npm update (default theme / definition)
  692. update: {
  693. forceDelete : true,
  694. excludeHiddenUnix : true,
  695. preserveFiles : false
  696. },
  697. // copy during first npm install
  698. install: {
  699. forceDelete : true,
  700. excludeHiddenUnix : true,
  701. preserveFiles : false
  702. },
  703. // copy for node_modules
  704. modules: {
  705. forceDelete : true,
  706. excludeHiddenUnix : true,
  707. preserveFiles : false
  708. },
  709. // copy for site theme
  710. site: {
  711. forceDelete : true,
  712. excludeHiddenUnix : true,
  713. preserveFiles : true
  714. }
  715. }
  716. }
  717. };